Make source PEP8 compliant
authorGiorgos Verigakis <verigak@gmail.com>
Thu, 17 May 2012 12:36:48 +0000 (15:36 +0300)
committerGiorgos Verigakis <verigak@gmail.com>
Thu, 17 May 2012 12:36:48 +0000 (15:36 +0300)
kamaki/cli.py
kamaki/clients/__init__.py
kamaki/clients/astakos.py
kamaki/clients/compute.py
kamaki/clients/cyclades.py
kamaki/clients/image.py
kamaki/clients/pithos.py
kamaki/clients/storage.py
kamaki/config.py
kamaki/utils.py

index a4be116..10e33c9 100755 (executable)
@@ -110,20 +110,20 @@ class ProgressBar(IncrementalBar):
 
 def command(api=None, group=None, name=None, syntax=None):
     """Class decorator that registers a class as a CLI command."""
-    
+
     def decorator(cls):
         grp, sep, cmd = cls.__name__.partition('_')
         if not sep:
             grp, cmd = None, cls.__name__
-        
+
         cls.api = api
         cls.group = group or grp
         cls.name = name or cmd
-        
+
         short_description, sep, long_description = cls.__doc__.partition('\n')
         cls.description = short_description
         cls.long_description = long_description or short_description
-        
+
         cls.syntax = syntax
         if cls.syntax is None:
             # Generate a syntax string based on main's arguments
@@ -135,7 +135,7 @@ def command(api=None, group=None, name=None, syntax=None):
             cls.syntax = ' '.join(x for x in [required, optional] if x)
             if spec.varargs:
                 cls.syntax += ' <%s ...>' % spec.varargs
-        
+
         if cls.group not in _commands:
             _commands[cls.group] = OrderedDict()
         _commands[cls.group][cls.name] = cls
@@ -146,7 +146,7 @@ def command(api=None, group=None, name=None, syntax=None):
 @command(api='config')
 class config_list(object):
     """List configuration options"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-a', dest='all', action='store_true',
                           default=False, help='include default values')
@@ -162,7 +162,7 @@ class config_list(object):
 @command(api='config')
 class config_get(object):
     """Show a configuration option"""
-    
+
     def main(self, option):
         section, sep, key = option.rpartition('.')
         section = section or 'global'
@@ -174,7 +174,7 @@ class config_get(object):
 @command(api='config')
 class config_set(object):
     """Set a configuration option"""
-    
+
     def main(self, option, value):
         section, sep, key = option.rpartition('.')
         section = section or 'global'
@@ -185,7 +185,7 @@ class config_set(object):
 @command(api='config')
 class config_delete(object):
     """Delete a configuration option (and use the default value)"""
-    
+
     def main(self, option):
         section, sep, key = option.rpartition('.')
         section = section or 'global'
@@ -196,7 +196,7 @@ class config_delete(object):
 @command(api='compute')
 class server_list(object):
     """List servers"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-l', dest='detail', action='store_true',
                 default=False, help='show detailed output')
@@ -209,7 +209,7 @@ class server_list(object):
 @command(api='compute')
 class server_info(object):
     """Get server details"""
-    
+
     def main(self, server_id):
         server = self.client.get_server_details(int(server_id))
         print_dict(server)
@@ -218,7 +218,7 @@ class server_info(object):
 @command(api='compute')
 class server_create(object):
     """Create a server"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('--personality', dest='personalities',
                           action='append', default=[],
@@ -230,16 +230,16 @@ class server_create(object):
         for personality in self.args.personalities:
             p = personality.split(',')
             p.extend([None] * (5 - len(p)))     # Fill missing fields with None
-            
+
             path = p[0]
-            
+
             if not path:
                 print("Invalid personality argument '%s'" % p)
                 return 1
             if not exists(path):
                 print("File %s does not exist" % path)
                 return 1
-            
+
             with open(path) as f:
                 contents = b64encode(f.read())
 
@@ -260,7 +260,7 @@ class server_create(object):
 @command(api='compute')
 class server_rename(object):
     """Update a server's name"""
-    
+
     def main(self, server_id, new_name):
         self.client.update_server_name(int(server_id), new_name)
 
@@ -268,7 +268,7 @@ class server_rename(object):
 @command(api='compute')
 class server_delete(object):
     """Delete a server"""
-    
+
     def main(self, server_id):
         self.client.delete_server(int(server_id))
 
@@ -276,7 +276,7 @@ class server_delete(object):
 @command(api='compute')
 class server_reboot(object):
     """Reboot a server"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-f', dest='hard', action='store_true',
                 default=False, help='perform a hard reboot')
@@ -288,7 +288,7 @@ class server_reboot(object):
 @command(api='cyclades')
 class server_start(object):
     """Start a server"""
-    
+
     def main(self, server_id):
         self.client.start_server(int(server_id))
 
@@ -296,7 +296,7 @@ class server_start(object):
 @command(api='cyclades')
 class server_shutdown(object):
     """Shutdown a server"""
-    
+
     def main(self, server_id):
         self.client.shutdown_server(int(server_id))
 
@@ -304,7 +304,7 @@ class server_shutdown(object):
 @command(api='cyclades')
 class server_console(object):
     """Get a VNC console"""
-    
+
     def main(self, server_id):
         reply = self.client.get_server_console(int(server_id))
         print_dict(reply)
@@ -313,7 +313,7 @@ class server_console(object):
 @command(api='cyclades')
 class server_firewall(object):
     """Set the server's firewall profile"""
-    
+
     def main(self, server_id, profile):
         self.client.set_firewall_profile(int(server_id), profile)
 
@@ -321,7 +321,7 @@ class server_firewall(object):
 @command(api='cyclades')
 class server_addr(object):
     """List a server's addresses"""
-    
+
     def main(self, server_id, network=None):
         reply = self.client.list_server_addresses(int(server_id), network)
         margin = max(len(x['name']) for x in reply)
@@ -331,7 +331,7 @@ class server_addr(object):
 @command(api='compute')
 class server_meta(object):
     """Get a server's metadata"""
-    
+
     def main(self, server_id, key=None):
         reply = self.client.get_server_metadata(int(server_id), key)
         print_dict(reply)
@@ -340,7 +340,7 @@ class server_meta(object):
 @command(api='compute')
 class server_addmeta(object):
     """Add server metadata"""
-    
+
     def main(self, server_id, key, val):
         reply = self.client.create_server_metadata(int(server_id), key, val)
         print_dict(reply)
@@ -349,7 +349,7 @@ class server_addmeta(object):
 @command(api='compute')
 class server_setmeta(object):
     """Update server's metadata"""
-    
+
     def main(self, server_id, key, val):
         metadata = {key: val}
         reply = self.client.update_server_metadata(int(server_id), **metadata)
@@ -359,7 +359,7 @@ class server_setmeta(object):
 @command(api='compute')
 class server_delmeta(object):
     """Delete server metadata"""
-    
+
     def main(self, server_id, key):
         self.client.delete_server_metadata(int(server_id), key)
 
@@ -367,7 +367,7 @@ class server_delmeta(object):
 @command(api='cyclades')
 class server_stats(object):
     """Get server statistics"""
-    
+
     def main(self, server_id):
         reply = self.client.get_server_stats(int(server_id))
         print_dict(reply, exclude=('serverRef',))
@@ -376,7 +376,7 @@ class server_stats(object):
 @command(api='compute')
 class flavor_list(object):
     """List flavors"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-l', dest='detail', action='store_true',
                 default=False, help='show detailed output')
@@ -389,7 +389,7 @@ class flavor_list(object):
 @command(api='compute')
 class flavor_info(object):
     """Get flavor details"""
-    
+
     def main(self, flavor_id):
         flavor = self.client.get_flavor_details(int(flavor_id))
         print_dict(flavor)
@@ -398,7 +398,7 @@ class flavor_info(object):
 @command(api='compute')
 class image_list(object):
     """List images"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-l', dest='detail', action='store_true',
                 default=False, help='show detailed output')
@@ -411,7 +411,7 @@ class image_list(object):
 @command(api='compute')
 class image_info(object):
     """Get image details"""
-    
+
     def main(self, image_id):
         image = self.client.get_image_details(image_id)
         print_dict(image)
@@ -420,7 +420,7 @@ class image_info(object):
 @command(api='compute')
 class image_delete(object):
     """Delete image"""
-    
+
     def main(self, image_id):
         self.client.delete_image(image_id)
 
@@ -428,7 +428,7 @@ class image_delete(object):
 @command(api='compute')
 class image_properties(object):
     """Get image properties"""
-    
+
     def main(self, image_id, key=None):
         reply = self.client.get_image_metadata(image_id, key)
         print_dict(reply)
@@ -437,7 +437,7 @@ class image_properties(object):
 @command(api='compute')
 class image_addproperty(object):
     """Add an image property"""
-    
+
     def main(self, image_id, key, val):
         reply = self.client.create_image_metadata(image_id, key, val)
         print_dict(reply)
