Skip to content

Commit

Permalink
Add argparser to enable specifying config file location
Browse files Browse the repository at this point in the history
Closes-Bug: #1775536
Change-Id: I01f1b26aff941528e40623dddd6c240e7bacc53e
  • Loading branch information
aszc-dev committed Jun 7, 2018
1 parent 944be4b commit 5d7ee43
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cvm/__main__.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import argparse
import sys

import gevent
Expand All @@ -15,17 +16,17 @@
VirtualMachineService, VirtualNetworkService)


def load_config():
with open('config.yaml', 'r') as ymlfile:
def load_config(config_file):
with open(config_file, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
esxi_cfg = cfg['esxi']
vcenter_cfg = cfg['vcenter']
vnc_cfg = cfg['vnc']
return esxi_cfg, vcenter_cfg, vnc_cfg


def main():
esxi_cfg, vcenter_cfg, vnc_cfg = load_config()
def main(args):
esxi_cfg, vcenter_cfg, vnc_cfg = load_config(args.config_file)

esxi_api_client = ESXiAPIClient(esxi_cfg)
event_history_collector = esxi_api_client.create_event_history_collector(const.EVENTS_TO_OBSERVE)
Expand Down Expand Up @@ -66,8 +67,12 @@ def main():


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-c", action="store", dest="config_file",
default='/etc/contrail/contrail-vcenter-manager/config.yaml')
parsed_args = parser.parse_args()
try:
main()
main(parsed_args)
sys.exit(0)
except KeyboardInterrupt:
sys.exit(0)

0 comments on commit 5d7ee43

Please sign in to comment.