From dd023d137a5e5ca7e44dd911fbc5c9b8ae375b6a Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 10 Sep 2012 18:31:40 +0200 Subject: [PATCH] Add support for differnt nova.ini file location: ./nova.ini, ~/nova.ini, /etc/ansible/nova.ini --- inventory/nova.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/inventory/nova.py b/inventory/nova.py index a06d39888c2..cbe5c72f884 100755 --- a/inventory/nova.py +++ b/inventory/nova.py @@ -76,9 +76,23 @@ except: # executed with no parameters, return the list of # all groups and hosts - -config = ConfigParser.SafeConfigParser() -config.read(os.path.dirname(os.path.realpath(__file__)) + '/nova.ini') +def nova_load_config_file(): + p = ConfigParser.SafeConfigParser() + path1 = os.getcwd() + "/nova.ini" + path2 = os.path.expanduser(os.environ.get('ANSIBLE_CONFIG', "~/nova.ini")) + path3 = "/etc/ansible/nova.ini" + + if os.path.exists(path1): + p.read(path1) + elif os.path.exists(path2): + p.read(path2) + elif os.path.exists(path3): + p.read(path3) + else: + return None + return p + +config = nova_load_config_file() client = nova_client.Client( version = config.get('openstack', 'version'),