+ """Wrapper class for the ./kamaki library"""
+ CONTAINER = "images"
+
+ @staticmethod
+ def get_default_cloud_name():
+ """Returns the name of the default cloud"""
+ clouds = config.keys('cloud')
+ default = config.get('global', 'default_cloud')
+ if not default:
+ return clouds[0] if len(clouds) else ""
+ return default if default in clouds else ""
+
+ @staticmethod
+ def set_default_cloud(name):
+ """Sets a cloud account as default"""
+ config.set('global', 'default_cloud', name)
+ config.write()
+
+ @staticmethod
+ def get_clouds():
+ """Returns the list of available clouds"""
+ names = config.keys('cloud')
+
+ clouds = {}
+ for name in names:
+ clouds[name] = config.get('cloud', name)
+
+ return clouds
+
+ @staticmethod
+ def get_cloud_by_name(name):
+ """Returns a dict with cloud info"""
+ return config.get('cloud', name)
+
+ @staticmethod
+ def save_cloud(name, url, token, description=""):
+ """Save a new cloud account"""
+ cloud = {'url': url, 'token': token}
+ if len(description):
+ cloud['description'] = description
+ config.set('cloud', name, cloud)
+
+ # Make the saved cloud the default one
+ config.set('global', 'default_cloud', name)
+ config.write()
+
+ @staticmethod
+ def remove_cloud(name):
+ """Deletes an existing cloud from the Kamaki configuration file"""
+ config.remove_option('cloud', name)
+ config.write()
+
+ @staticmethod
+ def create_account(url, token):
+ """Given a valid (URL, tokens) pair this method returns an Astakos
+ client instance
+ """
+ client = AstakosClient(url, token)
+ try:
+ client.authenticate()
+ except ClientError:
+ return None
+
+ return client
+
+ @staticmethod
+ def get_account(cloud_name):
+ """Given a saved cloud name this method returns an Astakos client
+ instance
+ """
+ cloud = config.get('cloud', cloud_name)
+ assert cloud, "cloud: `%s' does not exist" % cloud_name
+ assert 'url' in cloud, "url attr is missing in %s" % cloud_name
+ assert 'token' in cloud, "token attr is missing in %s" % cloud_name
+
+ return Kamaki.create_account(cloud['url'], cloud['token'])
+
+ def __init__(self, account, output):
+ """Create a Kamaki instance"""