* 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
This commit is contained in:
Rohit Karajgi 2011-12-02 16:13:18 -08:00
parent cb5d95412e
commit e1b050d01c
4 changed files with 65 additions and 11 deletions

View File

@ -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
authentication=keystone_v2

View File

@ -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

View File

@ -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):

View File

@ -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)