@@ -446,7 +446,7 @@ class image_addproperty(object):
 @command(api='compute')
 class image_setproperty(object):
     """Update an image property"""
-    
+
     def main(self, image_id, key, val):
         metadata = {key: val}
         reply = self.client.update_image_metadata(image_id, **metadata)
@@ -456,7 +456,7 @@ class image_setproperty(object):
 @command(api='compute')
 class image_delproperty(object):
     """Delete an image property"""
-    
+
     def main(self, image_id, key):
         self.client.delete_image_metadata(image_id, key)
 
@@ -464,7 +464,7 @@ class image_delproperty(object):
 @command(api='cyclades')
 class network_list(object):
     """List networks"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-l', dest='detail', action='store_true',
                 default=False, help='show detailed output')
@@ -477,7 +477,7 @@ class network_list(object):
 @command(api='cyclades')
 class network_create(object):
     """Create a network"""
-    
+
     def main(self, name):
         reply = self.client.create_network(name)
         print_dict(reply)
@@ -486,7 +486,7 @@ class network_create(object):
 @command(api='cyclades')
 class network_info(object):
     """Get network details"""
-    
+
     def main(self, network_id):
         network = self.client.get_network_details(network_id)
         print_dict(network)
@@ -495,7 +495,7 @@ class network_info(object):
 @command(api='cyclades')
 class network_rename(object):
     """Update network name"""
-    
+
     def main(self, network_id, new_name):
         self.client.update_network_name(network_id, new_name)
 
@@ -503,7 +503,7 @@ class network_rename(object):
 @command(api='cyclades')
 class network_delete(object):
     """Delete a network"""
-    
+
     def main(self, network_id):
         self.client.delete_network(network_id)
 
@@ -511,7 +511,7 @@ class network_delete(object):
 @command(api='cyclades')
 class network_connect(object):
     """Connect a server to a network"""
-    
+
     def main(self, server_id, network_id):
         self.client.connect_server(server_id, network_id)
 
@@ -519,7 +519,7 @@ class network_connect(object):
 @command(api='cyclades')
 class network_disconnect(object):
     """Disconnect a server from a network"""
-    
+
     def main(self, server_id, network_id):
         self.client.disconnect_server(server_id, network_id)
 
@@ -527,7 +527,7 @@ class network_disconnect(object):
 @command(api='image')
 class image_public(object):
     """List public images"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('-l', dest='detail', action='store_true',
                 default=False, help='show detailed output')
@@ -553,7 +553,7 @@ class image_public(object):
             val = getattr(self.args, filter, None)
             if val is not None:
                 filters[filter] = val
-        
+
         order = self.args.order or ''
         images = self.client.list_public(self.args.detail, filters=filters,
                                          order=order)
@@ -563,7 +563,7 @@ class image_public(object):
 @command(api='image')
 class image_meta(object):
     """Get image metadata"""
-    
+
     def main(self, image_id):
         image = self.client.get_meta(image_id)
         print_dict(image)
