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
This commit is contained in:
parent
fbf53d25ad
commit
d82f0e3135
@ -95,7 +95,9 @@ class Token(object):
|
|||||||
"%Y-%m-%dT%H:%M:%S.%fZ")
|
"%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
self.project = data["project"]
|
self.project = data["project"]
|
||||||
self.user = data["user"]
|
self.user = data["user"]
|
||||||
self.extras = data["extras"]
|
|
||||||
|
if "extras" in data:
|
||||||
|
self.extras = data["extras"]
|
||||||
|
|
||||||
def getCatalog(self, service_name=None, interface="public"):
|
def getCatalog(self, service_name=None, interface="public"):
|
||||||
if service_name:
|
if service_name:
|
||||||
@ -245,14 +247,21 @@ class Token(object):
|
|||||||
|
|
||||||
class KeystoneClient(object):
|
class KeystoneClient(object):
|
||||||
|
|
||||||
def __init__(self, auth_url, username, password, project_id=None,
|
def __init__(self, auth_url, username, password,
|
||||||
project_name=None, timeout=None,
|
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):
|
default_trust_expiration=None):
|
||||||
self.auth_url = auth_url
|
self.auth_url = auth_url
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
self.user_domain_id = user_domain_id
|
||||||
|
self.user_domain_name = user_domain_name
|
||||||
self.project_id = project_id
|
self.project_id = project_id
|
||||||
self.project_name = project_name
|
self.project_name = project_name
|
||||||
|
self.project_domain_id = project_domain_id
|
||||||
|
self.project_domain_name = project_domain_name
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.token = None
|
self.token = None
|
||||||
|
|
||||||
@ -275,9 +284,21 @@ class KeystoneClient(object):
|
|||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"User-Agent": "python-novaclient"}
|
"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"],
|
identity = {"methods": ["password"],
|
||||||
"password": {"user": {"name": self.username,
|
"password": {"user": {"name": self.username,
|
||||||
"domain": {"id": "default"},
|
"domain": user_domain,
|
||||||
"password": self.password}}}
|
"password": self.password}}}
|
||||||
|
|
||||||
data = {"auth": {}}
|
data = {"auth": {}}
|
||||||
@ -285,11 +306,11 @@ class KeystoneClient(object):
|
|||||||
|
|
||||||
if self.project_name:
|
if self.project_name:
|
||||||
data["auth"]["scope"] = {"project": {"name": self.project_name,
|
data["auth"]["scope"] = {"project": {"name": self.project_name,
|
||||||
"domain": {"id": "default"}}}
|
"domain": project_domain}}
|
||||||
|
|
||||||
if self.project_id:
|
if self.project_id:
|
||||||
data["auth"]["scope"] = {"project": {"id": 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",
|
response = requests.post(url=self.auth_url + "/auth/tokens",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
@ -52,6 +52,16 @@ def main():
|
|||||||
default=os.environ.get("OS_PASSWORD"),
|
default=os.environ.get("OS_PASSWORD"),
|
||||||
help="defaults to env[OS_PASSWORD]")
|
help="defaults to env[OS_PASSWORD]")
|
||||||
|
|
||||||
|
parser.add_argument("--os-user-domain-id",
|
||||||
|
metavar="<auth-user-domain-id>",
|
||||||
|
default=os.environ.get("OS_USER_DOMAIN_ID"),
|
||||||
|
help="defaults to env[OS_USER_DOMAIN_ID]")
|
||||||
|
|
||||||
|
parser.add_argument("--os-user-domain-name",
|
||||||
|
metavar="<auth-user-domain-name>",
|
||||||
|
default=os.environ.get("OS_USER_DOMAIN_NAME"),
|
||||||
|
help="defaults to env[OS_USER_DOMAIN_NAME]")
|
||||||
|
|
||||||
parser.add_argument("--os-project-name",
|
parser.add_argument("--os-project-name",
|
||||||
metavar="<auth-project-name>",
|
metavar="<auth-project-name>",
|
||||||
default=os.environ.get("OS_PROJECT_NAME"),
|
default=os.environ.get("OS_PROJECT_NAME"),
|
||||||
@ -62,6 +72,16 @@ def main():
|
|||||||
default=os.environ.get("OS_PROJECT_ID"),
|
default=os.environ.get("OS_PROJECT_ID"),
|
||||||
help="defaults to env[OS_PROJECT_ID]")
|
help="defaults to env[OS_PROJECT_ID]")
|
||||||
|
|
||||||
|
parser.add_argument("--os-project-domain-id",
|
||||||
|
metavar="<auth-project-domain-id>",
|
||||||
|
default=os.environ.get("OS_PROJECT_DOMAIN_ID"),
|
||||||
|
help="defaults to env[OS_PROJECT_DOMAIN_ID]")
|
||||||
|
|
||||||
|
parser.add_argument("--os-project-domain-name",
|
||||||
|
metavar="<auth-project-domain-name>",
|
||||||
|
default=os.environ.get("OS_PROJECT_DOMAIN_NAME"),
|
||||||
|
help="defaults to env[OS_PROJECT_DOMAIN_NAME]")
|
||||||
|
|
||||||
parser.add_argument("--os-auth-token",
|
parser.add_argument("--os-auth-token",
|
||||||
metavar="<auth-token>",
|
metavar="<auth-token>",
|
||||||
default=os.environ.get("OS_AUTH_TOKEN", None),
|
default=os.environ.get("OS_AUTH_TOKEN", None),
|
||||||
@ -122,7 +142,11 @@ def main():
|
|||||||
|
|
||||||
os_username = args.os_username
|
os_username = args.os_username
|
||||||
os_password = args.os_password
|
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_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 = args.os_auth_token
|
||||||
os_auth_token_cache = args.os_auth_token_cache
|
os_auth_token_cache = args.os_auth_token_cache
|
||||||
os_auth_url = args.os_auth_url
|
os_auth_url = args.os_auth_url
|
||||||
@ -141,10 +165,21 @@ def main():
|
|||||||
if not os_auth_url:
|
if not os_auth_url:
|
||||||
raise Exception("'os-auth-url' not defined!")
|
raise Exception("'os-auth-url' not defined!")
|
||||||
|
|
||||||
client = keystone_v3.KeystoneClient(auth_url=os_auth_url,
|
if not os_user_domain_name:
|
||||||
username=os_username,
|
os_user_domain_name = "default"
|
||||||
password=os_password,
|
|
||||||
project_name=os_project_name)
|
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
|
token = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user