minor tweaks and long overdue pep8

This commit is contained in:
Sandy Walsh 2011-10-25 09:34:23 -07:00
parent 881427de9d
commit 0a3eda6cdd
9 changed files with 28 additions and 23 deletions

@ -185,7 +185,8 @@ class HTTPClient(httplib2.Http):
_logger.debug("Using Endpoint URL: %s" % url) _logger.debug("Using Endpoint URL: %s" % url)
resp, body = self.request(url, "GET", resp, body = self.request(url, "GET",
headers={'X-Auth_Token': self.auth_token}) headers={'X-Auth_Token': self.auth_token})
return self._extract_service_catalog(url, resp, body, extract_token=False) return self._extract_service_catalog(url, resp, body,
extract_token=False)
def authenticate(self): def authenticate(self):
magic_tuple = urlparse.urlsplit(self.auth_url) magic_tuple = urlparse.urlsplit(self.auth_url)
@ -201,7 +202,7 @@ class HTTPClient(httplib2.Http):
# TODO(sandy): Assume admin endpoint is 35357 for now. # TODO(sandy): Assume admin endpoint is 35357 for now.
# Ideally this is going to have to be provided by the service catalog. # Ideally this is going to have to be provided by the service catalog.
new_netloc = netloc.replace(':%d' % port, ':%d' % (35357)) new_netloc = netloc.replace(':%d' % port, ':%d' % (35357,))
admin_url = urlparse.urlunsplit( admin_url = urlparse.urlunsplit(
(scheme, new_netloc, path, query, frag)) (scheme, new_netloc, path, query, frag))

@ -1,2 +1 @@
from novaclient.keystone.client import Client from novaclient.keystone.client import Client

@ -78,7 +78,7 @@ class TenantManager(base.ManagerWithFind):
""" """
update a tenant with a new name and description update a tenant with a new name and description
""" """
body = {"tenant": {'id': tenant_id }} body = {"tenant": {'id': tenant_id}}
if enabled is not None: if enabled is not None:
body['tenant']['enabled'] = enabled body['tenant']['enabled'] = enabled
if description: if description:

@ -36,7 +36,7 @@ class UserManager(base.ManagerWithFind):
""" """
# FIXME(ja): why do we have to send id in params and url? # FIXME(ja): why do we have to send id in params and url?
params = {"user": {"id": base.getid(user), params = {"user": {"id": base.getid(user),
"email": email }} "email": email}}
self._update("/users/%s" % base.getid(user), params) self._update("/users/%s" % base.getid(user), params)
@ -45,7 +45,7 @@ class UserManager(base.ManagerWithFind):
Update enabled-ness Update enabled-ness
""" """
params = {"user": {"id": base.getid(user), params = {"user": {"id": base.getid(user),
"enabled": enabled }} "enabled": enabled}}
self._update("/users/%s/enabled" % base.getid(user), params) self._update("/users/%s/enabled" % base.getid(user), params)
@ -54,7 +54,7 @@ class UserManager(base.ManagerWithFind):
Update password Update password
""" """
params = {"user": {"id": base.getid(user), params = {"user": {"id": base.getid(user),
"password": password }} "password": password}}
self._update("/users/%s/password" % base.getid(user), params) self._update("/users/%s/password" % base.getid(user), params)
@ -63,7 +63,7 @@ class UserManager(base.ManagerWithFind):
Update default tenant. Update default tenant.
""" """
params = {"user": {"id": base.getid(user), params = {"user": {"id": base.getid(user),
"tenantId": base.getid(tenant) }} "tenantId": base.getid(tenant)}}
# FIXME(ja): seems like a bad url - default tenant is an attribute # FIXME(ja): seems like a bad url - default tenant is an attribute
# not a subresource!??? # not a subresource!???
@ -73,7 +73,8 @@ class UserManager(base.ManagerWithFind):
""" """
Create a user. Create a user.
""" """
# FIXME(ja): email should be optional but keystone currently requires it # FIXME(ja): email should be optional but keystone currently
# requires it
params = {"user": {"id": user_id, params = {"user": {"id": user_id,
"password": password, "password": password,
"tenantId": tenant_id, "tenantId": tenant_id,

@ -38,10 +38,13 @@ class ServiceCatalog(object):
for endpoint in self.catalog['endpoints']: for endpoint in self.catalog['endpoints']:
if not filter_value or endpoint[attr] == filter_value: if not filter_value or endpoint[attr] == filter_value:
return endpoint[endpoint_type] return endpoint[endpoint_type]
raise novaclient.exceptions.EndpointNotFound()
# We don't always get a service catalog back ...
if not 'serviceCatalog' in self.catalog['access']: if not 'serviceCatalog' in self.catalog['access']:
return None return None
# Full catalog ...
catalog = self.catalog['access']['serviceCatalog'] catalog = self.catalog['access']['serviceCatalog']
for service in catalog: for service in catalog:

@ -174,9 +174,8 @@ class OpenStackComputeShell(object):
"via --url or via" "via --url or via"
"env[NOVA_URL") "env[NOVA_URL")
self.cs = self.get_api_class(options.version) \ self.cs = self.get_api_class(options.version)(user, apikey, projectid,
(user, apikey, projectid, url, url, region_name=region_name)
region_name=region_name)
try: try:
self.cs.authenticate() self.cs.authenticate()

@ -58,9 +58,9 @@ class ImageManager(base.ManagerWithFind):
self._delete("/images/%s" % base.getid(image)) self._delete("/images/%s" % base.getid(image))
def set_meta(self, image, metadata): def set_meta(self, image, metadata):
""" """
Set an images metadata Set an images metadata
:param image: The :class:`Image` to add metadata to :param image: The :class:`Image` to add metadata to
:param metadata: A dict of metadata to add to the image :param metadata: A dict of metadata to add to the image
""" """
@ -69,9 +69,9 @@ class ImageManager(base.ManagerWithFind):
"metadata") "metadata")
def delete_meta(self, image, keys): def delete_meta(self, image, keys):
""" """
Delete metadata from an image Delete metadata from an image
:param image: The :class:`Image` to add metadata to :param image: The :class:`Image` to add metadata to
:param keys: A list of metadata keys to delete from the image :param keys: A list of metadata keys to delete from the image
""" """