@@ -572,7 +572,7 @@ class image_meta(object):
 @command(api='image')
 class image_register(object):
     """Register an image"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('--checksum', dest='checksum', metavar='CHECKSUM',
                 help='set image checksum')
@@ -597,17 +597,17 @@ class image_register(object):
             account = self.config.get('storage', 'account')
             container = self.config.get('storage', 'container')
             location = 'pithos://%s/%s/%s' % (account, container, location)
-        
+
         params = {}
         for key in ('checksum', 'container_format', 'disk_format', 'id',
                     'owner', 'size'):
             val = getattr(self.args, key)
             if val is not None:
                 params[key] = val
-        
+
         if self.args.is_public:
             params['is_public'] = 'true'
-        
+
         properties = {}
         for property in self.args.properties or []:
             key, sep, val = property.partition('=')
@@ -615,14 +615,14 @@ class image_register(object):
                 print("Invalid property '%s'" % property)
                 return 1
             properties[key.strip()] = val.strip()
-        
+
         self.client.register(name, location, params, properties)
 
 
 @command(api='image')
 class image_members(object):
     """Get image members"""
-    
+
     def main(self, image_id):
         members = self.client.list_members(image_id)
         for member in members:
@@ -632,7 +632,7 @@ class image_members(object):
 @command(api='image')
 class image_shared(object):
     """List shared images"""
-    
+
     def main(self, member):
         images = self.client.list_shared(member)
         for image in images:
@@ -642,7 +642,7 @@ class image_shared(object):
 @command(api='image')
 class image_addmember(object):
     """Add a member to an image"""
-    
+
     def main(self, image_id, member):
         self.client.add_member(image_id, member)
 
@@ -650,7 +650,7 @@ class image_addmember(object):
 @command(api='image')
 class image_delmember(object):
     """Remove a member from an image"""
-    
+
     def main(self, image_id, member):
         self.client.remove_member(image_id, member)
 
@@ -658,31 +658,31 @@ class image_delmember(object):
 @command(api='image')
 class image_setmembers(object):
     """Set the members of an image"""
-    
+
     def main(self, image_id, *member):
         self.client.set_members(image_id, member)
 
 
 class _store_account_command(object):
     """Base class for account level storage commands"""
-    
+
     def update_parser(self, parser):
         parser.add_argument('--account', dest='account', metavar='NAME',
                           help="Specify an account to use")
 
     def progress(self, message):
         """Return a generator function to be used for progress tracking"""
-        
+
         MESSAGE_LENGTH = 25
-        
+
         def progress_gen(n):
             msg = message.ljust(MESSAGE_LENGTH)
             for i in ProgressBar(msg).iter(range(n)):
                 yield
             yield
-        
+
         return progress_gen
-    
+
     def main(self):
         if self.args.account is not None:
             self.client.account = self.args.account
@@ -690,7 +690,7 @@ class _store_account_command(object):
 
 class _store_container_command(_store_account_command):
     """Base class for container level storage commands"""
-    
+
     def update_parser(self, parser):
         super(_store_container_command, self).update_parser(parser)
         parser.add_argument('--container', dest='container', metavar='NAME',
@@ -705,7 +705,7 @@ class _store_container_command(_store_account_command):
 @command(api='storage')
 class store_create(_store_account_command):
     """Create a container"""
-    
+
     def main(self, container):
         super(store_create, self).main()
         self.client.create_container(container)
@@ -714,7 +714,7 @@ class store_create(_store_account_command):
 @command(api='storage')
 class store_container(_store_account_command):
     """Get container info"""
-    
+
     def main(self, container):
         super(store_container, self).main()
         reply = self.client.get_container_meta(container)
@@ -724,7 +724,7 @@ class store_container(_store_account_command):
 @command(api='storage')
 class store_list(_store_container_command):
     """List objects"""
-    
+
     def format_size(self, size):
         units = ('B', 'K', 'M', 'G', 'T')
         size = float(size)
@@ -734,22 +734,21 @@ class store_list(_store_container_command):
             size /= 1024
         s = ('%.1f' % size).rstrip('.0')
         return s + unit
-    
-    
+
     def main(self, path=''):
         super(store_list, self).main()
         for object in self.client.list_objects():
             size = self.format_size(object['bytes'])
             print('%6s %s' % (size, object['name']))
-        
+
 
 @command(api='storage')
 class store_upload(_store_container_command):
     """Upload a file"""
-    
+
     def main(self, path, remote_path=None):
         super(store_upload, self).main()
-        
+
         if remote_path is None:
             remote_path = basename(path)
         with open(path) as f:
@@ -762,21 +761,21 @@ class store_upload(_store_container_command):
 @command(api='storage')
 class store_download(_store_container_command):
     """Download a file"""
-        
+
     def main(self, remote_path, local_path='-'):
         super(store_download, self).main()
-        
+
         f, size = self.client.get_object(remote_path)
         out = open(local_path, 'w') if local_path != '-' else stdout
-        
-        blocksize = 4 * 1024**2
+
+        blocksize = 4 * 1024 ** 2
         nblocks = 1 + (size - 1) // blocksize
-        
+
         cb = self.progress('Downloading blocks') if local_path != '-' else None
         if cb:
             gen = cb(nblocks)
             gen.next()
-        
+
         data = f.read(blocksize)
         while data:
             out.write(data)
@@ -788,7 +787,7 @@ class store_download(_store_container_command):
 @command(api='storage')
 class store_delete(_store_container_command):
     """Delete a file"""
-    
+
     def main(self, path):
         super(store_delete, self).main()
         self.client.delete_object(path)
@@ -797,7 +796,7 @@ class store_delete(_store_container_command):
 @command(api='storage')
 class store_purge(_store_account_command):
     """Purge a container"""
-    
+
     def main(self, container):
         super(store_purge, self).main()
         self.client.purge_container(container)
@@ -806,7 +805,7 @@ class store_purge(_store_account_command):
 @command(api='astakos')
 class astakos_authenticate(object):
     """Authenticate a user"""
-    
+
     def main(self):
         reply = self.client.authenticate()
         print_dict(reply)
@@ -823,7 +822,7 @@ def print_commands(group):
     description = GROUPS.get(group, '')
     if description:
         print('\n' + description)
-    
+
     print('\nCommands:')
     for name, cls in _commands[group].items():
         print(' ', name.ljust(14), cls.description)
@@ -885,7 +884,7 @@ def main():
             print("Invalid option '%s'" % option)
             exit(1)
         config.override(section.strip(), key.strip(), val.strip())
-    
+
     apis = set(['config'])
     for api in ('compute', 'image', 'storage', 'astakos'):
         if config.getboolean(api, 'enable'):
@@ -894,7 +893,7 @@ def main():
         apis.add('cyclades')
     if config.getboolean('storage', 'pithos_extensions'):
         apis.add('pithos')
-    
+
     # Remove commands that belong to APIs that are not included
     for group, group_commands in _commands.items():
         for name, cls in group_commands.items():
@@ -927,7 +926,7 @@ def main():
         parser.print_help()
         print_commands(group)
         exit(1)
-    
+
     cmd = _commands[group][command]()
 
     parser.prog = '%s %s %s' % (exe, group, command)
@@ -937,13 +936,13 @@ def main():
     parser.epilog = ''
     if hasattr(cmd, 'update_parser'):
         cmd.update_parser(parser)
-    
+
     args, argv = parser.parse_known_args()
-    
+
     if args.help:
         parser.print_help()
         exit(0)
-    
+
     if args.silent:
         add_handler('', logging.CRITICAL)
     elif args.debug:
@@ -958,7 +957,7 @@ def main():
         add_handler('clients.recv', logging.INFO)
     else:
         add_handler('', logging.WARNING)
-    
+
     api = cmd.api
     if api in ('compute', 'cyclades'):
         url = config.get('compute', 'url')
@@ -984,10 +983,10 @@ def main():
         url = config.get('astakos', 'url')
         token = config.get('astakos', 'token') or config.get('global', 'token')
         cmd.client = clients.astakos(url, token)
-    
+
     cmd.args = args
     cmd.config = config
-    
+
     try:
         ret = cmd.main(*argv[2:])
         exit(ret)
@@ -1004,7 +1003,7 @@ def main():
             message = magenta(err.message)
         else:
             message = red(err.message)
-        
+
         print(message, file=stderr)
         if err.details and (args.verbose or args.debug):
             print(err.details, file=stderr)
index f319030..91d6979 100644 (file)
@@ -62,7 +62,7 @@ class Client(object):
         self.base_url = base_url
         self.token = token
 
-    def raise_for_status(self, r):        
+    def raise_for_status(self, r):
         message = "%d %s" % (r.status_code, r.status)
         details = r.text
         raise ClientError(message, r.status_code, details)
@@ -93,14 +93,14 @@ class Client(object):
         sendlog.info('')
         if req.data:
             sendlog.info('%s', req.data)
-        
+
         recvlog.info('%d %s', r.status_code, r.status)
         for key, val in r.headers.items():
             recvlog.info('%s: %s', key, val)
         recvlog.info('')
         if not raw and r.content:
             recvlog.debug(r.content)
-        
+
         if success is not None:
             # Success can either be an in or a collection
             success = (success,) if isinstance(success, int) else success
index 89798bb..5478d7c 100644 (file)
@@ -36,7 +36,7 @@ from . import Client, ClientError
 
 class AstakosClient(Client):
     """GRNet Astakos API client"""
-    
+
     def raise_for_status(self, r):
         msg = r.text.strip()
         if msg:
@@ -44,7 +44,7 @@ class AstakosClient(Client):
         else:
             # Fallback to the default
             super(AstakosClient, self).raise_for_status(r)
-    
+
     def authenticate(self):
         r = self.get('/im/authenticate')
         return r.json
index 1f239fc..d39c196 100644 (file)
@@ -36,7 +36,7 @@ from . import Client, ClientError
 
 class ComputeClient(Client):
     """OpenStack Compute API 1.1 client"""
-    
+
     def raise_for_status(self, r):
         d = r.json
         if not d:
@@ -46,21 +46,21 @@ class ComputeClient(Client):
         message = '%s: %s' % (key, val.get('message', ''))
         details = val.get('details', '')
         raise ClientError(message, r.status_code, details)
-    
+
     def list_servers(self, detail=False):
         """List servers, returned detailed output if detailed is True"""
-        
+
         path = '/servers/detail' if detail else '/servers'
         r = self.get(path, success=200)
         return r.json['servers']['values']
-    
+
     def get_server_details(self, server_id):
         """Return detailed output on a server specified by its id"""
-        
+
         path = '/servers/%s' % (server_id,)
         r = self.get(path, success=200)
         return r.json['server']
-    
+
     def create_server(self, name, flavor_id, image_id, personality=None):
         """Submit request to create a new server
 
