Commit d78c4f16 authored by Vincent Pelletier's avatar Vincent Pelletier

Move configuration file parsing out of Agent class and into main function.

Closes the gap between command-line arguments and configuration file.
Also, make key_file and cert_file optional, as they are only needed by
slap when master_url uses the "https" scheme.
parent 65c7277a
...@@ -30,24 +30,23 @@ def _decode_software_dict(software_dict): ...@@ -30,24 +30,23 @@ def _decode_software_dict(software_dict):
return result return result
class Agent: class Agent:
def __init__(self, configuration_file): def __init__(self, portal_url, master_url,
configuration = ConfigParser.SafeConfigParser() maximum_software_installation_duration, software_live_duration,
configuration.readfp(configuration_file) computer_list, software_list, log_directory, state_file, software_uri,
self.portal_url = configuration.get("agent", "portal_url") key_file=None, cert_file=None,
master_url = configuration.get("agent", "master_url") ):
key_file = configuration.get("agent", "key_file") self.portal_url = portal_url
cert_file = configuration.get("agent", "cert_file") master_url = master_url
key_file = key_file
cert_file = cert_file
self.maximum_software_installation_duration = \ self.maximum_software_installation_duration = \
timedelta(minutes=configuration.getfloat("agent", "maximum_software_installation_duration")) maximum_software_installation_duration
self.software_live_duration = \ self.software_live_duration = software_live_duration
timedelta(minutes=configuration.getfloat("agent", "software_live_duration")) self.computer_list = computer_list
self.computer_list = json.loads(configuration.get("agent", "computer_list")) self.software_list = software_list
self.software_list = json.loads(configuration.get("agent", "software_list")) self.software_uri = software_uri
self.software_uri = dict() self.log_directory = log_directory
for (software, uri) in configuration.items("software_uri"): self.state_file = state_file
self.software_uri[software] = uri
self.log_directory = configuration.get("agent", "log_directory")
self.state_file = configuration.get("agent", "state_file")
filename = os.path.join(self.log_directory, "agent-%s.log" % datetime.strftime(datetime.now(), "%Y%m%d")) filename = os.path.join(self.log_directory, "agent-%s.log" % datetime.strftime(datetime.now(), "%Y%m%d"))
basicConfig(filename=filename, format="%(asctime)-15s %(message)s", level="INFO") basicConfig(filename=filename, format="%(asctime)-15s %(message)s", level="INFO")
...@@ -124,16 +123,28 @@ def main(*args): ...@@ -124,16 +123,28 @@ def main(*args):
argument_option_instance = parser.parse_args(list(args)) argument_option_instance = parser.parse_args(list(args))
else: else:
argument_option_instance = parser.parse_args() argument_option_instance = parser.parse_args()
option_dict = {} configuration = ConfigParser.SafeConfigParser()
configuration_file = argument_option_instance.configuration_file[0] configuration.readfp(argument_option_instance.pop("configuration_file")[0])
for argument_key, argument_value in vars(argument_option_instance configuration_dict = dict(configuration.items("agent"))
).iteritems(): configuration_dict.update(argument_option_instance.__dict__)
option_dict.update({argument_key:argument_value})
pidfile = option_dict.get("pidfile") pidfile = option_dict.get("pidfile")
if pidfile: if pidfile:
setRunning(pidfile) setRunning(pidfile)
agent = Agent(
agent = Agent(configuration_file) portal_url=configuration_dict["portal_url"],
master_url=configuration_dict["master_url"],
maximum_software_installation_duration=timedelta(minutes=float(
configuration_dict["maximum_software_installation_duration"])),
software_live_duration=timedelta(minutes=float(configuration_dict[
"software_live_duration"])),
computer_list=json.loads(configuration_dict["computer_list"]),
software_list=json.loads(configuration_dict["software_list"]),
log_directory=configuration_dict["log_directory"],
state_file=configuration_dict["state_file"],
software_uri=dict(configuration.items("software_uri")),
key_file=configuration_dict.get("key_file", None),
cert_file=configuration_dict.get("cert_file", None),
)
now = datetime.now() now = datetime.now()
for computer in agent.computer_list: for computer in agent.computer_list:
installing_software_list = agent.getInstallingSoftwareReleaseListOnComputer(computer) installing_software_list = agent.getInstallingSoftwareReleaseListOnComputer(computer)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment