From e1b050d01c4aa198c38c52bb11696d3084472f4b Mon Sep 17 00:00:00 2001 From: Rohit Karajgi Date: Fri, 2 Dec 2011 16:13:18 -0800 Subject: [PATCH] * Added build_url() utility that returns an endpoint URL based on config parameters * Updated storm.conf * Added more properties to Nova config object * Fixed pep8 and the 'set' typo that came from a vi editor 'set list' fumble Change-Id: I67a9b7a8708cd64eb26eb9ec15c40b18eb8895de --- etc/storm.conf.sample | 7 +++++-- storm/common/utils/data_utils.py | 26 ++++++++++++++++++++++++++ storm/config.py | 25 ++++++++++++++++++++++--- storm/openstack.py | 18 ++++++++++++------ 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/etc/storm.conf.sample b/etc/storm.conf.sample index fc0658005b..dd14e1380c 100644 --- a/etc/storm.conf.sample +++ b/etc/storm.conf.sample @@ -1,5 +1,8 @@ [nova] -auth_url=http://127.0.0.1:5000/v2.0/tokens +host=127.0.0.1 +port=5000 +apiVer=v2.0 +path=tokens user=admin api_key=admin-key tenant_name=admin-project @@ -14,4 +17,4 @@ flavor_ref=1 flavor_ref_alt=2 create_image_enabled=true resize_available=true -authentication=keystone_v2 \ No newline at end of file +authentication=keystone_v2 diff --git a/storm/common/utils/data_utils.py b/storm/common/utils/data_utils.py index 8f43638ce3..3fdf370c52 100644 --- a/storm/common/utils/data_utils.py +++ b/storm/common/utils/data_utils.py @@ -1,5 +1,31 @@ import random +import urllib def rand_name(name='test'): return name + str(random.randint(1, 99999999999)) + + +def build_url(host, port, apiVer=None, path=None, params=None, https=False): + """Build the request URL from given host, port, path and parameters""" + + if https: + url = "https://" + host + else: + url = "http://" + host + + if port is not None: + url += ":" + port + url += "/" + + if apiVer is not None: + url += apiVer + "/" + + if path is not None: + url += path + + if params is not None: + url += "?" + url += urllib.urlencode(params) + + return url diff --git a/storm/config.py b/storm/config.py index 5ba7ef60e8..454f684944 100644 --- a/storm/config.py +++ b/storm/config.py @@ -15,9 +15,28 @@ class NovaConfig(object): return default_value @property - def auth_url(self): - """URL used to authenticate. Defaults to 127.0.0.1.""" - return self.get("auth_url", "127.0.0.1") + def host(self): + """Host IP for making Nova API requests. Defaults to '127.0.0.1'.""" + return self.get("host", "127.0.1") + + @property + def port(self): + """Listen port of the Nova service.""" + return self.get("port", "8773") + + @property + def apiVer(self): + """Version of the API""" + return self.get("apiVer", "v1.1") + + @property + def path(self): + """Path of API request""" + return self.get("path", "/") + + def params(self): + """Parameters to be passed with the API request""" + return self.get("params", "") @property def username(self): diff --git a/storm/openstack.py b/storm/openstack.py index ff68fce239..97c5b7d8ed 100644 --- a/storm/openstack.py +++ b/storm/openstack.py @@ -1,6 +1,7 @@ from storm.services.nova.json.images_client import ImagesClient from storm.services.nova.json.flavors_client import FlavorsClient from storm.services.nova.json.servers_client import ServersClient +from storm.common.utils import data_utils import storm.config @@ -12,27 +13,32 @@ class Manager(object): """ self.config = storm.config.StormConfig() + self.auth_url = data_utils.build_url(self.config.nova.host, + self.config.nova.port, + self.config.nova.apiVer, + self.config.nova.path) + if self.config.env.authentication == 'keystone_v2': self.servers_client = ServersClient(self.config.nova.username, self.config.nova.api_key, - self.config.nova.auth_url, + self.auth_url, self.config.nova.tenant_name) self.flavors_client = FlavorsClient(self.config.nova.username, self.config.nova.api_key, - self.config.nova.auth_url, + self.auth_url, self.config.nova.tenant_name) self.images_client = ImagesClient(self.config.nova.username, self.config.nova.api_key, - self.config.nova.auth_url, + self.auth_url, self.config.nova.tenant_name) else: #Assuming basic/native authentication self.servers_client = ServersClient(self.config.nova.username, self.config.nova.api_key, - self.config.nova.auth_url) + self.auth_url) self.flavors_client = FlavorsClient(self.config.nova.username, self.config.nova.api_key, - self.config.nova.auth_url) + self.auth_url) self.images_client = ImagesClient(self.config.nova.username, self.config.nova.api_key, - self.config.nova.auth_url) + self.auth_url)