@@ -78,10 +78,10 @@ class ComputeClient(Client):
                           'imageRef': image_id}}
         if personality:
             req['server']['personality'] = personality
-        
+
         r = self.post('/servers', json=req, success=202)
         return r.json['server']
-    
+
     def update_server_name(self, server_id, new_name):
         """Update the name of the server as reported by the API.
 
@@ -91,45 +91,44 @@ class ComputeClient(Client):
         path = '/servers/%s' % (server_id,)
         req = {'server': {'name': new_name}}
         self.put(path, json=req, success=204)
-    
+
     def delete_server(self, server_id):
         """Submit a deletion request for a server specified by id"""
-        
+
         path = '/servers/%s' % (server_id,)
         self.delete(path, success=204)
-    
+
     def reboot_server(self, server_id, hard=False):
         """Submit a reboot request for a server specified by id"""
-        
+
         path = '/servers/%s/action' % (server_id,)
         type = 'HARD' if hard else 'SOFT'
         req = {'reboot': {'type': type}}
         self.post(path, json=req, success=202)
-    
+
     def get_server_metadata(self, server_id, key=None):
         path = '/servers/%s/meta' % (server_id,)
         if key:
             path += '/%s' % key
         r = self.get(path, success=200)
         return r.json['meta'] if key else r.json['metadata']['values']
-    
+
     def create_server_metadata(self, server_id, key, val):
         path = '/servers/%d/meta/%s' % (server_id, key)
         req = {'meta': {key: val}}
         r = self.put(path, json=req, success=201)
         return r.json['meta']
-    
+
     def update_server_metadata(self, server_id, **metadata):
         path = '/servers/%d/meta' % (server_id,)
         req = {'metadata': metadata}
         r = self.post(path, json=req, success=201)
         return r.json['metadata']
-    
+
     def delete_server_metadata(self, server_id, key):
         path = '/servers/%d/meta/%s' % (server_id, key)
         self.delete(path, success=204)
-    
-    
+
     def list_flavors(self, detail=False):
         path = '/flavors/detail' if detail else '/flavors'
         r = self.get(path, success=200)
@@ -139,18 +138,17 @@ class ComputeClient(Client):
         path = '/flavors/%d' % flavor_id
         r = self.get(path, success=200)
         return r.json['flavor']
-    
-    
+
     def list_images(self, detail=False):
         path = '/images/detail' if detail else '/images'
         r = self.get(path, success=200)
         return r.json['images']['values']
-    
+
     def get_image_details(self, image_id):
         path = '/images/%s' % (image_id,)
         r = self.get(path, success=200)
         return r.json['image']
-    
+
     def delete_image(self, image_id):
         path = '/images/%s' % (image_id,)
         self.delete(path, success=204)
@@ -161,7 +159,7 @@ class ComputeClient(Client):
             path += '/%s' % key
         r = self.get(path, success=200)
         return r.json['meta'] if key else r.json['metadata']['values']
-    
+
     def create_image_metadata(self, image_id, key, val):
         path = '/images/%s/meta/%s' % (image_id, key)
         req = {'meta': {key: val}}
index f4503cc..d9d55d6 100644 (file)
@@ -36,29 +36,29 @@ from .compute import ComputeClient
 
 class CycladesClient(ComputeClient):
     """GRNet Cyclades API client"""
-    
+
     def start_server(self, server_id):
         """Submit a startup request for a server specified by id"""
-        
+
         path = '/servers/%s/action' % (server_id,)
         req = {'start': {}}
         self.post(path, json=req, success=202)
-    
+
     def shutdown_server(self, server_id):
         """Submit a shutdown request for a server specified by id"""
-        
+
         path = '/servers/%s/action' % (server_id,)
         req = {'shutdown': {}}
         self.post(path, json=req, success=202)
-    
+
     def get_server_console(self, server_id):
         """Get a VNC connection to the console of a server specified by id"""
-        
+
         path = '/servers/%s/action' % (server_id,)
         req = {'console': {'type': 'vnc'}}
         r = self.post(path, json=req, success=200)
         return r.json['console']
-    
+
     def set_firewall_profile(self, server_id, profile):
         """Set the firewall profile for the public interface of a server
 
