Bump version to 0.2.8
[snf-image-creator] / image_creator / kamaki_wrapper.py
index dafea32..654a933 100644 (file)
@@ -39,8 +39,6 @@ from kamaki.clients.image import ImageClient
 from kamaki.clients.pithos import PithosClient
 from kamaki.clients.astakos import AstakosClient
 
-from image_creator.util import FatalError
-
 
 class Kamaki(object):
 
@@ -48,17 +46,20 @@ class Kamaki(object):
 
     @staticmethod
     def get_token():
+        """Get the saved token"""
         config = Config()
         return config.get('global', 'token')
 
     @staticmethod
     def save_token(token):
+        """Save this token to the configuration file"""
         config = Config()
         config.set('global', 'token', token)
         config.write()
 
     @staticmethod
     def get_account(token):
+        """Return the account corresponding to this token"""
         config = Config()
         astakos = AstakosClient(config.get('astakos', 'url'), token)
         try:
@@ -71,14 +72,16 @@ class Kamaki(object):
         return account
 
     def __init__(self, account, output):
+        """Create a Kamaki instance"""
         self.account = account
         self.out = output
 
         config = Config()
 
         pithos_url = config.get('store', 'url')
-        self.pithos_client = PithosClient(pithos_url,
-            self.account['auth_token'], self.account['uuid'], self.CONTAINER)
+        self.pithos_client = PithosClient(
+            pithos_url, self.account['auth_token'], self.account['uuid'],
+            self.CONTAINER)
 
         image_url = config.get('image', 'url')
         self.image_client = ImageClient(image_url, self.account['auth_token'])
@@ -103,15 +106,15 @@ class Kamaki(object):
         return "pithos://%s/%s/%s" % (self.account['uuid'], self.CONTAINER,
                                       path)
 
-    def register(self, name, location, metadata):
+    def register(self, name, location, metadata, public=False):
         """Register an image to ~okeanos"""
 
         # Convert all metadata to strings
         str_metadata = {}
         for (key, value) in metadata.iteritems():
             str_metadata[str(key)] = str(value)
-
-        params = {'is_public': 'true', 'disk_format': 'diskdump'}
+        is_public = 'true' if public else 'false'
+        params = {'is_public': is_public, 'disk_format': 'diskdump'}
         self.image_client.register(name, location, params, str_metadata)
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :