diff options
author | Sushil Kumar <sushil.kumar2@globallogic.com> | 2014-01-13 17:04:50 +0000 |
---|---|---|
committer | Sushil Kumar <sushil.kumar2@globallogic.com> | 2014-05-09 08:54:39 +0000 |
commit | 8bc695bd70853305bdd1009a69503728712f57a5 (patch) | |
tree | 315d6cb2c99ce9d610b32a6340d58b2decce60ad | |
parent | 4643f78a200aff5155e7029dfde0eebe9bef0e70 (diff) | |
download | python-troveclient-8bc695bd70853305bdd1009a69503728712f57a5.tar.gz |
Enabled F821, H306, H402, and H404 flake8 rule
Reasons:
- F821 is disabled.
- H306 is disabled.
- H402 is disabled.
- H404 is disabled.
Changes:
- Updates tox.ini to enable F821, H306, H402 and H404 rules.
- Updates code for F821, H306, H402 and H404 violation.
Change-Id: I772270bb833ac774e080fc63e330d6b333f23de2
45 files changed, 304 insertions, 484 deletions
@@ -33,6 +33,6 @@ commands = python setup.py build_sphinx [flake8] -ignore = F821,H202,H306,H402,H404 +ignore = H202 show-source = True exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build, diff --git a/troveclient/base.py b/troveclient/base.py index 99d6988..cc005d4 100644 --- a/troveclient/base.py +++ b/troveclient/base.py @@ -26,10 +26,10 @@ import os import six from six.moves.urllib import parse +from troveclient import common from troveclient.openstack.common.apiclient import base from troveclient.openstack.common.apiclient import exceptions from troveclient import utils -from troveclient import common # Python 2.4 compat try: @@ -40,9 +40,10 @@ except NameError: def getid(obj): - """ - Abstracts the common pattern of allowing both an object or an object's ID - as a parameter when dealing with relationships. + """Retrieves an id from object or integer. + + Abstracts the common pattern of allowing both an object or an object's + ID as a parameter when dealing with relationships. """ try: return obj.id @@ -51,9 +52,10 @@ def getid(obj): class Manager(utils.HookableMixin): - """ - Managers interact with a particular type of API (servers, flavors, images, - etc.) and provide CRUD operations for them. + """Manager defining CRUD operations for API. + + Managers interact with a particular type of API (servers, flavors, + images, etc.) and provide CRUD operations for them. """ resource_class = None @@ -101,7 +103,8 @@ class Manager(utils.HookableMixin): @contextlib.contextmanager def completion_cache(self, cache_type, obj_class, mode): - """ + """Bash-completion cache. + The completion cache store items that can be used for bash autocompletion, like UUIDs or human-friendly IDs. @@ -185,17 +188,14 @@ class Manager(utils.HookableMixin): class ManagerWithFind(six.with_metaclass(abc.ABCMeta, Manager)): - """ - Like a `Manager`, but with additional `find()`/`findall()` methods. - """ + """Like a `Manager`, but with additional `find()`/`findall()` methods.""" @abc.abstractmethod def list(self): pass def find(self, **kwargs): - """ - Find a single item with attributes matching ``**kwargs``. + """Find a single item with attributes matching ``**kwargs``. This isn't very efficient: it loads the entire list then filters on the Python side. @@ -211,8 +211,7 @@ class ManagerWithFind(six.with_metaclass(abc.ABCMeta, Manager)): return matches[0] def findall(self, **kwargs): - """ - Find all items with attributes matching ``**kwargs``. + """Find all items with attributes matching ``**kwargs``. This isn't very efficient: it loads the entire list then filters on the Python side. @@ -232,10 +231,9 @@ class ManagerWithFind(six.with_metaclass(abc.ABCMeta, Manager)): class Resource(base.Resource): - """ - A resource represents a particular instance of an object (server, flavor, - etc). This is pretty much just a bag for attributes. + """A resource represents a particular instance of an object like server. + This is pretty much just a bag for attributes. :param manager: Manager object :param info: dictionary representing resource attributes :param loaded: prevent lazy-loading if set to True diff --git a/troveclient/client.py b/troveclient/client.py index 58a15fb..25a2235 100644 --- a/troveclient/client.py +++ b/troveclient/client.py @@ -24,9 +24,10 @@ from __future__ import print_function import logging import os import requests + +from troveclient.openstack.common.apiclient import client from troveclient.openstack.common.apiclient import exceptions from troveclient import service_catalog -from troveclient.openstack.common.apiclient import client try: import urlparse diff --git a/troveclient/compat/__init__.py b/troveclient/compat/__init__.py index 55d8ef8..a08dcb8 100644 --- a/troveclient/compat/__init__.py +++ b/troveclient/compat/__init__.py @@ -14,19 +14,19 @@ # under the License. +from troveclient.compat.client import Dbaas # noqa +from troveclient.compat.client import TroveHTTPClient # noqa +from troveclient.compat.versions import Versions # noqa from troveclient.v1.accounts import Accounts # noqa from troveclient.v1.databases import Databases # noqa +from troveclient.v1.diagnostics import DiagnosticsInterrogator # noqa +from troveclient.v1.diagnostics import HwInfoInterrogator # noqa from troveclient.v1.flavors import Flavors # noqa -from troveclient.v1.instances import Instances # noqa from troveclient.v1.hosts import Hosts # noqa +from troveclient.v1.instances import Instances # noqa from troveclient.v1.management import Management # noqa -from troveclient.v1.management import RootHistory # noqa from troveclient.v1.management import MgmtFlavors # noqa +from troveclient.v1.management import RootHistory # noqa from troveclient.v1.root import Root # noqa from troveclient.v1.storage import StorageInfo # noqa from troveclient.v1.users import Users # noqa -from troveclient.compat.versions import Versions # noqa -from troveclient.v1.diagnostics import DiagnosticsInterrogator # noqa -from troveclient.v1.diagnostics import HwInfoInterrogator # noqa -from troveclient.compat.client import Dbaas # noqa -from troveclient.compat.client import TroveHTTPClient # noqa diff --git a/troveclient/compat/auth.py b/troveclient/compat/auth.py index f7e0ea9..8482fea 100644 --- a/troveclient/compat/auth.py +++ b/troveclient/compat/auth.py @@ -38,8 +38,7 @@ def get_authenticator_cls(cls_or_name): class Authenticator(object): - """ - Helper class to perform Keystone or other miscellaneous authentication. + """Helper class to perform Keystone or other miscellaneous authentication. The "authenticate" method returns a ServiceCatalog, which can be used to obtain a token. @@ -154,7 +153,8 @@ class RaxAuthenticator(Authenticator): class RaxAuthenticator2(RaxAuthenticator): - """ + """Rax specific authenticator. + Necessary to be able to call using the same auth url as the new client uses for Rax auth. """ @@ -225,7 +225,8 @@ class ServiceCatalog(object): def _url_for(self, attr=None, filter_value=None, endpoint_type='publicURL'): - """ + """Fetch requested URL. + Fetch the public URL from the Trove service for a particular endpoint attribute. If none given, return the first. """ diff --git a/troveclient/compat/base.py b/troveclient/compat/base.py index 915ec71..b83e746 100644 --- a/troveclient/compat/base.py +++ b/troveclient/compat/base.py @@ -35,9 +35,10 @@ except NameError: def getid(obj): - """ - Abstracts the common pattern of allowing both an object or an object's ID - as a parameter when dealing with relationships. + """Retrives an id from object or integer. + + Abstracts the common pattern of allowing both an object or an object's + ID as a parameter when dealing with relationships. """ try: return obj.id @@ -46,9 +47,10 @@ def getid(obj): class Manager(utils.HookableMixin): - """ - Managers interact with a particular type of API (servers, flavors, images, - etc.) and provide CRUD operations for them. + """Manager defining CRUD operations for API. + + Managers interact with a particular type of API (servers, flavors, + images, etc.) and provide CRUD operations for them. """ resource_class = None @@ -81,7 +83,8 @@ class Manager(utils.HookableMixin): @contextlib.contextmanager def completion_cache(self, cache_type, obj_class, mode): - """ + """Bash-completion cache. + The completion cache store items that can be used for bash autocompletion, like UUIDs or human-friendly IDs. @@ -164,13 +167,10 @@ class Manager(utils.HookableMixin): class ManagerWithFind(Manager): - """ - Like a `Manager`, but with additional `find()`/`findall()` methods. - """ + """Like a `Manager`, but with additional `find()`/`findall()` methods.""" def find(self, **kwargs): - """ - Find a single item with attributes matching ``**kwargs``. + """Find a single item with attributes matching ``**kwargs``. This isn't very efficient: it loads the entire list then filters on the Python side. @@ -186,8 +186,7 @@ class ManagerWithFind(Manager): return matches[0] def findall(self, **kwargs): - """ - Find all items with attributes matching ``**kwargs``. + """Find all items with attributes matching ``**kwargs``. This isn't very efficient: it loads the entire list then filters on the Python side. @@ -210,10 +209,9 @@ class ManagerWithFind(Manager): class Resource(object): - """ - A resource represents a particular instance of an object (server, flavor, - etc). This is pretty much just a bag for attributes. + """A resource represents a particular instance of an object like server. + This is pretty much just a bag for attributes. :param manager: Manager object :param info: dictionary representing resource attributes :param loaded: prevent lazy-loading if set to True @@ -238,9 +236,7 @@ class Resource(object): @property def human_id(self): - """Subclasses may override this provide a pretty ID which can be used - for bash completion. - """ + """Provides a pretty ID which can be used for bash completion.""" if 'name' in self.__dict__ and self.HUMAN_ID: return utils.slugify(self.name) return None diff --git a/troveclient/compat/cli.py b/troveclient/compat/cli.py index 0a144eb..3244027 100644 --- a/troveclient/compat/cli.py +++ b/troveclient/compat/cli.py @@ -35,7 +35,7 @@ from troveclient.compat import common class InstanceCommands(common.AuthedCommandsBase): - """Commands to perform various instance operations and actions""" + """Commands to perform various instance operations and actions.""" params = [ 'flavor', @@ -64,7 +64,7 @@ class InstanceCommands(common.AuthedCommandsBase): return configuration_ref def create(self): - """Create a new instance""" + """Create a new instance.""" self._require('name', 'flavor') volume = None if self.size: @@ -79,28 +79,28 @@ class InstanceCommands(common.AuthedCommandsBase): # TODO(pdmars): is this actually what this should be named? def modify(self): - """Modify an instance""" + """Modify an instance.""" self._require('id') self._pretty_print(self.dbaas.instances.modify, self.id, configuration_ref=self._get_configuration_ref()) def delete(self): - """Delete the specified instance""" + """Delete the specified instance.""" self._require('id') print(self.dbaas.instances.delete(self.id)) def get(self): - """Get details for the specified instance""" + """Get details for the specified instance.""" self._require('id') self._pretty_print(self.dbaas.instances.get, self.id) def backups(self): - """Get a list of backups for the specified instance""" + """Get a list of backups for the specified instance.""" self._require('id') self._pretty_list(self.dbaas.instances.backups, self.id) def list(self): - """List all instances for account""" + """List all instances for account.""" # limit and marker are not required. limit = self.limit or None if limit: @@ -108,7 +108,7 @@ class InstanceCommands(common.AuthedCommandsBase): self._pretty_paged(self.dbaas.instances.list) def resize_volume(self): - """Resize an instance volume""" + """Resize an instance volume.""" self._require('id', 'size') self._pretty_print(self.dbaas.instances.resize_volume, self.id, self.size) @@ -120,28 +120,28 @@ class InstanceCommands(common.AuthedCommandsBase): self.flavor) def restart(self): - """Restart the database""" + """Restart the database.""" self._require('id') self._pretty_print(self.dbaas.instances.restart, self.id) def configuration(self): - """Get configuration for the specified instance""" + """Get configuration for the specified instance.""" self._require('id') self._pretty_print(self.dbaas.instances.configuration, self.id) class FlavorsCommands(common.AuthedCommandsBase): - """Commands for listing Flavors""" + """Command for listing Flavors.""" params = [] def list(self): - """List the available flavors""" + """List the available flavors.""" self._pretty_list(self.dbaas.flavors.list) class DatabaseCommands(common.AuthedCommandsBase): - """Database CRUD operations on an instance""" + """Database CRUD operations on an instance.""" params = [ 'name', @@ -151,24 +151,24 @@ class DatabaseCommands(common.AuthedCommandsBase): ] def create(self): - """Create a database""" + """Create a database.""" self._require('id', 'name') databases = [{'name': self.name}] print(self.dbaas.databases.create(self.id, databases)) def delete(self): - """Delete a database""" + """Delete a database.""" self._require('id', 'name') print(self.dbaas.databases.delete(self.id, self.name)) def list(self): - """List the databases""" + """List the databases.""" self._require('id') self._pretty_paged(self.dbaas.databases.list, self.id) class UserCommands(common.AuthedCommandsBase): - """User CRUD operations on an instance""" + """User CRUD operations on an instance.""" params = [ 'id', 'database', @@ -182,7 +182,7 @@ class UserCommands(common.AuthedCommandsBase): ] def create(self): - """Create a user in instance, with access to one or more databases""" + """Create a user in instance, with access to one or more databases.""" self._require('id', 'name', 'password', 'databases') self._make_list('databases') databases = [{'name': dbname} for dbname in self.databases] @@ -218,7 +218,7 @@ class UserCommands(common.AuthedCommandsBase): self.hostname) def list(self): - """List all the users for an instance""" + """List all the users for an instance.""" self._require('id') self._pretty_paged(self.dbaas.users.list, self.id) @@ -253,7 +253,7 @@ class UserCommands(common.AuthedCommandsBase): class RootCommands(common.AuthedCommandsBase): - """Root user related operations on an instance""" + """Root user related operations on an instance.""" params = [ 'id', @@ -269,119 +269,120 @@ class RootCommands(common.AuthedCommandsBase): print(sys.exc_info()[1]) def enabled(self): - """Check the instance for root access""" + """Check the instance for root access.""" self._require('id') self._pretty_print(self.dbaas.root.is_root_enabled, self.id) class VersionCommands(common.AuthedCommandsBase): - """List available versions""" + """List available versions.""" params = [ 'url', ] def list(self): - """List all the supported versions""" + """List all the supported versions.""" self._require('url') self._pretty_list(self.dbaas.versions.index, self.url) class LimitsCommands(common.AuthedCommandsBase): - """Show the rate limits and absolute limits""" + """Show the rate limits and absolute limits.""" def list(self): - """List the rate limits and absolute limits""" + """List the rate limits and absolute limits.""" self._pretty_list(self.dbaas.limits.list) class BackupsCommands(common.AuthedCommandsBase): - """Command to manage and show backups""" + """Command to manage and show backups.""" params = ['name', 'instance', 'description'] def get(self): - """Get details for the specified backup""" + """Get details for the specified backup.""" self._require('id') self._pretty_print(self.dbaas.backups.get, self.id) def list(self): - """List backups""" + """List backups.""" self._pretty_list(self.dbaas.backups.list) def create(self): - """Create a new backup""" + """Create a new backup.""" self._require('name', 'instance') self._pretty_print(self.dbaas.backups.create, self.name, self.instance, self.description) def delete(self): - """Delete a backup""" + """Delete a backup.""" self._require('id') self._pretty_print(self.dbaas.backups.delete, self.id) class DatastoreConfigurationParameters(common.AuthedCommandsBase): - """Command to show configuration parameters for a datastore""" + """Command to show configuration parameters for a datastore.""" params = ['datastore', 'parameter'] def parameters(self): - """List parameters that can be set""" + """List parameters that can be set.""" self._require('datastore') self._pretty_print(self.dbaas.configuration_parameters.parameters, self.datastore) def get_parameter(self): - """List parameters that can be set""" + """List parameters that can be set.""" self._require('datastore', 'parameter') self._pretty_print(self.dbaas.configuration_parameters.get_parameter, self.datastore, self.parameter) class ConfigurationsCommands(common.AuthedCommandsBase): - """Command to manage and show configurations""" + """Command to manage and show configurations.""" params = ['name', 'instances', 'values', 'description', 'parameter'] def get(self): - """Get details for the specified configuration""" + """Get details for the specified configuration.""" self._require('id') self._pretty_print(self.dbaas.configurations.get, self.id) def list_instances(self): - """Get details for the specified configuration""" + """Get details for the specified configuration.""" self._require('id') self._pretty_list(self.dbaas.configurations.instances, self.id) def list(self): - """List configurations""" + """List configurations.""" self._pretty_list(self.dbaas.configurations.list) def create(self): - """Create a new configuration""" + """Create a new configuration.""" self._require('name', 'values') self._pretty_print(self.dbaas.configurations.create, self.name, self.values, self.description) def update(self): - """Update an existing configuration""" + """Update an existing configuration.""" self._require('id', 'values') self._pretty_print(self.dbaas.configurations.update, self.id, self.values, self.name, self.description) def edit(self): - """Edit an existing configuration values""" + """Edit an existing configuration values.""" self._require('id', 'values') self._pretty_print(self.dbaas.configurations.edit, self.id, self.values) def delete(self): - """Delete a configuration""" + """Delete a configuration.""" self._require('id') self._pretty_print(self.dbaas.configurations.delete, self.id) class SecurityGroupCommands(common.AuthedCommandsBase): - """Commands to list and show Security Groups For an Instance and """ - """create and delete security group rules for them. """ + """Commands to list and show Security Groups For an Instance and + create and delete security group rules for them. + """ params = [ 'id', 'secgroup_id', @@ -397,11 +398,11 @@ class SecurityGroupCommands(common.AuthedCommandsBase): self._pretty_print(self.dbaas.security_groups.get, self.id) def list(self): - """List all the Security Groups and the rules""" + """List all the Security Groups and the rules.""" self._pretty_paged(self.dbaas.security_groups.list) def add_rule(self): - """Add a security group rule""" + """Add a security group rule.""" self._require('secgroup_id', 'protocol', 'from_port', 'to_port', 'cidr') self.dbaas.security_group_rules.create(self.secgroup_id, self.protocol, @@ -409,7 +410,7 @@ class SecurityGroupCommands(common.AuthedCommandsBase): self.cidr) def delete_rule(self): - """Delete a security group rule""" + """Delete a security group rule.""" self._require('id') self.dbaas.security_group_rules.delete(self.id) diff --git a/troveclient/compat/client.py b/troveclient/compat/client.py index b718355..bc40074 100644 --- a/troveclient/compat/client.py +++ b/troveclient/compat/client.py @@ -16,8 +16,8 @@ import httplib2 import logging import os -import time import sys +import time try: import json @@ -277,19 +277,18 @@ class TroveHTTPClient(httplib2.Http): class Dbaas(object): - """ - Top-level object to access the Rackspace Database as a Service API. + """Top-level object to access the Rackspace Database as a Service API. Create an instance with your creds:: - >>> red = Dbaas(USERNAME, API_KEY, TENANT, AUTH_URL, SERVICE_NAME, \ + >> red = Dbaas(USERNAME, API_KEY, TENANT, AUTH_URL, SERVICE_NAME, \ SERVICE_URL) Then call methods on its managers:: - >>> red.instances.list() + >> red.instances.list() ... - >>> red.flavors.list() + >> red.flavors.list() ... &c. @@ -365,8 +364,7 @@ class Dbaas(object): return self.client.get_timings() def authenticate(self): - """ - Authenticate against the server. + """Authenticate against the server. This is called to perform an authentication to retrieve a token. diff --git a/troveclient/compat/common.py b/troveclient/compat/common.py index c735ac6..9f8cba5 100644 --- a/troveclient/compat/common.py +++ b/troveclient/compat/common.py @@ -42,7 +42,7 @@ def check_for_exceptions(resp, body): def print_actions(cmd, actions): - """Print help for the command with list of options and description""" + """Print help for the command with list of options and description.""" print("Available actions for '%s' cmd:" % cmd) for k, v in six.iteritems(actions): print("\t%-20s%s" % (k, v.__doc__)) @@ -50,7 +50,7 @@ def print_actions(cmd, actions): def print_commands(commands): - """Print the list of available commands and description""" + """Print the list of available commands and description.""" print("Available commands") for k, v in six.iteritems(commands): @@ -330,7 +330,7 @@ class CommandsBase(object): class Auth(CommandsBase): - """Authenticate with your username and api key""" + """Authenticate with your username and api key.""" params = [ 'apikey', 'auth_strategy', @@ -350,7 +350,7 @@ class Auth(CommandsBase): self.dbaas = None def login(self): - """Login to retrieve an auth token to use for other api calls""" + """Login to retrieve an auth token to use for other api calls.""" self._require('username', 'apikey', 'tenant_id', 'auth_url') try: self.dbaas = self._get_client() diff --git a/troveclient/compat/exceptions.py b/troveclient/compat/exceptions.py index 9761128..22bba23 100644 --- a/troveclient/compat/exceptions.py +++ b/troveclient/compat/exceptions.py @@ -69,9 +69,7 @@ class AmbiguousEndpoints(Exception): 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, request_id=None): self.code = code self.message = message or self.__class__.message @@ -87,41 +85,32 @@ 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: your don't have 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 OverLimit(ClientException): - """ - HTTP 413 - Over limit: you're over the API limits for this time period. + """HTTP 413 + - Over limit: you're over the API limits for this time period. """ http_status = 413 message = "Over limit" @@ -129,17 +118,15 @@ class OverLimit(ClientException): # NotImplemented is a python keyword. class HTTPNotImplemented(ClientException): - """ - HTTP 501 - Not Implemented: the server does not support this operation. + """HTTP 501 + - Not Implemented: the server does not support this operation. """ http_status = 501 message = "Not Implemented" class UnprocessableEntity(ClientException): - """ - HTTP 422 - Unprocessable Entity: The request cannot be processed. - """ + """HTTP 422 - Unprocessable Entity: The request cannot be processed.""" http_status = 422 message = "Unprocessable Entity" @@ -157,9 +144,7 @@ _code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized, def from_response(response, body): - """ - Return an instance of an ClientException or subclass - based on an httplib2 response. + """Return an instance of an ClientException based on a request's response. Usage:: diff --git a/troveclient/compat/mcli.py b/troveclient/compat/mcli.py index 7a597ed..8dda4d0 100644 --- a/troveclient/compat/mcli.py +++ b/troveclient/compat/mcli.py @@ -43,24 +43,24 @@ def _pretty_print(info): class HostCommands(common.AuthedCommandsBase): - """Commands to list info on hosts""" + """Commands to list info on hosts.""" params = [ 'name', ] def update_all(self): - """Update all instances on a host""" + """Update all instances on a host.""" self._require('name') self.dbaas.hosts.update_all(self.name) def get(self): - """List details for the specified host""" + """List details for the specified host.""" self._require('name') self._pretty_print(self.dbaas.hosts.get, self.name) def list(self): - """List all compute hosts""" + """List all compute hosts.""" self._pretty_list(self.dbaas.hosts.index) @@ -73,12 +73,12 @@ class QuotaCommands(common.AuthedCommandsBase): 'backups'] def list(self): - """List all quotas for a tenant""" + """List all quotas for a tenant.""" self._require('id') self._pretty_print(self.dbaas.quota.show, self.id) def update(self): - """Update quota limits for a tenant""" + """Update quota limits for a tenant.""" self._require('id') self._pretty_print(self.dbaas.quota.update, self.id, dict((param, getattr(self, param)) @@ -99,18 +99,18 @@ class RootCommands(common.AuthedCommandsBase): class AccountCommands(common.AuthedCommandsBase): - """Commands to list account info""" + """Commands to list account info.""" params = [ 'id', ] def list(self): - """List all accounts with non-deleted instances""" + """List all accounts with non-deleted instances.""" self._pretty_print(self.dbaas.accounts.index) def get(self): - """List details for the account provided""" + """List details for the account provided.""" self._require('id') self._pretty_print(self.dbaas.accounts.show, self.id) @@ -132,7 +132,7 @@ class InstanceCommands(common.AuthedCommandsBase): self._pretty_print(self.dbaas.management.show, self.id) def list(self): - """List all instances for account""" + """List all instances for account.""" deleted = None if self.deleted is not None: if self.deleted.lower() in ['true']: @@ -173,17 +173,17 @@ class InstanceCommands(common.AuthedCommandsBase): class StorageCommands(common.AuthedCommandsBase): - """Commands to list devices info""" + """Commands to list devices info.""" params = [] def list(self): - """List details for the storage device""" + """List details for the storage device.""" self._pretty_list(self.dbaas.storage.index) class FlavorsCommands(common.AuthedCommandsBase): - """Commands for managing Flavors""" + """Commands for managing Flavors.""" params = [ 'name', @@ -198,7 +198,7 @@ class FlavorsCommands(common.AuthedCommandsBase): ] def create(self): - """Create a new flavor""" + """Create a new flavor.""" self._require('name', 'ram', 'disk', 'vcpus', 'flavor_id', 'service_type') self._pretty_print(self.dbaas.mgmt_flavor.create, self.name, diff --git a/troveclient/compat/tests/test_auth.py b/troveclient/compat/tests/test_auth.py index 33ebf5e..22b7cdf 100644 --- a/troveclient/compat/tests/test_auth.py +++ b/troveclient/compat/tests/test_auth.py @@ -15,10 +15,10 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools -from troveclient.compat import auth import mock +import testtools +from troveclient.compat import auth from troveclient.compat import exceptions """ diff --git a/troveclient/compat/tests/test_common.py b/troveclient/compat/tests/test_common.py index edd297d..53ed30f 100644 --- a/troveclient/compat/tests/test_common.py +++ b/troveclient/compat/tests/test_common.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -import sys -import optparse -import json import collections +import json +import optparse +import sys -import testtools import mock +import testtools from troveclient.compat import common diff --git a/troveclient/compat/utils.py b/troveclient/compat/utils.py index f8422fd..2b21e9e 100644 --- a/troveclient/compat/utils.py +++ b/troveclient/compat/utils.py @@ -36,9 +36,10 @@ class HookableMixin(object): def env(*vars, **kwargs): - """ - returns the first environment variable set - if none are non-empty, defaults to '' or keyword arg default + """Returns environment variables. + + 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) @@ -50,7 +51,8 @@ def env(*vars, **kwargs): # http://code.activestate.com/recipes/ # 577257-slugify-make-a-string-usable-in-a-url-or-filename/ def slugify(value): - """ + """Converts a string usable in a url or filename. + Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens. diff --git a/troveclient/compat/versions.py b/troveclient/compat/versions.py index 5c8b7d2..3089f2d 100644 --- a/troveclient/compat/versions.py +++ b/troveclient/compat/versions.py @@ -17,23 +17,18 @@ from troveclient.compat import base class Version(base.Resource): - """ - Version is an opaque instance used to hold version information. - """ + """Version is an opaque instance used to hold version information.""" def __repr__(self): return "<Version: %s>" % self.id class Versions(base.ManagerWithFind): - """ - Manage :class:`Versions` information. - """ + """Manage :class:`Versions` information.""" resource_class = Version def index(self, url): - """ - Get a list of all versions. + """Get a list of all versions. :rtype: list of :class:`Versions`. """ diff --git a/troveclient/shell.py b/troveclient/shell.py index e5d9490..0f6522e 100644 --- a/troveclient/shell.py +++ b/troveclient/shell.py @@ -24,20 +24,21 @@ import argparse import glob import imp import itertools +import logging import os import pkgutil import sys -import logging import pkg_resources import six import troveclient import troveclient.extension + from troveclient import client -from troveclient.openstack.common import strutils from troveclient.openstack.common.apiclient import exceptions as exc from troveclient.openstack.common import gettextutils as gtu +from troveclient.openstack.common import strutils from troveclient import utils from troveclient.v1 import shell as shell_v1 @@ -487,9 +488,7 @@ class OpenStackTroveShell(object): @utils.arg('command', metavar='<subcommand>', nargs='?', help='Display help for <subcommand>.') def do_help(self, args): - """ - Displays help about this program or one of its subcommands. - """ + """Displays help about this program or one of its subcommands.""" if args.command: if args.command in self.subcommands: self.subcommands[args.command].print_help() @@ -508,7 +507,8 @@ class OpenStackHelpFormatter(argparse.HelpFormatter): super(OpenStackHelpFormatter, self).start_section(heading) def _format_usage(self, usage, actions, groups, prefix): - """ + """Formats the argument list to correct argument positions. + Print positionals before optionals in the usage string to help users avoid argparse nargs='*' problems. diff --git a/troveclient/tests/test_accounts.py b/troveclient/tests/test_accounts.py index 0eb24a3..6821e5c 100644 --- a/troveclient/tests/test_accounts.py +++ b/troveclient/tests/test_accounts.py @@ -15,11 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools -from troveclient.v1 import accounts from troveclient import base +from troveclient.v1 import accounts """ Unit tests for accounts.py diff --git a/troveclient/tests/test_backups.py b/troveclient/tests/test_backups.py index 912400a..791c6d4 100644 --- a/troveclient/tests/test_backups.py +++ b/troveclient/tests/test_backups.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools import uuid from troveclient.v1 import backups diff --git a/troveclient/tests/test_base.py b/troveclient/tests/test_base.py index 5679cc0..b7732e9 100644 --- a/troveclient/tests/test_base.py +++ b/troveclient/tests/test_base.py @@ -18,12 +18,12 @@ import contextlib import os -import testtools import mock +import testtools from troveclient import base -from troveclient.openstack.common.apiclient import exceptions from troveclient import common +from troveclient.openstack.common.apiclient import exceptions from troveclient import utils """ diff --git a/troveclient/tests/test_common.py b/troveclient/tests/test_common.py index bedf42a..55e8645 100644 --- a/troveclient/tests/test_common.py +++ b/troveclient/tests/test_common.py @@ -15,8 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools from troveclient import common diff --git a/troveclient/tests/test_configurations.py b/troveclient/tests/test_configurations.py index c287143..feb82a1 100644 --- a/troveclient/tests/test_configurations.py +++ b/troveclient/tests/test_configurations.py @@ -15,11 +15,11 @@ # under the License. import json -import testtools import mock +import testtools -from troveclient.v1 import configurations from troveclient import base +from troveclient.v1 import configurations """ Unit tests for configurations.py diff --git a/troveclient/tests/test_datastores.py b/troveclient/tests/test_datastores.py index 01927f3..fe6e39f 100644 --- a/troveclient/tests/test_datastores.py +++ b/troveclient/tests/test_datastores.py @@ -15,11 +15,11 @@ # under the License. -import testtools import mock +import testtools -from troveclient.v1 import datastores from troveclient import base +from troveclient.v1 import datastores """ diff --git a/troveclient/tests/test_instances.py b/troveclient/tests/test_instances.py index 69f61f8..cdd29e4 100644 --- a/troveclient/tests/test_instances.py +++ b/troveclient/tests/test_instances.py @@ -15,11 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools -from troveclient.v1 import instances from troveclient import base +from troveclient.v1 import instances """ Unit tests for instances.py diff --git a/troveclient/tests/test_limits.py b/troveclient/tests/test_limits.py index 7ecd9ab..a4b1271 100644 --- a/troveclient/tests/test_limits.py +++ b/troveclient/tests/test_limits.py @@ -15,15 +15,14 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools + from troveclient.v1 import limits class LimitsTest(testtools.TestCase): - """ - This class tests the calling code for the Limits API - """ + """This class tests the calling code for the Limits API.""" def setUp(self): super(LimitsTest, self).setUp() diff --git a/troveclient/tests/test_management.py b/troveclient/tests/test_management.py index 06acc81..7c0a77b 100644 --- a/troveclient/tests/test_management.py +++ b/troveclient/tests/test_management.py @@ -15,11 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools -from troveclient.v1 import management from troveclient import base +from troveclient.v1 import management """ Unit tests for management.py diff --git a/troveclient/tests/test_secgroups.py b/troveclient/tests/test_secgroups.py index ecb6464..5c658a9 100644 --- a/troveclient/tests/test_secgroups.py +++ b/troveclient/tests/test_secgroups.py @@ -15,8 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools from troveclient.v1 import security_groups diff --git a/troveclient/tests/test_users.py b/troveclient/tests/test_users.py index 0df9a25..ffd5e2e 100644 --- a/troveclient/tests/test_users.py +++ b/troveclient/tests/test_users.py @@ -15,11 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools import mock +import testtools -from troveclient.v1 import users from troveclient import base +from troveclient.v1 import users """ Unit tests for users.py diff --git a/troveclient/utils.py b/troveclient/utils.py index b5e3965..b7cbb02 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -17,12 +17,12 @@ from __future__ import print_function import os +import simplejson as json import sys import uuid -import simplejson as json -import six import prettytable +import six from troveclient.openstack.common.apiclient import exceptions from troveclient.openstack.common import strutils @@ -37,8 +37,9 @@ def arg(*args, **kwargs): def env(*vars, **kwargs): - """ - returns the first environment variable set + """Returns environment variables. + + Returns the first environment variable set if none are non-empty, defaults to '' or keyword arg default """ for v in vars: @@ -63,8 +64,8 @@ def add_arg(f, *args, **kwargs): def unauthenticated(f): - """ - Adds 'unauthenticated' attribute to decorated function. + """Adds 'unauthenticated' attribute to decorated function. + Usage: @unauthenticated def mymethod(f): @@ -75,7 +76,8 @@ def unauthenticated(f): def isunauthenticated(f): - """ + """Decorator to mark authentication-non-required. + Checks to see if the function is marked as not requiring authentication with the @unauthenticated decorator. Returns True if decorator is set to True, False otherwise. @@ -84,8 +86,8 @@ def isunauthenticated(f): def service_type(stype): - """ - Adds 'service_type' attribute to decorated function. + """Adds 'service_type' attribute to decorated function. + Usage: @service_type('database') def mymethod(f): @@ -98,9 +100,7 @@ def service_type(stype): def get_service_type(f): - """ - Retrieves service type from function - """ + """Retrieves service type from function.""" return getattr(f, 'service_type', None) @@ -113,11 +113,12 @@ def translate_keys(collection, convert): def _output_override(objs, print_as): - """ + """Output override flag checking. + If an output override global flag is set, print with override raise BaseException if no printing was overridden. """ - if 'json_output' in globals() and json_output: + if 'json_output' in globals(): if print_as == 'list': new_objs = [] for o in objs: @@ -261,7 +262,8 @@ def safe_issubclass(*args): # http://code.activestate.com/recipes/ # 577257-slugify-make-a-string-usable-in-a-url-or-filename/ def slugify(value): - """ + """Converts a string usable in a url or filename. + Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens. diff --git a/troveclient/v1/accounts.py b/troveclient/v1/accounts.py index 5a5006f..b0ef08f 100644 --- a/troveclient/v1/accounts.py +++ b/troveclient/v1/accounts.py @@ -19,17 +19,13 @@ from troveclient import common class Account(base.Resource): - """ - Account is an opaque instance used to hold account information. - """ + """Account is an opaque instance used to hold account information.""" def __repr__(self): return "<Account: %s>" % self.name class Accounts(base.ManagerWithFind): - """ - Manage :class:`Account` information. - """ + """Manage :class:`Account` information.""" resource_class = Account @@ -40,7 +36,7 @@ class Accounts(base.ManagerWithFind): return self.resource_class(self, body[response_key]) def index(self): - """Get a list of all accounts with non-deleted instances""" + """Get a list of all accounts with non-deleted instances.""" url = "/mgmt/accounts" resp, body = self.api.client.get(url) @@ -50,8 +46,7 @@ class Accounts(base.ManagerWithFind): return base.Resource(self, body) def show(self, account): - """ - Get details of one account. + """Get details of one account. :rtype: :class:`Account`. """ diff --git a/troveclient/v1/backups.py b/troveclient/v1/backups.py index e3a91be..bee134e 100644 --- a/troveclient/v1/backups.py +++ b/troveclient/v1/backups.py @@ -20,23 +20,18 @@ from troveclient import common class Backup(base.Resource): - """ - Backup is a resource used to hold backup information. - """ + """Backup is a resource used to hold backup information.""" def __repr__(self): return "<Backup: %s>" % self.name class Backups(base.ManagerWithFind): - """ - Manage :class:`Backups` information. - """ + """Manage :class:`Backups` information.""" resource_class = Backup def get(self, backup): - """ - Get a specific backup. + """Get a specific backup. :rtype: :class:`Backups` """ @@ -44,17 +39,14 @@ class Backups(base.ManagerWithFind): "backup") def list(self, limit=None, marker=None): - """ - Get a list of all backups. + """Get a list of all backups. :rtype: list of :class:`Backups`. """ return self._paginated("/backups", "backups", limit, marker) def create(self, name, instance, description=None, parent_id=None): - """ - Create a new backup from the given instance. - """ + """Create a new backup from the given instance.""" body = { "backup": { "name": name, @@ -68,8 +60,7 @@ class Backups(base.ManagerWithFind): return self._create("/backups", body, "backup") def delete(self, backup_id): - """ - Delete the specified backup. + """Delete the specified backup. :param backup_id: The backup id to delete """ diff --git a/troveclient/v1/client.py b/troveclient/v1/client.py index becb41b..75972bc 100644 --- a/troveclient/v1/client.py +++ b/troveclient/v1/client.py @@ -28,16 +28,15 @@ from troveclient.v1 import users class Client(object): - """ - Top-level object to access the OpenStack Database API. + """Top-level object to access the OpenStack Database API. Create an instance with your creds:: - >>> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL) + >> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL) Then call methods on its managers:: - >>> client.instances.list() + >> client.instances.list() ... """ @@ -105,8 +104,7 @@ class Client(object): bypass_url=bypass_url) def authenticate(self): - """ - Authenticate against the server. + """Authenticate against the server. Normally this is called automatically when you first access the API, but you can call this method to force authentication right now. diff --git a/troveclient/v1/configurations.py b/troveclient/v1/configurations.py index 61c890e..7874424 100644 --- a/troveclient/v1/configurations.py +++ b/troveclient/v1/configurations.py @@ -20,23 +20,18 @@ from troveclient import common class Configuration(base.Resource): - """ - Configuration is a resource used to hold configuration information. - """ + """Configuration is a resource used to hold configuration information.""" def __repr__(self): return "<Configuration: %s>" % self.name class Configurations(base.ManagerWithFind): - """ - Manage :class:`Configurations` information. - """ + """Manage :class:`Configurations` information.""" resource_class = Configuration def get(self, configuration): - """ - Get a specific configuration. + """Get a specific configuration. :rtype: :class:`Configurations` """ @@ -44,8 +39,7 @@ class Configurations(base.ManagerWithFind): "configuration") def instances(self, configuration, limit=None, marker=None): - """ - Get a list of instances on a configuration. + """Get a list of instances on a configuration. :rtype: :class:`Configurations` """ @@ -54,8 +48,7 @@ class Configurations(base.ManagerWithFind): "instances", limit, marker) def list(self, limit=None, marker=None): - """ - Get a list of all configurations. + """Get a list of all configurations. :rtype: list of :class:`Configurations`. """ @@ -63,9 +56,7 @@ class Configurations(base.ManagerWithFind): def create(self, name, values, description=None, datastore=None, datastore_version=None): - """ - Create a new configuration. - """ + """Create a new configuration.""" body = { "configuration": { "name": name, @@ -84,9 +75,7 @@ class Configurations(base.ManagerWithFind): return self._create("/configurations", body, "configuration") def update(self, configuration_id, values, name=None, description=None): - """ - Update an existing configuration. - """ + """Update an existing configuration.""" body = { "configuration": { "values": json.loads(values) @@ -101,9 +90,7 @@ class Configurations(base.ManagerWithFind): common.check_for_exceptions(resp, body, url) def edit(self, configuration_id, values): - """ - Update an existing configuration. - """ + """Update an existing configuration.""" body = { "configuration": { "values": json.loads(values) @@ -114,8 +101,7 @@ class Configurations(base.ManagerWithFind): common.check_for_exceptions(resp, body, url) def delete(self, configuration_id): - """ - Delete the specified configuration. + """Delete the specified configuration. :param configuration_id: The configuration id to delete """ @@ -125,45 +111,33 @@ class Configurations(base.ManagerWithFind): class ConfigurationParameter(base.Resource): - """ - Configuration Parameter. - """ + """Configuration Parameter.""" def __repr__(self): return "<ConfigurationParameter: %s>" % self.__dict__ class ConfigurationParameters(base.ManagerWithFind): - """ - Manage :class:`ConfigurationParameters` information. - """ + """Manage :class:`ConfigurationParameters` information.""" resource_class = ConfigurationParameter def parameters(self, datastore, version): - """ - Get a list of valid parameters that can be changed. - """ + """Get a list of valid parameters that can be changed.""" return self._list("/datastores/%s/versions/%s/parameters" % (datastore, version), "configuration-parameters") def get_parameter(self, datastore, version, key): - """ - Get a list of valid parameters that can be changed. - """ + """Get a list of valid parameters that can be changed.""" return self._get("/datastores/%s/versions/%s/parameters/%s" % (datastore, version, key)) def parameters_by_version(self, version): - """ - Get a list of valid parameters that can be changed. - """ + """Get a list of valid parameters that can be changed.""" return self._list("/datastores/versions/%s/parameters" % version, "configuration-parameters") def get_parameter_by_version(self, version, key): - """ - Get a list of valid parameters that can be changed. - """ + """Get a list of valid parameters that can be changed.""" return self._get("/datastores/versions/%s/parameters/%s" % (version, key)) diff --git a/troveclient/v1/databases.py b/troveclient/v1/databases.py index 03ce315..1e95796 100644 --- a/troveclient/v1/databases.py +++ b/troveclient/v1/databases.py @@ -19,39 +19,34 @@ from troveclient import common class Database(base.Resource): - """ - According to Wikipedia, "A database is a system intended to organize, - store, and retrieve - large amounts of data easily." + """Wikipedia definition for database. + + "A database is a system intended to organize, store, and retrieve large + amounts of data easily." """ def __repr__(self): return "<Database: %s>" % self.name class Databases(base.ManagerWithFind): - """ - Manage :class:`Databases` resources. - """ + """Manage :class:`Databases` resources.""" resource_class = Database def create(self, instance_id, databases): - """ - Create new databases within the specified instance - """ + """Create new databases within the specified instance.""" body = {"databases": databases} url = "/instances/%s/databases" % instance_id resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) def delete(self, instance_id, dbname): - """Delete an existing database in the specified instance""" + """Delete an existing database in the specified instance.""" url = "/instances/%s/databases/%s" % (instance_id, dbname) resp, body = self.api.client.delete(url) common.check_for_exceptions(resp, body, url) def list(self, instance, limit=None, marker=None): - """ - Get a list of all Databases from the instance. + """Get a list of all Databases from the instance. :rtype: list of :class:`Database`. """ diff --git a/troveclient/v1/datastores.py b/troveclient/v1/datastores.py index 2208fe1..bdce1fe 100644 --- a/troveclient/v1/datastores.py +++ b/troveclient/v1/datastores.py @@ -30,25 +30,21 @@ class DatastoreVersion(base.Resource): class Datastores(base.ManagerWithFind): - """ - Manage :class:`Datastore` resources. - """ + """Manage :class:`Datastore` resources.""" resource_class = Datastore def __repr__(self): return "<Datastore Manager at %s>" % id(self) def list(self, limit=None, marker=None): - """ - Get a list of all datastores. + """Get a list of all datastores. :rtype: list of :class:`Datastore`. """ return self._paginated("/datastores", "datastores", limit, marker) def get(self, datastore): - """ - Get a specific datastore. + """Get a specific datastore. :rtype: :class:`Datastore` """ @@ -57,17 +53,14 @@ class Datastores(base.ManagerWithFind): class DatastoreVersions(base.ManagerWithFind): - """ - Manage :class:`DatastoreVersion` resources. - """ + """Manage :class:`DatastoreVersion` resources.""" resource_class = DatastoreVersion def __repr__(self): return "<DatastoreVersions Manager at %s>" % id(self) def list(self, datastore, limit=None, marker=None): - """ - Get a list of all datastore versions. + """Get a list of all datastore versions. :rtype: list of :class:`DatastoreVersion`. """ @@ -75,8 +68,7 @@ class DatastoreVersions(base.ManagerWithFind): "versions", limit, marker) def get(self, datastore, datastore_version): - """ - Get a specific datastore version. + """Get a specific datastore version. :rtype: :class:`DatastoreVersion` """ @@ -85,8 +77,8 @@ class DatastoreVersions(base.ManagerWithFind): "version") def get_by_uuid(self, datastore_version): - """ - Get a specific datastore version. + """Get a specific datastore version. + :rtype: :class:`DatastoreVersion` """ return self._get("/datastores/versions/%s" % diff --git a/troveclient/v1/diagnostics.py b/troveclient/v1/diagnostics.py index 81aa58a..dffb153 100644 --- a/troveclient/v1/diagnostics.py +++ b/troveclient/v1/diagnostics.py @@ -18,23 +18,17 @@ from troveclient import base class Diagnostics(base.Resource): - """ - Account is an opaque instance used to hold account information. - """ + """Account is an opaque instance used to hold account information.""" def __repr__(self): return "<Diagnostics: %s>" % self.version class DiagnosticsInterrogator(base.ManagerWithFind): - """ - Manager class for Interrogator resource - """ + """Manager class for Interrogator resource.""" resource_class = Diagnostics def get(self, instance): - """ - Get the diagnostics of the guest on the instance. - """ + """Get the diagnostics of the guest on the instance.""" return self._get("/mgmt/instances/%s/diagnostics" % base.getid(instance), "diagnostics") @@ -50,15 +44,11 @@ class HwInfo(base.Resource): class HwInfoInterrogator(base.ManagerWithFind): - """ - Manager class for HwInfo - """ + """Manager class for HwInfo.""" resource_class = HwInfo def get(self, instance): - """ - Get the hardware information of the instance. - """ + """Get the hardware information of the instance.""" return self._get("/mgmt/instances/%s/hwinfo" % base.getid(instance)) # Appease the abc gods diff --git a/troveclient/v1/flavors.py b/troveclient/v1/flavors.py index 0a65894..d61fd04 100644 --- a/troveclient/v1/flavors.py +++ b/troveclient/v1/flavors.py @@ -18,31 +18,25 @@ from troveclient import base class Flavor(base.Resource): - """ - A Flavor is an Instance type, specifying among other things, RAM size. - """ + """A Flavor is an Instance type, specifying other things, like RAM size.""" def __repr__(self): return "<Flavor: %s>" % self.name class Flavors(base.ManagerWithFind): - """ - Manage :class:`Flavor` resources. - """ + """Manage :class:`Flavor` resources.""" resource_class = Flavor def list(self): - """ - Get a list of all flavors. + """Get a list of all flavors. :rtype: list of :class:`Flavor`. """ return self._list("/flavors", "flavors") def get(self, flavor): - """ - Get a specific flavor. + """Get a specific flavor. :rtype: :class:`Flavor` """ diff --git a/troveclient/v1/hosts.py b/troveclient/v1/hosts.py index 67fbc71..de46f3c 100644 --- a/troveclient/v1/hosts.py +++ b/troveclient/v1/hosts.py @@ -19,17 +19,13 @@ from troveclient import common class Host(base.Resource): - """ - A Hosts is an opaque instance used to store Host instances. - """ + """A Hosts is an opaque instance used to store Host instances.""" def __repr__(self): return "<Host: %s>" % self.name class Hosts(base.ManagerWithFind): - """ - Manage :class:`Host` resources. - """ + """Manage :class:`Host` resources.""" resource_class = Host def _list(self, url, response_key): @@ -39,31 +35,25 @@ class Hosts(base.ManagerWithFind): return [self.resource_class(self, res) for res in body[response_key]] def _action(self, host_id, body): - """ - Perform a host "action" -- update - """ + """Perform a host "action" -- update.""" url = "/mgmt/hosts/%s/instances/action" % host_id resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) def update_all(self, host_id): - """ - Update all instances on a host. - """ + """Update all instances on a host.""" body = {'update': ''} self._action(host_id, body) def index(self): - """ - Get a list of all hosts. + """Get a list of all hosts. :rtype: list of :class:`Hosts`. """ return self._list("/mgmt/hosts", "hosts") def get(self, host): - """ - Get a specific host. + """Get a specific host. :rtype: :class:`host` """ diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py index ed44464..2bf922e 100644 --- a/troveclient/v1/instances.py +++ b/troveclient/v1/instances.py @@ -23,9 +23,7 @@ REBOOT_HARD = 'HARD' class Instance(base.Resource): - """ - An Instance is an opaque instance used to store Database instances. - """ + """An Instance is an opaque instance used to store Database instances.""" def __repr__(self): return "<Instance: %s>" % self.name @@ -33,30 +31,22 @@ class Instance(base.Resource): return self.manager.databases.list(self) def delete(self): - """ - Delete the instance. - """ + """Delete the instance.""" self.manager.delete(self) def restart(self): - """ - Restart the database instance - """ + """Restart the database instance.""" self.manager.restart(self.id) class Instances(base.ManagerWithFind): - """ - Manage :class:`Instance` resources. - """ + """Manage :class:`Instance` resources.""" resource_class = Instance def create(self, name, flavor_id, volume=None, databases=None, users=None, restorePoint=None, availability_zone=None, datastore=None, datastore_version=None, nics=None, configuration=None): - """ - Create (boot) a new instance. - """ + """Create (boot) a new instance.""" body = {"instance": { "name": name, "flavorRef": flavor_id @@ -97,16 +87,14 @@ class Instances(base.ManagerWithFind): common.check_for_exceptions(resp, body, url) def list(self, limit=None, marker=None): - """ - Get a list of all instances. + """Get a list of all instances. :rtype: list of :class:`Instance`. """ return self._paginated("/instances", "instances", limit, marker) def get(self, instance): - """ - Get a specific instances. + """Get a specific instances. :rtype: :class:`Instance` """ @@ -114,8 +102,7 @@ class Instances(base.ManagerWithFind): "instance") def backups(self, instance, limit=None, marker=None): - """ - Get the list of backups for a specific instance. + """Get the list of backups for a specific instance. :rtype: list of :class:`Backups`. """ @@ -123,8 +110,7 @@ class Instances(base.ManagerWithFind): return self._paginated(url, "backups", limit, marker) def delete(self, instance): - """ - Delete the specified instance. + """Delete the specified instance. :param instance_id: The instance id to delete """ @@ -133,9 +119,7 @@ class Instances(base.ManagerWithFind): common.check_for_exceptions(resp, body, url) def _action(self, instance_id, body): - """ - Perform a server "action" -- reboot/rebuild/resize/etc. - """ + """Perform a server "action" -- reboot/rebuild/resize/etc.""" url = "/instances/%s/action" % instance_id resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) @@ -144,22 +128,17 @@ class Instances(base.ManagerWithFind): return body def resize_volume(self, instance_id, volume_size): - """ - Resize the volume on an existing instances - """ + """Resize the volume on an existing instances.""" body = {"resize": {"volume": {"size": volume_size}}} self._action(instance_id, body) def resize_instance(self, instance_id, flavor_id): - """ - Resize the volume on an existing instances - """ + """Resize the volume on an existing instances.""" body = {"resize": {"flavorRef": flavor_id}} self._action(instance_id, body) def restart(self, instance_id): - """ - Restart the database instance. + """Restart the database instance. :param instance_id: The :class:`Instance` (or its ID) to share onto. """ @@ -167,8 +146,7 @@ class Instances(base.ManagerWithFind): self._action(instance_id, body) def configuration(self, instance): - """ - Get a configuration on instances. + """Get a configuration on instances. :rtype: :class:`Instance` """ diff --git a/troveclient/v1/limits.py b/troveclient/v1/limits.py index ca446b2..2e4f5d7 100644 --- a/troveclient/v1/limits.py +++ b/troveclient/v1/limits.py @@ -26,9 +26,7 @@ class Limit(base.Resource): class Limits(base.ManagerWithFind): - """ - Manages :class `Limit` resources - """ + """Manages :class `Limit` resources.""" resource_class = Limit def __repr__(self): @@ -46,7 +44,5 @@ class Limits(base.ManagerWithFind): return [self.resource_class(self, res) for res in body[response_key]] def list(self): - """ - Retrieve the limits - """ + """Retrieve the limits.""" return self._list("/limits", "limits") diff --git a/troveclient/v1/management.py b/troveclient/v1/management.py index 28ca225..782b3c1 100644 --- a/troveclient/v1/management.py +++ b/troveclient/v1/management.py @@ -16,8 +16,8 @@ from troveclient import base from troveclient import common -from troveclient.v1 import instances from troveclient.v1 import flavors +from troveclient.v1 import instances class RootHistory(base.Resource): @@ -27,9 +27,7 @@ class RootHistory(base.Resource): class Management(base.ManagerWithFind): - """ - Manage :class:`Instances` resources. - """ + """Manage :class:`Instances` resources.""" resource_class = instances.Instance # Appease the abc gods @@ -37,8 +35,7 @@ class Management(base.ManagerWithFind): pass def show(self, instance): - """ - Get details of one instance. + """Get details of one instance. :rtype: :class:`Instance`. """ @@ -47,8 +44,8 @@ class Management(base.ManagerWithFind): 'instance') def index(self, deleted=None, limit=None, marker=None): - """ - Show an overview of all local instances. + """Show an overview of all local instances. + Optionally, filter by deleted status. :rtype: list of :class:`Instance`. @@ -64,10 +61,7 @@ class Management(base.ManagerWithFind): return self._paginated(url, "instances", limit, marker) def root_enabled_history(self, instance): - """ - Get root access history of one instance. - - """ + """Get root access history of one instance.""" url = "/mgmt/instances/%s/root" % base.getid(instance) resp, body = self.api.client.get(url) if not body: @@ -75,9 +69,7 @@ class Management(base.ManagerWithFind): return RootHistory(self, body['root_history']) def _action(self, instance_id, body): - """ - Perform a server "action" -- reboot/rebuild/resize/etc. - """ + """Perform a server "action" -- reboot/rebuild/resize/etc.""" url = "/mgmt/instances/%s/action" % instance_id resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) @@ -87,8 +79,7 @@ class Management(base.ManagerWithFind): self._action(instance_id, body) def reboot(self, instance_id): - """ - Reboot the underlying OS. + """Reboot the underlying OS. :param instance_id: The :class:`Instance` (or its ID) to share onto. """ @@ -96,8 +87,7 @@ class Management(base.ManagerWithFind): self._action(instance_id, body) def migrate(self, instance_id, host=None): - """ - Migrate the instance. + """Migrate the instance. :param instance_id: The :class:`Instance` (or its ID) to share onto. """ @@ -108,24 +98,18 @@ class Management(base.ManagerWithFind): self._action(instance_id, body) def update(self, instance_id): - """ - Update the guest agent via apt-get. - """ + """Update the guest agent via apt-get.""" body = {'update': {}} self._action(instance_id, body) def reset_task_status(self, instance_id): - """ - Set the task status to NONE. - """ + """Set the task status to NONE.""" body = {'reset-task-status': {}} self._action(instance_id, body) class MgmtFlavors(base.ManagerWithFind): - """ - Manage :class:`Flavor` resources. - """ + """Manage :class:`Flavor` resources.""" resource_class = flavors.Flavor def __repr__(self): @@ -138,9 +122,7 @@ class MgmtFlavors(base.ManagerWithFind): def create(self, name, ram, disk, vcpus, flavorid="auto", ephemeral=None, swap=None, rxtx_factor=None, service_type=None): - """ - Create a new flavor. - """ + """Create a new flavor.""" body = {"flavor": { "flavor_id": flavorid, "name": name, diff --git a/troveclient/v1/quota.py b/troveclient/v1/quota.py index f68369e..e461c52 100644 --- a/troveclient/v1/quota.py +++ b/troveclient/v1/quota.py @@ -20,14 +20,12 @@ from troveclient import common class Quotas(base.ManagerWithFind): - """ - Manage :class:`Quota` information. - """ + """Manage :class:`Quota` information.""" resource_class = base.Resource def show(self, tenant_id): - """Get a list of all quotas for a tenant id""" + """Get a list of all quotas for a tenant id.""" url = "/mgmt/quotas/%s" % tenant_id resp, body = self.api.client.get(url) @@ -39,9 +37,7 @@ class Quotas(base.ManagerWithFind): return body['quotas'] def update(self, id, quotas): - """ - Set limits for quotas - """ + """Set limits for quotas.""" url = "/mgmt/quotas/%s" % id body = {"quotas": quotas} resp, body = self.api.client.put(url, body=body) diff --git a/troveclient/v1/root.py b/troveclient/v1/root.py index 51391ab..95f2088 100644 --- a/troveclient/v1/root.py +++ b/troveclient/v1/root.py @@ -15,21 +15,20 @@ # under the License. from troveclient import base -from troveclient.v1 import users from troveclient import common +from troveclient.v1 import users class Root(base.ManagerWithFind): - """ - Manager class for Root resource - """ + """Manager class for Root resource.""" resource_class = users.User url = "/instances/%s/root" def create(self, instance_id): - """ + """Implements root-enable API. + Enable the root user and return the root password for the - specified db instance + specified db instance. """ resp, body = self.api.client.post(self.url % instance_id) common.check_for_exceptions(resp, body, self.url) diff --git a/troveclient/v1/security_groups.py b/troveclient/v1/security_groups.py index 86be637..9f79800 100644 --- a/troveclient/v1/security_groups.py +++ b/troveclient/v1/security_groups.py @@ -20,23 +20,18 @@ from troveclient import common class SecurityGroup(base.Resource): - """ - Security Group is a resource used to hold security group information. - """ + """Security Group is a resource used to hold security group information.""" def __repr__(self): return "<SecurityGroup: %s>" % self.name class SecurityGroups(base.ManagerWithFind): - """ - Manage :class:`SecurityGroup` resources. - """ + """Manage :class:`SecurityGroup` resources.""" resource_class = SecurityGroup def list(self, limit=None, marker=None): - """ - Get a list of all security groups. + """Get a list of all security groups. :rtype: list of :class:`SecurityGroup`. """ @@ -44,8 +39,7 @@ class SecurityGroups(base.ManagerWithFind): limit, marker) def get(self, security_group): - """ - Get a specific security group. + """Get a specific security group. :rtype: :class:`SecurityGroup` """ @@ -54,10 +48,7 @@ class SecurityGroups(base.ManagerWithFind): class SecurityGroupRule(base.Resource): - """ - Security Group Rule is a resource used to hold security group - rule related information. - """ + """This resource is used to hold security group rule information.""" def __repr__(self): return ("<SecurityGroupRule: " @@ -69,15 +60,11 @@ class SecurityGroupRule(base.Resource): class SecurityGroupRules(base.ManagerWithFind): - """ - Manage :class:`SecurityGroupRules` resources. - """ + """Manage :class:`SecurityGroupRules` resources.""" resource_class = SecurityGroupRule def create(self, group_id, cidr): - """ - Create a new security group rule. - """ + """Create a new security group rule.""" body = {"security_group_rule": { "group_id": group_id, "cidr": cidr @@ -86,8 +73,7 @@ class SecurityGroupRules(base.ManagerWithFind): "security_group_rule", return_raw=True) def delete(self, security_group_rule): - """ - Delete the specified security group rule. + """Delete the specified security group rule. :param security_group_rule: The security group rule to delete """ diff --git a/troveclient/v1/storage.py b/troveclient/v1/storage.py index b996814..05bef70 100644 --- a/troveclient/v1/storage.py +++ b/troveclient/v1/storage.py @@ -18,17 +18,13 @@ from troveclient import base class Device(base.Resource): - """ - Storage is an opaque instance used to hold storage information. - """ + """Storage is an opaque instance used to hold storage information.""" def __repr__(self): return "<Device: %s>" % self.name class StorageInfo(base.ManagerWithFind): - """ - Manage :class:`Storage` resources. - """ + """Manage :class:`Storage` resources.""" resource_class = Device def _list(self, url, response_key): @@ -38,8 +34,7 @@ class StorageInfo(base.ManagerWithFind): return [self.resource_class(self, res) for res in body[response_key]] def index(self): - """ - Get a list of all storages. + """Get a list of all storages. :rtype: list of :class:`Storages`. """ diff --git a/troveclient/v1/users.py b/troveclient/v1/users.py index 423fee8..ee0d4fc 100644 --- a/troveclient/v1/users.py +++ b/troveclient/v1/users.py @@ -15,43 +15,36 @@ # under the License. from troveclient import base -from troveclient.v1 import databases from troveclient import common +from troveclient.v1 import databases class User(base.Resource): - """ - A database user - """ + """A database user.""" def __repr__(self): return "<User: %s>" % self.name class Users(base.ManagerWithFind): - """ - Manage :class:`Users` resources. - """ + """Manage :class:`Users` resources.""" resource_class = User def create(self, instance_id, users): - """ - Create users with permissions to the specified databases - """ + """Create users with permissions to the specified databases.""" body = {"users": users} url = "/instances/%s/users" % instance_id resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) def delete(self, instance_id, username, hostname=None): - """Delete an existing user in the specified instance""" + """Delete an existing user in the specified instance.""" user = common.quote_user_host(username, hostname) url = "/instances/%s/users/%s" % (instance_id, user) resp, body = self.api.client.delete(url) common.check_for_exceptions(resp, body, url) def list(self, instance, limit=None, marker=None): - """ - Get a list of all Users from the instance's Database. + """Get a list of all Users from the instance's Database. :rtype: list of :class:`User`. """ @@ -59,8 +52,7 @@ class Users(base.ManagerWithFind): return self._paginated(url, "users", limit, marker) def get(self, instance_id, username, hostname=None): - """ - Get a single User from the instance's Database. + """Get a single User from the instance's Database. :rtype: :class:`User`. """ @@ -70,8 +62,7 @@ class Users(base.ManagerWithFind): def update_attributes(self, instance, username, newuserattr=None, hostname=None): - """ - Update attributes of a single User in an instance. + """Update attributes of a single User in an instance. :rtype: :class:`User`. """ @@ -87,7 +78,7 @@ class Users(base.ManagerWithFind): common.check_for_exceptions(resp, body, url) def list_access(self, instance, username, hostname=None): - """Show all databases the given user has access to. """ + """Show all databases the given user has access to.""" instance_id = base.getid(instance) user = common.quote_user_host(username, hostname) url = "/instances/%(instance_id)s/users/%(user)s/databases" |