@@ -68,7 +68,7 @@ class CycladesClient(ComputeClient):
         path = '/servers/%s/action' % (server_id,)
         req = {'firewallProfile': {'profile': profile}}
         self.post(path, json=req, success=202)
-    
+
     def list_server_addresses(self, server_id, network=None):
         path = '/servers/%s/ips' % (server_id,)
         if network:
@@ -78,13 +78,12 @@ class CycladesClient(ComputeClient):
             return [r.json['network']]
         else:
             return r.json['addresses']['values']
-    
+
     def get_server_stats(self, server_id):
         path = '/servers/%s/stats' % (server_id,)
         r = self.get(path, success=200)
         return r.json['stats']
-    
-    
+
     def list_networks(self, detail=False):
         path = '/networks/detail' if detail else '/networks'
         r = self.get(path, success=200)
index 36dcb2a..3e39857 100644 (file)
@@ -37,40 +37,40 @@ from . import Client, ClientError
 
 class ImageClient(Client):
     """OpenStack Image Service API 1.0 and GRNET Plankton client"""
-    
+
     def raise_for_status(self, r):
         if r.status_code == 404:
             raise ClientError("Image not found", r.status_code)
-        
+
         # Fallback to the default
         super(ImageClient, self).raise_for_status(r)
-    
+
     def list_public(self, detail=False, filters={}, order=''):
         path = '/images/detail' if detail else '/images/'
         params = {}
         params.update(filters)
