+ 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()