refactored --service_name to only work with compute calls and added

--volume_service_name for volume calls

Change-Id: I2b1188fb57f9576daebfaceaddc6eea44a47b4ee
This commit is contained in:
Chuck 2012-04-12 15:41:35 -05:00
parent d743f92dc2
commit 636f32b00a
5 changed files with 40 additions and 24 deletions

View File

@ -12,6 +12,7 @@ Chmouel Boudjnah <chmouel.boudjnah@rackspace.co.uk>
Chris Behrens <cbehrens+github@codestud.com>
Christian Berendt <berendt@b1-systems.de>
Christopher MacGown <ignoti+github@gmail.com>
Chuck Thier <cthier@gmail.com>
Cole Robinson <crobinso@redhat.com>
Dan Prince <dprince@redhat.com>
Dan Wendlandt <dan@nicira.com>

View File

@ -42,7 +42,7 @@ class HTTPClient(httplib2.Http):
timeout=None, proxy_tenant_id=None,
proxy_token=None, region_name=None,
endpoint_type='publicURL', service_type=None,
service_name=None):
service_name=None, volume_service_name=None):
super(HTTPClient, self).__init__(timeout=timeout)
self.user = user
self.password = password
@ -53,6 +53,7 @@ class HTTPClient(httplib2.Http):
self.endpoint_type = endpoint_type
self.service_type = service_type
self.service_name = service_name
self.volume_service_name = volume_service_name
self.management_url = None
self.auth_token = None
@ -159,11 +160,12 @@ class HTTPClient(httplib2.Http):
self.auth_token = self.service_catalog.get_token()
management_url = self.service_catalog.url_for(
attr='region',
filter_value=self.region_name,
endpoint_type=self.endpoint_type,
service_type=self.service_type,
service_name=self.service_name)
attr='region',
filter_value=self.region_name,
endpoint_type=self.endpoint_type,
service_type=self.service_type,
service_name=self.service_name,
volume_service_name=self.volume_service_name,)
self.management_url = management_url.rstrip('/')
return None
except exceptions.AmbiguousEndpoints:

View File

@ -30,7 +30,7 @@ class ServiceCatalog(object):
def url_for(self, attr=None, filter_value=None,
service_type=None, endpoint_type='publicURL',
service_name=None):
service_name=None, volume_service_name=None):
"""Fetch the public URL from the Compute service for
a particular endpoint attribute. If none given, return
the first. See tests for sample service catalog."""
@ -54,7 +54,12 @@ class ServiceCatalog(object):
if service.get("type") != service_type:
continue
if service_name and service.get('name') != service_name:
if (service_name and service_type == 'compute' and
service.get('name') != service_name):
continue
if (volume_service_name and service_type == 'volume' and
service.get('name') != volume_service_name):
continue
endpoints = service['endpoints']

View File

@ -113,6 +113,10 @@ class OpenStackComputeShell(object):
default=utils.env('NOVA_SERVICE_NAME'),
help='Defaults to env[NOVA_SERVICE_NAME]')
parser.add_argument('--volume_service_name',
default=utils.env('NOVA_VOLUME_SERVICE_NAME'),
help='Defaults to env[NOVA_VOLUME_SERVICE_NAME]')
parser.add_argument('--endpoint_type',
default=utils.env('NOVA_ENDPOINT_TYPE',
default=DEFAULT_NOVA_ENDPOINT_TYPE),
@ -292,14 +296,15 @@ class OpenStackComputeShell(object):
return 0
(os_username, os_password, os_tenant_name, os_auth_url,
os_region_name, endpoint_type,
insecure, service_type, service_name,
os_region_name, endpoint_type, insecure,
service_type, service_name, volume_service_name,
username, apikey, projectid, url, region_name) = (
args.os_username, args.os_password,
args.os_tenant_name, args.os_auth_url,
args.os_region_name, args.endpoint_type,
args.insecure, args.service_type, args.service_name,
args.username, args.apikey, args.projectid,
args.volume_service_name, args.username,
args.apikey, args.projectid,
args.url, args.region_name)
if not endpoint_type:
@ -360,7 +365,8 @@ class OpenStackComputeShell(object):
os_password, os_tenant_name, os_auth_url, insecure,
region_name=os_region_name, endpoint_type=endpoint_type,
extensions=self.extensions, service_type=service_type,
service_name=service_name)
service_name=service_name,
volume_service_name=volume_service_name)
try:
if not utils.isunauthenticated(args.func):

View File

@ -44,7 +44,8 @@ class Client(object):
insecure=False, timeout=None, proxy_tenant_id=None,
proxy_token=None, region_name=None,
endpoint_type='publicURL', extensions=None,
service_type='compute', service_name=None):
service_type='compute', service_name=None,
volume_service_name=None):
# FIXME(comstud): Rename the api_key argument above when we
# know it's not being used as keyword argument
password = api_key
@ -83,17 +84,18 @@ class Client(object):
extension.manager_class(self))
self.client = client.HTTPClient(username,
password,
project_id,
auth_url,
insecure=insecure,
timeout=timeout,
proxy_token=proxy_token,
proxy_tenant_id=proxy_tenant_id,
region_name=region_name,
endpoint_type=endpoint_type,
service_type=service_type,
service_name=service_name)
password,
project_id,
auth_url,
insecure=insecure,
timeout=timeout,
proxy_token=proxy_token,
proxy_tenant_id=proxy_tenant_id,
region_name=region_name,
endpoint_type=endpoint_type,
service_type=service_type,
service_name=service_name,
volume_service_name=volume_service_name)
def authenticate(self):
"""