diff options
author | Ruan HE <ruan.he@orange.com> | 2015-11-23 16:41:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2015-11-23 16:41:33 +0000 |
commit | 840ac3ebca7af381132bf7e93c1e4c0430d6b16a (patch) | |
tree | c2b69a290f35a7e107ae397842ee3fdf5317ef8c /moonclient | |
parent | bc89d458c81973547b585df3be12facc782e5781 (diff) | |
parent | fa9692879b1c77dfe4602531a52f537bd618053e (diff) |
Merge "Add password and authurl in global moonclient command."
Diffstat (limited to 'moonclient')
-rw-r--r-- | moonclient/moonclient/shell.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/moonclient/moonclient/shell.py b/moonclient/moonclient/shell.py index 5e40bf40..4073a227 100644 --- a/moonclient/moonclient/shell.py +++ b/moonclient/moonclient/shell.py @@ -37,6 +37,7 @@ class MoonClient(App): _intraextension = None _tenant_id = None _tenant_name = None + secureprotocol = False user_saving_file = ".moonclient" post = { "auth": { @@ -77,6 +78,10 @@ class MoonClient(App): self.post["auth"]["scope"]["project"]["name"] = creds["tenant_name"] self.host = creds["auth_url"].replace("https://", "").replace("http://", "").split("/")[0].split(":")[0] self.port = creds["auth_url"].replace("https://", "").replace("http://", "").split("/")[0].split(":")[1] + if "https" in creds["auth_url"]: + self.secureprotocol = True + else: + self.secureprotocol = False self._tenant_name = creds["tenant_name"] self.parser.add_argument( '--username', @@ -90,13 +95,24 @@ class MoonClient(App): help='Force OpenStack tenant', default=None ) + self.parser.add_argument( + '--password', + metavar='<password-str>', + help='Force OpenStack password', + default=None + ) + self.parser.add_argument( + '--authurl', + metavar='<authurl-str>', + help='Force OpenStack authentication URL', + default=None + ) @property def tenant_id(self): if not self._tenant_id: self._tenant_id = self.get_url("/v3/projects?name={}".format(self._tenant_name), authtoken=True)["projects"][0]["id"] - # TODO: change '/v3/projects?name={}' return self._tenant_id @property @@ -114,7 +130,6 @@ class MoonClient(App): def get_tenant_uuid(self, tenant_name): return self.get_url("/v3/projects?name={}".format(tenant_name), authtoken=True)["projects"][0]["id"] - # TODO: change '/v3/projects?name={}' def get_url(self, url, post_data=None, delete_data=None, method="GET", authtoken=None): if post_data: @@ -122,6 +137,7 @@ class MoonClient(App): if delete_data: method = "DELETE" self.log.debug("\033[32m{} {}\033[m".format(method, url)) + # TODO: we must manage authentication and requests with secure protocol (ie. HTTPS) conn = httplib.HTTPConnection(self.host, self.port) self.log.debug("Host: {}:{}".format(self.host, self.port)) headers = { @@ -189,10 +205,20 @@ class MoonClient(App): if self.options.username: self.post["auth"]["identity"]["password"]["user"]["name"] = self.options.username self.log.debug("change username {}".format(self.options.username)) + if self.options.password: + self.post["auth"]["identity"]["password"]["user"]["password"] = self.options.password + self.log.debug("change password") if self.options.tenant: self.post["auth"]["scope"]["project"]["name"] = self.options.tenant self._tenant_name = self.options.tenant self.log.debug("change tenant {}".format(self.options.tenant)) + if self.options.authurl: + self.host = self.options.authurl.replace("https://", "").replace("http://", "").split("/")[0].split(":")[0] + self.port = self.options.authurl.replace("https://", "").replace("http://", "").split("/")[0].split(":")[1] + if "https" in self.options.authurl: + self.secureprotocol = True + else: + self.secureprotocol = False data = self.get_url("/v3/auth/tokens", post_data=self.post) if "token" not in data: raise Exception("Authentication problem ({})".format(data)) |