diff --git a/inventory.py b/inventory.py index 67b11233..e2fb274f 100755 --- a/inventory.py +++ b/inventory.py @@ -19,6 +19,7 @@ def parse_params(logger): parser = OptionParser() parser.add_option("-u", "--user", help="specify user to log in", action="store", dest="user") parser.add_option("-p", "--password", help="specify password to log in", action="store", dest="password") + parser.add_option("-a", "--authsource", help="specify auth source to authenticate against", action="store", dest="authsource") parser.add_option("-o", "--port", help="specify inventory port", action="store", dest="port") parser.add_option("-m", "--config", help="Path to the configuration to set properties of the resources kept in " "the inventory", action="store", dest="config") @@ -37,6 +38,10 @@ def parse_params(logger): os.environ['USER'] = options.user if options.password: os.environ['PASSWORD'] = options.password + if options.authsource: + os.environ['AUTHSOURCE'] = options.authsource + elif "AUTHSOURCE" not in os.environ: + os.environ['AUTHSOURCE'] = 'Local' if options.info: logger.setLevel(logging.INFO) ConsoleHandler.setLevel(logging.INFO) diff --git a/tests/TestLaunchInventory.py b/tests/TestLaunchInventory.py index e77e1c14..22173146 100644 --- a/tests/TestLaunchInventory.py +++ b/tests/TestLaunchInventory.py @@ -57,6 +57,7 @@ def test_with_cli_and_env_params(self): '-s', '180'] os.environ['USER'] = 'env_testuser' os.environ['PASSWORD'] = 'testps31!_2' + os.environ['AUTHSOURCE'] = 'Local' os.environ['PORT'] = '1123' os.environ['TARGET'] = '/wrong/path/to/atlas.yaml' os.environ['INVENTORY_CONFIG'] = 'wrong/path/to/config.yaml' @@ -78,6 +79,7 @@ def test_env_params(self): os.environ.clear() os.environ['USER'] = 'testuser' os.environ['PASSWORD'] = 'testpw31!' + os.environ['AUTHSOURCE'] = 'Local' os.environ['PORT'] = '1234' os.environ['TARGET'] = 'vrops-vcenter-test.company.com' os.environ['INVENTORY_CONFIG'] = 'tests/inventory_config.yaml' diff --git a/tools/Vrops.py b/tools/Vrops.py index b3707f3d..b196ceeb 100644 --- a/tools/Vrops.py +++ b/tools/Vrops.py @@ -22,7 +22,7 @@ def get_token(target): } payload = { "username": os.environ['USER'], - "authSource": "Local", + "authSource": os.environ['AUTHSOURCE'], "password": os.environ['PASSWORD'] } disable_warnings(exceptions.InsecureRequestWarning)