-        
+
         if order.startswith('-'):
             params['sort_dir'] = 'desc'
             order = order[1:]
         else:
             params['sort_dir'] = 'asc'
-        
+
         if order:
             params['sort_key'] = order
-        
+
         r = self.get(path, params=params, success=200)
         return r.json
-    
+
     def get_meta(self, image_id):
         path = '/images/%s' % (image_id,)
         r = self.head(path, success=200)
-        
+
         reply = {}
         properties = {}
         meta_prefix = 'x-image-meta-'
         property_prefix = 'x-image-meta-property-'
-        
+
         for key, val in r.headers.items():
             key = key.lower()
             if key.startswith(property_prefix):
@@ -79,28 +79,28 @@ class ImageClient(Client):
             elif key.startswith(meta_prefix):
                 key = key[len(meta_prefix):]
                 reply[key] = val
-        
+
         if properties:
             reply['properties'] = properties
         return reply
-    
+
     def register(self, name, location, params={}, properties={}):
         path = '/images/'
         headers = {}
         headers['x-image-meta-name'] = name
         headers['x-image-meta-location'] = location
-        
+
         for key, val in params.items():
             if key in ('id', 'store', 'disk_format', 'container_format',
                        'size', 'checksum', 'is_public', 'owner'):
                 key = 'x-image-meta-' + key.replace('_', '-')
                 headers[key] = val
-        
+
         for key, val in properties.items():
             headers['x-image-meta-property-' + key] = val
-        
+
         self.post(path, headers=headers, success=200)
-    
+
     def list_members(self, image_id):
         path = '/images/%s/members' % (image_id,)
         r = self.get(path, success=200)
@@ -118,7 +118,7 @@ class ImageClient(Client):
     def remove_member(self, image_id, member):
         path = '/images/%s/members/%s' % (image_id, member)
         self.delete(path, success=204)
-    
+
     def set_members(self, image_id, members):
         path = '/images/%s/members' % image_id
         req = {'memberships': [{'member_id': member} for member in members]}
index 9698631..703629b 100644 (file)
@@ -63,20 +63,20 @@ class PithosClient(StorageClient):
         r = self.post(path, params=params, data=data, headers=headers,
                       success=202)
         assert r.text.strip() == hash, 'Local hash does not match server'
-    
+
     def create_object(self, object, f, size=None, hash_cb=None,
                       upload_cb=None):
         """Create an object by uploading only the missing blocks
-        
+
         hash_cb is a generator function taking the total number of blocks to
         be hashed as an argument. Its next() will be called every time a block
         is hashed.
-        
+
         upload_cb is a generator function with the same properties that is
         called every time a block is uploaded.
         """
         self.assert_container()
-        
+
         meta = self.get_container_meta(self.container)
         blocksize = int(meta['block-size'])
         blockhash = meta['block-hash']
@@ -113,9 +113,9 @@ class PithosClient(StorageClient):
 
         if r.status_code == 201:
             return
-        
+
         missing = r.json
-        
+
         if upload_cb:
             upload_gen = upload_cb(len(missing))
             upload_gen.next()
