* 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
diff --git a/storm/common/utils/data_utils.py b/storm/common/utils/data_utils.py
index 8f43638..3fdf370 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 5ba7ef6..454f684 100644
--- a/storm/config.py
+++ b/storm/config.py
@@ -15,9 +15,28 @@
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 ff68fce..97c5b7d 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 @@
"""
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)