Upgraded to PEP8 1.3.3 to stay aligned with Nova, etc.

Made all the necessary changes to pass new PEP8 standards.

Also cleaned up docstrings to conform to the HACKING stanards.

Change-Id: Ib8df3030da7a7885655689ab5da0717748c9edbe
This commit is contained in:
Josh Kearney 2013-01-31 13:31:41 -06:00
parent ba4be2af5a
commit cdee965095
7 changed files with 93 additions and 128 deletions

View File

@ -13,8 +13,7 @@
# under the License.
#
"""Manage access to the clients, including authenticating when needed.
"""
"""Manage access to the clients, including authenticating when needed."""
import logging
@ -22,13 +21,12 @@ from openstackclient.compute import client as compute_client
from openstackclient.identity import client as identity_client
from openstackclient.image import client as image_client
LOG = logging.getLogger(__name__)
class ClientCache(object):
"""Descriptor class for caching created client handles.
"""
"""Descriptor class for caching created client handles."""
def __init__(self, factory):
self.factory = factory
self._handle = None
@ -41,20 +39,14 @@ class ClientCache(object):
class ClientManager(object):
"""Manages access to API clients, including authentication.
"""
"""Manages access to API clients, including authentication."""
compute = ClientCache(compute_client.make_client)
identity = ClientCache(identity_client.make_client)
image = ClientCache(image_client.make_client)
def __init__(self, token=None, url=None,
auth_url=None,
tenant_name=None, tenant_id=None,
username=None, password=None,
region_name=None,
api_version=None,
):
def __init__(self, token=None, url=None, auth_url=None, tenant_name=None,
tenant_id=None, username=None, password=None,
region_name=None, api_version=None):
self._token = token
self._url = url
self._auth_url = auth_url
@ -74,8 +66,7 @@ class ClientManager(object):
return
def get_endpoint_for_service_type(self, service_type):
"""Return the endpoint URL for the service type.
"""
"""Return the endpoint URL for the service type."""
# See if we are using password flow auth, i.e. we have a
# service catalog to select endpoints from
if self._service_catalog:

View File

@ -13,17 +13,13 @@
# under the License.
#
"""
OpenStack base command
"""
"""OpenStack base command"""
from cliff.command import Command
class OpenStackCommand(Command):
"""Base class for OpenStack commands
"""
"""Base class for OpenStack commands."""
api = None
def run(self, parsed_args):

View File

@ -13,9 +13,7 @@
# under the License.
#
"""
Exception definitions.
"""
"""Exception definitions."""
class CommandError(Exception):
@ -27,8 +25,7 @@ class AuthorizationFailure(Exception):
class NoTokenLookupException(Exception):
"""This form of authentication does not support looking up
endpoints from an existing token."""
"""This does not support looking up endpoints from an existing token."""
pass
@ -38,15 +35,12 @@ class EndpointNotFound(Exception):
class UnsupportedVersion(Exception):
"""Indicates that the user is trying to use an unsupported
version of the API"""
"""The user is trying to use an unsupported version of the API"""
pass
class ClientException(Exception):
"""
The base exception class for all exceptions this library raises.
"""
"""The base exception class for all exceptions this library raises."""
def __init__(self, code, message=None, details=None):
self.code = code
self.message = message or self.__class__.message
@ -57,59 +51,44 @@ class ClientException(Exception):
class BadRequest(ClientException):
"""
HTTP 400 - Bad request: you sent some malformed data.
"""
"""HTTP 400 - Bad request: you sent some malformed data."""
http_status = 400
message = "Bad request"
class Unauthorized(ClientException):
"""
HTTP 401 - Unauthorized: bad credentials.
"""
"""HTTP 401 - Unauthorized: bad credentials."""
http_status = 401
message = "Unauthorized"
class Forbidden(ClientException):
"""
HTTP 403 - Forbidden: your credentials don't give you access to this
resource.
"""
"""HTTP 403 - Forbidden: not authorized to access to this resource."""
http_status = 403
message = "Forbidden"
class NotFound(ClientException):
"""
HTTP 404 - Not found
"""
"""HTTP 404 - Not found"""
http_status = 404
message = "Not found"
class Conflict(ClientException):
"""
HTTP 409 - Conflict
"""
"""HTTP 409 - Conflict"""
http_status = 409
message = "Conflict"
class OverLimit(ClientException):
"""
HTTP 413 - Over limit: you're over the API limits for this time period.
"""
"""HTTP 413 - Over limit: reached the API limits for this time period."""
http_status = 413
message = "Over limit"
# NotImplemented is a python keyword.
class HTTPNotImplemented(ClientException):
"""
HTTP 501 - Not Implemented: the server does not support this operation.
"""
"""HTTP 501 - Not Implemented: server does not support this operation."""
http_status = 501
message = "Not Implemented"
@ -120,14 +99,18 @@ class HTTPNotImplemented(ClientException):
# for c in ClientException.__subclasses__())
#
# Instead, we have to hardcode it:
_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized,
Forbidden, NotFound, OverLimit, HTTPNotImplemented])
_code_map = dict((c.http_status, c) for c in [
BadRequest,
Unauthorized,
Forbidden,
NotFound,
OverLimit,
HTTPNotImplemented
])
def from_response(response, body):
"""
Return an instance of a ClientException or subclass
based on an httplib2 response.
"""Return an instance of a ClientException based on an httplib2 response.
Usage::