index 7dad66e..3c984a8 100644 (file)
@@ -36,44 +36,44 @@ from . import Client, ClientError
 
 class StorageClient(Client):
     """OpenStack Object Storage API 1.0 client"""
-    
+
     def __init__(self, base_url, token, account=None, container=None):
         super(StorageClient, self).__init__(base_url, token)
         self.account = account
         self.container = container
-    
+
     def assert_account(self):
         if not self.account:
             raise ClientError("Please provide an account")
-    
+
     def assert_container(self):
         self.assert_account()
         if not self.container:
             raise ClientError("Please provide a container")
-    
+
     def create_container(self, container):
         self.assert_account()
         path = '/%s/%s' % (self.account, container)
         r = self.put(path, success=(201, 202))
         if r.status_code == 202:
             raise ClientError("Container already exists", r.status_code)
-    
+
     def get_container_meta(self, container):
         self.assert_account()
         path = '/%s/%s' % (self.account, container)
         r = self.head(path, success=(204, 404))
         if r.status_code == 404:
             raise ClientError("Container does not exist", r.status_code)
-        
+
         reply = {}
         prefix = 'x-container-'
         for key, val in r.headers.items():
             key = key.lower()
             if key.startswith(prefix):
                 reply[key[len(prefix):]] = val
-        
+
         return reply
-    
+
     def create_object(self, object, f, size=None, hash_cb=None,
                       upload_cb=None):
         # This is a naive implementation, it loads the whole file in memory
@@ -81,19 +81,19 @@ class StorageClient(Client):
         path = '/%s/%s/%s' % (self.account, self.container, object)
         data = f.read(size) if size is not None else f.read()
         self.put(path, data=data, success=201)
-    
+
     def get_object(self, object):
         self.assert_container()
         path = '/%s/%s/%s' % (self.account, self.container, object)
         r = self.get(path, raw=True, success=200)
         size = int(r.headers['content-length'])
         return r.raw, size
-    
+
     def delete_object(self, object):
         self.assert_container()
         path = '/%s/%s/%s' % (self.account, self.container, object)
         self.delete(path, success=204)
-    
+
     def list_objects(self, path=''):
         self.assert_container()
         path = '/%s/%s' % (self.account, self.container)
index f4733ac..d5643c2 100644 (file)
@@ -90,31 +90,31 @@ class Config(RawConfigParser):
         self.path = path or os.environ.get(CONFIG_ENV, CONFIG_PATH)
         self._overrides = defaultdict(dict)
         self.read(self.path)
-    
+
     def sections(self):
         return DEFAULTS.keys()
-    
+
     def get(self, section, option):
         value = self._overrides.get(section, {}).get(option)
         if value is not None:
             return value
-        
+
         try:
             return RawConfigParser.get(self, section, option)
         except (NoSectionError, NoOptionError):
             return DEFAULTS.get(section, {}).get(option)
-    
+
     def set(self, section, option, value):
         if section not in RawConfigParser.sections(self):
             self.add_section(section)
         RawConfigParser.set(self, section, option, value)
-    
+
     def remove_option(self, section, option):
         try:
             RawConfigParser.remove_option(self, section, option)
         except NoSectionError:
             pass
-    
+
     def items(self, section, include_defaults=False):
         d = dict(DEFAULTS[section]) if include_defaults else {}
         try:
@@ -122,10 +122,10 @@ class Config(RawConfigParser):
         except NoSectionError:
             pass
         return d.items()
-    
+
     def override(self, section, option, value):
         self._overrides[section][option] = value
-    
+
     def write(self):
         with open(self.path, 'w') as f:
             os.chmod(self.path, 0600)
index a4ac780..506e276 100644 (file)
@@ -31,6 +31,7 @@
 # interpreted as representing official policies, either expressed
 # or implied, of GRNET S.A.
 
+
 def print_addresses(addresses, margin):
     for address in addresses:
         if address['id'] == 'public':
@@ -56,11 +57,11 @@ def print_dict(d, exclude=()):
     if not d:
         return
     margin = max(len(key) for key in d) + 1
-    
+
     for key, val in sorted(d.items()):
         if key in exclude:
             continue
-        
+
         if key == 'addresses':
             print '%s:' % 'addresses'.rjust(margin)
             print_addresses(val.get('values', []), margin)
@@ -74,7 +75,7 @@ def print_dict(d, exclude=()):
             for key, val in val.items():
                 print '%s: %s' % (key.rjust(margin + 4), val)
             continue
-        
+
         print '%s: %s' % (key.rjust(margin), val)