Indicate unused variables and other misc. house cleaning.

Change-Id: I4529d8b6b27dddb1b79ee2167a054b471eaf0dbc
This commit is contained in:
Josh Kearney 2012-06-26 11:34:31 -05:00
parent b7c51840b9
commit d4c9b12f39
8 changed files with 57 additions and 45 deletions

View File

@ -0,0 +1,13 @@
# Copyright 2012 OpenStack LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -56,11 +56,10 @@ class Manager(utils.HookableMixin):
self.api = api
def _list(self, url, response_key, obj_class=None, body=None):
resp = None
if body:
resp, body = self.api.client.post(url, body=body)
_resp, body = self.api.client.post(url, body=body)
else:
resp, body = self.api.client.get(url)
_resp, body = self.api.client.get(url)
if obj_class is None:
obj_class = self.resource_class
@ -138,7 +137,7 @@ class Manager(utils.HookableMixin):
cache.write("%s\n" % val)
def _get(self, url, response_key=None):
resp, body = self.api.client.get(url)
_resp, body = self.api.client.get(url)
if response_key:
return self.resource_class(self, body[response_key], loaded=True)
else:
@ -146,7 +145,7 @@ class Manager(utils.HookableMixin):
def _create(self, url, body, response_key, return_raw=False, **kwargs):
self.run_hooks('modify_body_for_create', body, **kwargs)
resp, body = self.api.client.post(url, body=body)
_resp, body = self.api.client.post(url, body=body)
if return_raw:
return body[response_key]
@ -155,11 +154,11 @@ class Manager(utils.HookableMixin):
return self.resource_class(self, body[response_key])
def _delete(self, url):
resp, body = self.api.client.delete(url)
_resp, _body = self.api.client.delete(url)
def _update(self, url, body, **kwargs):
self.run_hooks('modify_body_for_update', body, **kwargs)
resp, body = self.api.client.put(url, body=body)
_resp, body = self.api.client.put(url, body=body)
return body

View File