View File

@ -13,9 +13,7 @@
# under the License.
#
"""
Common client utilities
"""
"""Common client utilities"""
import os
import sys

View File

@ -13,9 +13,7 @@
# under the License.
#
"""
Command-line interface to the OpenStack APIs
"""
"""Command-line interface to the OpenStack APIs"""
import getpass
import logging
@ -59,8 +57,7 @@ class OpenStackShell(App):
super(OpenStackShell, self).__init__(
description=__doc__.strip(),
version=VERSION,
command_manager=CommandManager('openstack.cli'),
)
command_manager=CommandManager('openstack.cli'))
# This is instantiated in initialize_app() only when using
# password flow auth
@ -69,57 +66,64 @@ class OpenStackShell(App):
def build_option_parser(self, description, version):
parser = super(OpenStackShell, self).build_option_parser(
description,
version,
)
version)
# Global arguments
parser.add_argument('--os-auth-url', metavar='<auth-url>',
parser.add_argument(
'--os-auth-url',
metavar='<auth-url>',
default=env('OS_AUTH_URL'),
help='Authentication URL (Env: OS_AUTH_URL)')
parser.add_argument('--os-tenant-name', metavar='<auth-tenant-name>',
parser.add_argument(
'--os-tenant-name',
metavar='<auth-tenant-name>',
default=env('OS_TENANT_NAME'),
help='Authentication tenant name (Env: OS_TENANT_NAME)')
parser.add_argument('--os-tenant-id', metavar='<auth-tenant-id>',
parser.add_argument(
'--os-tenant-id',
metavar='<auth-tenant-id>',
default=env('OS_TENANT_ID'),
help='Authentication tenant ID (Env: OS_TENANT_ID)')
parser.add_argument('--os-username', metavar='<auth-username>',
parser.add_argument(
'--os-username',
metavar='<auth-username>',
default=utils.env('OS_USERNAME'),
help='Authentication username (Env: OS_USERNAME)')
parser.add_argument('--os-password', metavar='<auth-password>',
parser.add_argument(
'--os-password',
metavar='<auth-password>',
default=utils.env('OS_PASSWORD'),
help='Authentication password (Env: OS_PASSWORD)')
parser.add_argument('--os-region-name', metavar='<auth-region-name>',
parser.add_argument(
'--os-region-name',
metavar='<auth-region-name>',
default=env('OS_REGION_NAME'),
help='Authentication region name (Env: OS_REGION_NAME)')
parser.add_argument('--os-identity-api-version',
parser.add_argument(
'--os-identity-api-version',
metavar='<identity-api-version>',
default=env('OS_IDENTITY_API_VERSION', default='2.0'),
help='Identity API version, default=2.0 '
'(Env: OS_IDENTITY_API_VERSION)')
parser.add_argument('--os-compute-api-version',
parser.add_argument(
'--os-compute-api-version',
metavar='<compute-api-version>',
default=env('OS_COMPUTE_API_VERSION', default='2'),
help='Compute API version, default=2 '
'(Env: OS_COMPUTE_API_VERSION)')
parser.add_argument('--os-image-api-version',
parser.add_argument(
'--os-image-api-version',
metavar='<image-api-version>',
default=env('OS_IMAGE_API_VERSION', default='1.0'),
help='Image API version, default=1.0 '
'(Env: OS_IMAGE_API_VERSION)')
parser.add_argument('--os-token', metavar='<token>',
help='Image API version, default=1.0 (Env: OS_IMAGE_API_VERSION)')
parser.add_argument(
'--os-token',
metavar='<token>',
default=env('OS_TOKEN'),
help='Defaults to env[OS_TOKEN]')
parser.add_argument('--os-url', metavar='<url>',
parser.add_argument(
'--os-url',
metavar='<url>',
default=env('OS_URL'),
help='Defaults to env[OS_URL]')
@ -198,8 +202,7 @@ class OpenStackShell(App):
username=self.options.os_username,
password=self.options.os_password,
region_name=self.options.os_region_name,
api_version=self.api_version,
)
api_version=self.api_version)
return
def init_keyring_backend(self):
@ -260,7 +263,6 @@ class OpenStackShell(App):
def prepare_to_run_command(self, cmd):
"""Set up auth and API versions"""
self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__)
self.log.debug("api: %s" % cmd.api if hasattr(cmd, 'api') else None)
return

View File

@ -63,7 +63,6 @@ setuptools.setup(
'openstackclient.identity.v2_0.endpoint:ListEndpoint',
'show_endpoint=' +
'openstackclient.identity.v2_0.endpoint:ShowEndpoint',
'add_role=' +
'openstackclient.identity.v2_0.role:AddRole',
'create_role=' +
@ -74,7 +73,6 @@ setuptools.setup(
'remove_role=' +
'openstackclient.identity.v2_0.role:RemoveRole',
'show_role=openstackclient.identity.v2_0.role:ShowRole',
'create_server=openstackclient.compute.v2.server:CreateServer',
'delete_server=openstackclient.compute.v2.server:DeleteServer',
'list_server=openstackclient.compute.v2.server:ListServer',
@ -85,14 +83,12 @@ setuptools.setup(
'show_server=openstackclient.compute.v2.server:ShowServer',
'suspend_server=openstackclient.compute.v2.server:SuspendServer',
'unpause_server=openstackclient.compute.v2.server:UnpauseServer',
'create_service=' +
'openstackclient.identity.v2_0.service:CreateService',
'delete_service=' +
'openstackclient.identity.v2_0.service:DeleteService',
'list_service=openstackclient.identity.v2_0.service:ListService',
'show_service=openstackclient.identity.v2_0.service:ShowService',
'create_tenant=' +
'openstackclient.identity.v2_0.tenant:CreateTenant',
'delete_tenant=' +
@ -100,7 +96,6 @@ setuptools.setup(
'list_tenant=openstackclient.identity.v2_0.tenant:ListTenant',
'set_tenant=openstackclient.identity.v2_0.tenant:SetTenant',
'show_tenant=openstackclient.identity.v2_0.tenant:ShowTenant',
'create_user=' +
'openstackclient.identity.v2_0.user:CreateUser',
'delete_user=' +

View File

@ -11,7 +11,7 @@ deps = -r{toxinidir}/tools/pip-requires
commands = python setup.py testr --testr-args='{posargs}'
[testenv:pep8]
deps = pep8==1.1
deps = pep8==1.3.3
commands = pep8 --repeat --show-source openstackclient setup.py
[testenv:venv]