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

View File

@ -185,7 +185,8 @@ class HTTPClient(httplib2.Http):
_logger.debug("Using Endpoint URL: %s" % url)
resp, body = self.request(url, "GET",
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):
magic_tuple = urlparse.urlsplit(self.auth_url)
@ -201,7 +202,7 @@ class HTTPClient(httplib2.Http):
# TODO(sandy): Assume admin endpoint is 35357 for now.
# 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(
(scheme, new_netloc, path, query, frag))

View File

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

View File

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

View File

@ -36,7 +36,7 @@ class UserManager(base.ManagerWithFind):
"""
# FIXME(ja): why do we have to send id in params and url?
params = {"user": {"id": base.getid(user),
"email": email }}
"email": email}}
self._update("/users/%s" % base.getid(user), params)
@ -45,7 +45,7 @@ class UserManager(base.ManagerWithFind):
Update enabled-ness
"""
params = {"user": {"id": base.getid(user),
"enabled": enabled }}
"enabled": enabled}}
self._update("/users/%s/enabled" % base.getid(user), params)
@ -54,7 +54,7 @@ class UserManager(base.ManagerWithFind):
Update password
"""
params = {"user": {"id": base.getid(user),
"password": password }}
"password": password}}
self._update("/users/%s/password" % base.getid(user), params)
@ -63,7 +63,7 @@ class UserManager(base.ManagerWithFind):
Update default tenant.
"""
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
# not a subresource!???
@ -73,7 +73,8 @@ class UserManager(base.ManagerWithFind):
"""
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,
"password": password,
"tenantId": tenant_id,

View File

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

View File

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

View File

@ -844,6 +844,7 @@ def do_volume_detach(cs, args):
cs.volumes.delete_server_volume(_find_server(cs, args.server).id,
args.attachment_id)
def _print_floating_ip_list(floating_ips):
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('--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):
"""Create a new key pair for use with instances"""
name = args.name
@ -1049,7 +1051,8 @@ def do_keypair_add(cs, args):
with open(pub_key) as f:
pub_key = f.read()
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)
@ -1070,4 +1073,3 @@ def do_keypair_list(cs, args):
keypairs = cs.keypairs.list()
columns = ['Name', 'Fingerprint']
utils.print_list(keypairs, columns)

View File

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