@ -253,7 +253,7 @@ def do_zone_boot(cs, args):
min_count=min_count, min_count=min_count,
max_count=max_count) max_count=max_count)
print "Reservation ID=", reservation_id print "Reservation ID=", reservation_id
def _translate_flavor_keys(collection): def _translate_flavor_keys(collection):
convert = [('ram', 'memory_mb'), ('disk', 'local_gb')] convert = [('ram', 'memory_mb'), ('disk', 'local_gb')]
@ -844,6 +844,7 @@ def do_volume_detach(cs, args):
cs.volumes.delete_server_volume(_find_server(cs, args.server).id, cs.volumes.delete_server_volume(_find_server(cs, args.server).id,
args.attachment_id) args.attachment_id)
def _print_floating_ip_list(floating_ips): def _print_floating_ip_list(floating_ips):
utils.print_list(floating_ips, ['Ip', 'Instance Id', 'Fixed Ip']) utils.print_list(floating_ips, ['Ip', 'Instance Id', 'Fixed Ip'])
@ -1038,7 +1039,8 @@ def do_secgroup_delete_group_rule(cs, args):
@utils.arg('name', metavar='<name>', help='Name of key.') @utils.arg('name', metavar='<name>', help='Name of key.')
@utils.arg('--pub_key', metavar='<pub_key>', help='Path to a public ssh key.', default=None) @utils.arg('--pub_key', metavar='<pub_key>', help='Path to a public ssh key.',
default=None)
def do_keypair_add(cs, args): def do_keypair_add(cs, args):
"""Create a new key pair for use with instances""" """Create a new key pair for use with instances"""
name = args.name name = args.name
@ -1049,8 +1051,9 @@ def do_keypair_add(cs, args):
with open(pub_key) as f: with open(pub_key) as f:
pub_key = f.read() pub_key = f.read()
except IOError, e: except IOError, e:
raise exceptions.CommandError("Can't open or read '%s': %s" % (pub_key, e)) raise exceptions.CommandError("Can't open or read '%s': %s" % \
(pub_key, e))
keypair = cs.keypairs.create(name, pub_key) keypair = cs.keypairs.create(name, pub_key)
if not pub_key: if not pub_key:
@ -1070,4 +1073,3 @@ def do_keypair_list(cs, args):
keypairs = cs.keypairs.list() keypairs = cs.keypairs.list()
columns = ['Name', 'Fingerprint'] columns = ['Name', 'Fingerprint']
utils.print_list(keypairs, columns) utils.print_list(keypairs, columns)

@ -125,5 +125,5 @@ class VolumeManager(base.ManagerWithFind):
:param server_id: The ID of the server :param server_id: The ID of the server
:param attachment_id: The ID of the attachment :param attachment_id: The ID of the attachment
""" """
return self._delete("/servers/%s/os-volume_attachments/%s" % (server_id, return self._delete("/servers/%s/os-volume_attachments/%s" %
attachment_id,)) (server_id, attachment_id,))