diff --git a/reddwarfclient/auth.py b/reddwarfclient/auth.py index 76ef1767..a0f6e247 100644 --- a/reddwarfclient/auth.py +++ b/reddwarfclient/auth.py @@ -42,7 +42,7 @@ class Authenticator(object): """ - URL_REQUIRED=True + URL_REQUIRED = True def __init__(self, client, type, url, username, password, tenant, region=None, service_type=None, service_name=None, diff --git a/reddwarfclient/cli.py b/reddwarfclient/cli.py index ace13c14..c8613ac3 100644 --- a/reddwarfclient/cli.py +++ b/reddwarfclient/cli.py @@ -209,12 +209,13 @@ COMMANDS = {'auth': common.Auth, 'version': VersionCommands, } + def main(): # Parse arguments - load_file=True + load_file = True for index, arg in enumerate(sys.argv): if (arg == "auth" and len(sys.argv) > (index + 1) - and sys.argv[index + 1]=="login"): + and sys.argv[index + 1] == "login"): load_file = False oparser = common.CliOptions.create_optparser(load_file) @@ -226,7 +227,7 @@ def main(): common.print_commands(COMMANDS) if options.verbose: - os.environ['RDC_PP'] = "True" + os.environ['RDC_PP'] = "True" os.environ['REDDWARFCLIENT_DEBUG'] = "True" # Pop the command and check if it's in the known commands diff --git a/reddwarfclient/client.py b/reddwarfclient/client.py index 44757ad7..2b2dcbdf 100644 --- a/reddwarfclient/client.py +++ b/reddwarfclient/client.py @@ -194,9 +194,9 @@ class ReddwarfHTTPClient(httplib2.Http): raise exceptions.from_response(resp, body) def morph_request(self, kwargs): - kwargs['headers']['Accept'] = 'application/json' - kwargs['headers']['Content-Type'] = 'application/json' - if 'body' in kwargs: + kwargs['headers']['Accept'] = 'application/json' + kwargs['headers']['Content-Type'] = 'application/json' + if 'body' in kwargs: kwargs['body'] = json.dumps(kwargs['body']) def morph_response_body(self, body_string): @@ -274,7 +274,6 @@ class ReddwarfHTTPClient(httplib2.Http): self.service_url = service_url - class Dbaas(object): """ Top-level object to access the Rackspace Database as a Service API. diff --git a/reddwarfclient/common.py b/reddwarfclient/common.py index 4491150d..9139d2ab 100644 --- a/reddwarfclient/common.py +++ b/reddwarfclient/common.py @@ -75,20 +75,20 @@ class CliOptions(object): APITOKEN = os.path.expanduser("~/.apitoken") DEFAULT_VALUES = { - 'username':None, - 'apikey':None, - 'tenant_id':None, - 'auth_url':None, - 'auth_type':'keystone', - 'service_type':'reddwarf', - 'service_name':'Reddwarf', - 'region':'RegionOne', - 'service_url':None, - 'insecure':False, - 'verbose':False, - 'debug':False, - 'token':None, - 'xml':None, + 'username': None, + 'apikey': None, + 'tenant_id': None, + 'auth_url': None, + 'auth_type': 'keystone', + 'service_type': 'reddwarf', + 'service_name': 'Reddwarf', + 'region': 'RegionOne', + 'service_url': None, + 'insecure': False, + 'verbose': False, + 'debug': False, + 'token': None, + 'xml': None, } def __init__(self, **kwargs): @@ -111,7 +111,6 @@ class CliOptions(object): print("ERROR: Token file found at %s was corrupt." % cls.APITOKEN) return cls.default() - @classmethod def save_from_instance_fields(cls, instance): apitoken = cls.default() @@ -121,7 +120,6 @@ class CliOptions(object): with open(cls.APITOKEN, 'wb') as token: pickle.dump(apitoken, token, protocol=2) - @classmethod def create_optparser(cls, load_file): oparser = optparse.OptionParser( @@ -131,6 +129,7 @@ class CliOptions(object): file = cls.load_from_file() else: file = cls.default() + def add_option(*args, **kwargs): if len(args) == 1: name = args[0] @@ -165,7 +164,6 @@ class CliOptions(object): add_option("token", help="Token from a prior login.") add_option("xml", action="store_true", help="Changes format to XML.") - oparser.add_option("--secure", action="store_false", dest="insecure", help="Run in insecure mode for https endpoints.") oparser.add_option("--json", action="store_false", dest="xml", @@ -256,6 +254,7 @@ class CommandsBase(object): if self.verbose: self._safe_exec(func, *args, **kwargs) return # Skip this, since the verbose stuff will show up anyway. + def wrapped_func(): result = func(*args, **kwargs) if result: diff --git a/reddwarfclient/diagnostics.py b/reddwarfclient/diagnostics.py index 64904b71..06da06c0 100644 --- a/reddwarfclient/diagnostics.py +++ b/reddwarfclient/diagnostics.py @@ -35,8 +35,8 @@ class DiagnosticsInterrogator(base.ManagerWithFind): """ Get the diagnostics of the guest on the instance. """ - return self._get("/mgmt/instances/%s/diagnostics" % base.getid(instance), - "diagnostics") + return self._get("/mgmt/instances/%s/diagnostics" % + base.getid(instance), "diagnostics") class HwInfo(base.Resource): diff --git a/reddwarfclient/exceptions.py b/reddwarfclient/exceptions.py index eb305a38..88c3f7ee 100644 --- a/reddwarfclient/exceptions.py +++ b/reddwarfclient/exceptions.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. + class UnsupportedVersion(Exception): """Indicates that the user is trying to use an unsupported version of the API""" @@ -55,6 +56,7 @@ class ResponseFormatError(Exception): """Could not parse the response format.""" pass + class AmbiguousEndpoints(Exception): """Found more than one matching endpoint in Service Catalog.""" def __init__(self, endpoints=None): diff --git a/reddwarfclient/instances.py b/reddwarfclient/instances.py index 3e095f4a..4d633c32 100644 --- a/reddwarfclient/instances.py +++ b/reddwarfclient/instances.py @@ -155,9 +155,10 @@ class Instances(base.ManagerWithFind): """ body = {'reset-password': {}} return self._action(instance_id, body) - + Instances.resize_flavor = Instances.resize_instance + class InstanceStatus(object): ACTIVE = "ACTIVE" diff --git a/reddwarfclient/xml.py b/reddwarfclient/xml.py index d0b7f9b4..ee064099 100644 --- a/reddwarfclient/xml.py +++ b/reddwarfclient/xml.py @@ -6,15 +6,15 @@ from reddwarfclient import exceptions from reddwarfclient.client import ReddwarfHTTPClient -XML_NS = { None: "http://docs.openstack.org/database/api/v1.0" } +XML_NS = {None: "http://docs.openstack.org/database/api/v1.0"} # This dictionary contains XML paths of things that should become list items. LISTIFY = { - "accounts":[[]], - "databases":[[]], + "accounts": [[]], + "databases": [[]], "flavors": [[]], "instances": [[]], - "links" : [["flavor", "instance", "instances"], + "links": [["flavor", "instance", "instances"], ["instance", "instances"]], "hosts": [[]], "devices": [[]], @@ -24,6 +24,7 @@ LISTIFY = { REQUEST_AS_LIST = set(['databases', 'users']) + def element_ancestors_match_list(element, list): """ For element root at <foo><blah><root></blah></foo> matches against @@ -55,9 +56,10 @@ def element_to_json(name, element): else: return element_to_dict(element) + def root_element_to_json(name, element): """Returns a tuple of the root JSON value, plus the links if found.""" - if name == "rootEnabled": # Why oh why were we inconsistent here? :'( + if name == "rootEnabled": # Why oh why were we inconsistent here? :'( return bool(element.text), None elif element_must_be_list(element, name): return element_to_list(element, True) @@ -203,7 +205,7 @@ class ReddwarfXmlClient(ReddwarfHTTPClient): raise exceptions.ResponseFormatError() root_name = normalize_tag(root_element) root_value, links = root_element_to_json(root_name, root_element) - result = { root_name:root_value } + result = {root_name: root_value} if links: result['links'] = links return result diff --git a/tox.ini b/tox.ini index fa600d3c..976d57c0 100644 --- a/tox.ini +++ b/tox.ini @@ -11,3 +11,6 @@ deps = commands = sphinx-build -b doctest {toxinidir}/docs/source {envtmpdir}/html sphinx-build -b html {toxinidir}/docs/source {envtmpdir}/html + +[testenv:pep8] +commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc reddwarfclient setup.py \ No newline at end of file