@ -196,7 +196,7 @@ class OpenStackComputeShell(object):
def _discover_extensions(self, version):
extensions = []
for name, module in itertools.chain(
self._discover_via_python_path(version),
self._discover_via_python_path(),
self._discover_via_contrib_path(version)):
extension = novaclient.extension.Extension(name, module)
@ -204,8 +204,8 @@ class OpenStackComputeShell(object):
return extensions
def _discover_via_python_path(self, version):
for (module_loader, name, ispkg) in pkgutil.iter_modules():
def _discover_via_python_path(self):
for (module_loader, name, _ispkg) in pkgutil.iter_modules():
if name.endswith('python_novaclient_ext'):
if not hasattr(module_loader, 'load_module'):
# Python 2.6 compat: actually get an ImpImporter obj
@ -243,11 +243,11 @@ class OpenStackComputeShell(object):
command = attr[3:].replace('_', '-')
callback = getattr(actions_module, attr)
desc = callback.__doc__ or ''
help = desc.strip().split('\n')[0]
action_help = desc.strip().split('\n')[0]
arguments = getattr(callback, 'arguments', [])
subparser = subparsers.add_parser(command,
help=help,
help=action_help,
description=desc,
add_help=False,
formatter_class=OpenStackHelpFormatter
@ -411,7 +411,7 @@ class OpenStackComputeShell(object):
for extension in self.extensions:
extension.run_hooks(hook_type, *args, **kwargs)
def do_bash_completion(self, args):
def do_bash_completion(self, _args):
"""
Prints all of the commands and options to stdout so that the
nova.bash_completion script doesn't have to hard code them.

View File

@ -16,13 +16,13 @@ def arg(*args, **kwargs):
return _decorator
def env(*vars, **kwargs):
def env(*args, **kwargs):
"""
returns the first environment variable set
if none are non-empty, defaults to '' or keyword arg default
"""
for v in vars:
value = os.environ.get(v, None)
for arg in args:
value = os.environ.get(arg, None)
if value:
return value
return kwargs.get('default', '')
@ -149,11 +149,11 @@ def print_list(objs, fields, formatters={}, sortby_index=0):
print pt.get_string(sortby=sortby)
def print_dict(d, property="Property"):
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
def print_dict(d, dict_property="Property"):
pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False)
pt.align = 'l'
[pt.add_row(list(r)) for r in d.iteritems()]
print pt.get_string(sortby=property)
print pt.get_string(sortby=dict_property)
def find_resource(manager, name_or_id):

View File

@ -51,14 +51,14 @@ class SecurityGroupManager(base.ManagerWithFind):
"""
self._delete('/os-security-groups/%s' % base.getid(group))
def get(self, id):
def get(self, group_id):
"""
Get a security group
:param group: The security group to get by ID
:param group_id: The security group to get by ID
:rtype: :class:`SecurityGroup`
"""
return self._get('/os-security-groups/%s' % id,
return self._get('/os-security-groups/%s' % group_id,
'security_group')
def list(self):

View File

@ -177,14 +177,14 @@ class Server(base.Resource):
"""
self.manager.change_password(self, password)
def reboot(self, type=REBOOT_SOFT):
def reboot(self, reboot_type=REBOOT_SOFT):
"""
Reboot the server.
:param type: either :data:`REBOOT_SOFT` for a software-level reboot,
or `REBOOT_HARD` for a virtual power cycle hard reboot.
:param reboot_type: either :data:`REBOOT_SOFT` for a software-level
reboot, or `REBOOT_HARD` for a virtual power cycle hard reboot.
"""
self.manager.reboot(self, type)
self.manager.reboot(self, reboot_type)
def rebuild(self, image, password=None, **kwargs):
"""
@ -515,15 +515,15 @@ class ServerManager(local_base.BootingManagerWithFind):
"""
self._delete("/servers/%s" % base.getid(server))
def reboot(self, server, type=REBOOT_SOFT):
def reboot(self, server, reboot_type=REBOOT_SOFT):
"""
Reboot a server.
:param server: The :class:`Server` (or its ID) to share onto.
:param type: either :data:`REBOOT_SOFT` for a software-level reboot,
or `REBOOT_HARD` for a virtual power cycle hard reboot.
:param reboot_type: either :data:`REBOOT_SOFT` for a software-level
reboot, or `REBOOT_HARD` for a virtual power cycle hard reboot.
"""
self._action('reboot', server, {'type': type})
self._action('reboot', server, {'type': reboot_type})
def rebuild(self, server, image, password=None, **kwargs):
"""
@ -536,7 +536,7 @@ class ServerManager(local_base.BootingManagerWithFind):
body = {'imageRef': base.getid(image)}
if password is not None:
body['adminPass'] = password
resp, body = self._action('rebuild', server, body, **kwargs)
_resp, body = self._action('rebuild', server, body, **kwargs)
return Server(self, body['server'])
def migrate(self, server):

View File

@ -234,7 +234,7 @@ def do_boot(cs, args):
_poll_for_status(cs.servers.get, info['id'], 'building', ['active'])
def do_cloudpipe_list(cs, args):
def do_cloudpipe_list(cs, _args):
"""Print a list of all cloudpipe instances."""
cloudpipes = cs.cloudpipe.list()
columns = ['Project Id', "Public IP", "Public Port", "Internal IP"]
@ -301,7 +301,7 @@ def _print_flavor_list(flavors):
'RXTX_Factor'])
def do_flavor_list(cs, args):
def do_flavor_list(cs, _args):
"""Print a list of available 'flavors' (sizes of servers)."""
flavors = cs.flavors.list()
_print_flavor_list(flavors)
@ -358,7 +358,7 @@ def do_flavor_create(cs, args):
_print_flavor_list([f])
def do_image_list(cs, args):
def do_image_list(cs, _args):
"""Print a list of available images to boot from."""
image_list = cs.images.list()
@ -860,11 +860,11 @@ def _find_volume_snapshot(cs, snapshot):
return utils.find_resource(cs.volume_snapshots, snapshot)
def _print_volume(cs, volume):
def _print_volume(volume):
utils.print_dict(volume._info)
def _print_volume_snapshot(cs, snapshot):
def _print_volume_snapshot(snapshot):
utils.print_dict(snapshot._info)
@ -887,7 +887,7 @@ def _translate_volume_snapshot_keys(collection):
@utils.service_type('volume')
def do_volume_list(cs, args):
def do_volume_list(cs, _args):
"""List all the volumes."""
volumes = cs.volumes.list()
_translate_volume_keys(volumes)
@ -905,7 +905,7 @@ def do_volume_list(cs, args):
def do_volume_show(cs, args):
"""Show details about a volume."""
volume = _find_volume(cs, args.volume)
_print_volume(cs, volume)
_print_volume(volume)
@utils.arg('size',
@ -972,7 +972,7 @@ def do_volume_detach(cs, args):
@utils.service_type('volume')
def do_volume_snapshot_list(cs, args):
def do_volume_snapshot_list(cs, _args):
"""List all the snapshots."""
snapshots = cs.volume_snapshots.list()
_translate_volume_snapshot_keys(snapshots)
@ -985,7 +985,7 @@ def do_volume_snapshot_list(cs, args):
def do_volume_snapshot_show(cs, args):
"""Show details about a snapshot."""
snapshot = _find_volume_snapshot(cs, args.snapshot)
_print_volume_snapshot(cs, snapshot)
_print_volume_snapshot(snapshot)
@utils.arg('volume_id',
@ -1120,12 +1120,12 @@ def do_floating_ip_delete(cs, args):
raise exceptions.CommandError("Floating ip %s not found.", args.address)
def do_floating_ip_list(cs, args):
def do_floating_ip_list(cs, _args):
"""List floating ips for this tenant."""
_print_floating_ip_list(cs.floating_ips.list())
def do_floating_ip_pool_list(cs, args):
def do_floating_ip_pool_list(cs, _args):
"""List all floating ip pools."""
utils.print_list(cs.floating_ip_pools.list(), ['name'])
@ -1649,14 +1649,14 @@ def do_host_action(cs, args):
utils.print_list([result], ['HOST', 'power_action'])
def do_endpoints(cs, args):
def do_endpoints(cs, _args):
"""Discover endpoints that get returned from the authenticate services"""
catalog = cs.client.service_catalog.catalog
for e in catalog['access']['serviceCatalog']:
utils.print_dict(e['endpoints'][0], e['name'])
def do_credentials(cs, args):
def do_credentials(cs, _args):
"""Show user credentials returned from auth"""
catalog = cs.client.service_catalog.catalog
utils.print_dict(catalog['access']['user'], "User Credentials")

View File

@ -108,7 +108,7 @@ class ServersTest(utils.TestCase):
s = cs.servers.get(1234)
s.reboot()
cs.assert_called('POST', '/servers/1234/action')
cs.servers.reboot(s, type='HARD')
cs.servers.reboot(s, reboot_type='HARD')
cs.assert_called('POST', '/servers/1234/action')
def test_rebuild_server(self):