summaryrefslogtreecommitdiff
path: root/azurelinuxagent/agent.py
diff options
context:
space:
mode:
authorƁukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>2017-05-18 19:58:02 +0200
committerusd-importer <ubuntu-server@lists.ubuntu.com>2017-05-31 09:53:12 +0000
commit4fb0b5a09b26135ade285844da5d7dfe582a8d4c (patch)
tree09b1e5867d6e7501118cdd0af0012b51fc216530 /azurelinuxagent/agent.py
parent473ad6fbfe0b9c3b362b530492928303f2b4c7f3 (diff)
downloadvyos-walinuxagent-4fb0b5a09b26135ade285844da5d7dfe582a8d4c.tar.gz
vyos-walinuxagent-4fb0b5a09b26135ade285844da5d7dfe582a8d4c.zip
Import patches-unapplied version 2.2.12-0ubuntu1 to ubuntu/artful-proposed
Imported using git-ubuntu import. Changelog parent: 473ad6fbfe0b9c3b362b530492928303f2b4c7f3 New changelog entries: * New upstream release (LP: #1690854). - Refreshed debian/patches/disable_import_test.patch.
Diffstat (limited to 'azurelinuxagent/agent.py')
-rw-r--r--azurelinuxagent/agent.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/azurelinuxagent/agent.py b/azurelinuxagent/agent.py
index bd6dd20..90b4253 100644
--- a/azurelinuxagent/agent.py
+++ b/azurelinuxagent/agent.py
@@ -21,6 +21,8 @@
Module agent
"""
+from __future__ import print_function
+
import os
import sys
import re
@@ -37,17 +39,21 @@ from azurelinuxagent.common.version import AGENT_NAME, AGENT_LONG_VERSION, \
from azurelinuxagent.common.osutil import get_osutil
class Agent(object):
- def __init__(self, verbose):
+ def __init__(self, verbose, conf_file_path=None):
"""
Initialize agent running environment.
"""
+ self.conf_file_path = conf_file_path
self.osutil = get_osutil()
+
#Init stdout log
level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
logger.add_logger_appender(logger.AppenderType.STDOUT, level)
#Init config
- conf_file_path = self.osutil.get_agent_conf_file_path()
+ conf_file_path = self.conf_file_path \
+ if self.conf_file_path is not None \
+ else self.osutil.get_agent_conf_file_path()
conf.load_conf_from_file(conf_file_path)
#Init log
@@ -67,9 +73,13 @@ class Agent(object):
"""
Run agent daemon
"""
+ child_args = None \
+ if self.conf_file_path is None \
+ else "-configuration-path:{0}".format(self.conf_file_path)
+
from azurelinuxagent.daemon import get_daemon_handler
daemon_handler = get_daemon_handler()
- daemon_handler.run()
+ daemon_handler.run(child_args=child_args)
def provision(self):
"""
@@ -113,7 +123,7 @@ def main(args=[]):
"""
if len(args) <= 0:
args = sys.argv[1:]
- command, force, verbose = parse_args(args)
+ command, force, verbose, conf_file_path = parse_args(args)
if command == "version":
version()
elif command == "help":
@@ -122,7 +132,7 @@ def main(args=[]):
start()
else:
try:
- agent = Agent(verbose)
+ agent = Agent(verbose, conf_file_path=conf_file_path)
if command == "deprovision+user":
agent.deprovision(force, deluser=True)
elif command == "deprovision":
@@ -147,8 +157,18 @@ def parse_args(sys_args):
cmd = "help"
force = False
verbose = False
+ conf_file_path = None
for a in sys_args:
- if re.match("^([-/]*)deprovision\\+user", a):
+ m = re.match("^(?:[-/]*)configuration-path:([\w/\.\-_]+)", a)
+ if not m is None:
+ conf_file_path = m.group(1)
+ if not os.path.exists(conf_file_path):
+ print("Error: Configuration file {0} does not exist".format(
+ conf_file_path), file=sys.stderr)
+ usage()
+ sys.exit(1)
+
+ elif re.match("^([-/]*)deprovision\\+user", a):
cmd = "deprovision+user"
elif re.match("^([-/]*)deprovision", a):
cmd = "deprovision"
@@ -171,7 +191,7 @@ def parse_args(sys_args):
else:
cmd = "help"
break
- return cmd, force, verbose
+ return cmd, force, verbose, conf_file_path
def version():
"""
@@ -191,6 +211,7 @@ def usage():
"""
print("")
print((("usage: {0} [-verbose] [-force] [-help] "
+ "-configuration-path:<path to configuration file>"
"-deprovision[+user]|-register-service|-version|-daemon|-start|"
"-run-exthandlers]"
"").format(sys.argv[0])))