From d82f0e3135833d4bdc43a48cafd4301f52bf140a Mon Sep 17 00:00:00 2001 From: Lisa Zangrando Date: Mon, 28 Nov 2016 20:10:11 +0100 Subject: [PATCH] Added support for OpenStack DOMAIN to shell.py - added new shell options: --os-user-domain-id, --os-ser-domain-name, --os-project-domain-id, --os-project-domain-name Change-Id: Id110010a325989c3b6370647aa3cf8afebeb2657 Sem-Ver: feature --- synergy/client/keystone_v3.py | 33 ++++++++++++++++++++++----- synergy/client/shell.py | 43 +++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/synergy/client/keystone_v3.py b/synergy/client/keystone_v3.py index 6629023..b4d17cc 100644 --- a/synergy/client/keystone_v3.py +++ b/synergy/client/keystone_v3.py @@ -95,7 +95,9 @@ class Token(object): "%Y-%m-%dT%H:%M:%S.%fZ") self.project = data["project"] self.user = data["user"] - self.extras = data["extras"] + + if "extras" in data: + self.extras = data["extras"] def getCatalog(self, service_name=None, interface="public"): if service_name: @@ -245,14 +247,21 @@ class Token(object): class KeystoneClient(object): - def __init__(self, auth_url, username, password, project_id=None, - project_name=None, timeout=None, + def __init__(self, auth_url, username, password, + user_domain_id=None, + user_domain_name="default", project_id=None, + project_name=None, project_domain_id=None, + project_domain_name="default", timeout=None, default_trust_expiration=None): self.auth_url = auth_url self.username = username self.password = password + self.user_domain_id = user_domain_id + self.user_domain_name = user_domain_name self.project_id = project_id self.project_name = project_name + self.project_domain_id = project_domain_id + self.project_domain_name = project_domain_name self.timeout = timeout self.token = None @@ -275,9 +284,21 @@ class KeystoneClient(object): "Accept": "application/json", "User-Agent": "python-novaclient"} + user_domain = {} + if self.user_domain_id is not None: + user_domain["id"] = self.user_domain_id + else: + user_domain["name"] = self.user_domain_name + + project_domain = {} + if self.project_domain_id is not None: + project_domain["id"] = self.project_domain_id + else: + project_domain["name"] = self.project_domain_name + identity = {"methods": ["password"], "password": {"user": {"name": self.username, - "domain": {"id": "default"}, + "domain": user_domain, "password": self.password}}} data = {"auth": {}} @@ -285,11 +306,11 @@ class KeystoneClient(object): if self.project_name: data["auth"]["scope"] = {"project": {"name": self.project_name, - "domain": {"id": "default"}}} + "domain": project_domain}} if self.project_id: data["auth"]["scope"] = {"project": {"id": self.project_id, - "domain": {"id": "default"}}} + "domain": project_domain}} response = requests.post(url=self.auth_url + "/auth/tokens", headers=headers, diff --git a/synergy/client/shell.py b/synergy/client/shell.py index 405ea2e..c61b2a0 100644 --- a/synergy/client/shell.py +++ b/synergy/client/shell.py @@ -52,6 +52,16 @@ def main(): default=os.environ.get("OS_PASSWORD"), help="defaults to env[OS_PASSWORD]") + parser.add_argument("--os-user-domain-id", + metavar="", + default=os.environ.get("OS_USER_DOMAIN_ID"), + help="defaults to env[OS_USER_DOMAIN_ID]") + + parser.add_argument("--os-user-domain-name", + metavar="", + default=os.environ.get("OS_USER_DOMAIN_NAME"), + help="defaults to env[OS_USER_DOMAIN_NAME]") + parser.add_argument("--os-project-name", metavar="", default=os.environ.get("OS_PROJECT_NAME"), @@ -62,6 +72,16 @@ def main(): default=os.environ.get("OS_PROJECT_ID"), help="defaults to env[OS_PROJECT_ID]") + parser.add_argument("--os-project-domain-id", + metavar="", + default=os.environ.get("OS_PROJECT_DOMAIN_ID"), + help="defaults to env[OS_PROJECT_DOMAIN_ID]") + + parser.add_argument("--os-project-domain-name", + metavar="", + default=os.environ.get("OS_PROJECT_DOMAIN_NAME"), + help="defaults to env[OS_PROJECT_DOMAIN_NAME]") + parser.add_argument("--os-auth-token", metavar="", default=os.environ.get("OS_AUTH_TOKEN", None), @@ -122,7 +142,11 @@ def main(): os_username = args.os_username os_password = args.os_password + os_user_domain_id = args.os_user_domain_id + os_user_domain_name = args.os_user_domain_name os_project_name = args.os_project_name + os_project_domain_id = args.os_project_domain_id + os_project_domain_name = args.os_project_domain_name os_auth_token = args.os_auth_token os_auth_token_cache = args.os_auth_token_cache os_auth_url = args.os_auth_url @@ -141,10 +165,21 @@ def main(): if not os_auth_url: raise Exception("'os-auth-url' not defined!") - client = keystone_v3.KeystoneClient(auth_url=os_auth_url, - username=os_username, - password=os_password, - project_name=os_project_name) + if not os_user_domain_name: + os_user_domain_name = "default" + + if not os_project_domain_name: + os_project_domain_name = "default" + + client = keystone_v3.KeystoneClient( + auth_url=os_auth_url, + username=os_username, + password=os_password, + user_domain_id=os_user_domain_id, + user_domain_name=os_user_domain_name, + project_name=os_project_name, + project_domain_id=os_project_domain_id, + project_domain_name=os_project_domain_name) token = None