src/modules/client/image.py
changeset 1086 16500d7bf1ca
parent 1085 aa3274c0fe55
child 1087 293c0aa5f32e
--- a/src/modules/client/image.py	Fri Apr 24 17:06:44 2009 -0700
+++ b/src/modules/client/image.py	Sat Apr 25 00:24:16 2009 -0500
@@ -339,14 +339,23 @@
 
                 self.__set_dirs(imgtype=imgtype, root=root)
 
+                # Create the publisher object before creating the image...
+                repo = publisher.Repository()
+                repo.add_origin(pub_url, ssl_cert=ssl_cert, ssl_key=ssl_key)
+                newpub = publisher.Publisher(prefix,
+                    meta_root=self._get_publisher_meta_root(prefix),
+                    repositories=[repo])
+
+                # ...so that if creation of the Publisher object fails, an
+                # empty, useless image won't be left behind.
                 if not os.path.exists(os.path.join(self.imgdir,
                     imageconfig.CFG_FILE)):
                         self.history.operation_name = "image-create"
                 else:
                         self.history.operation_name = "image-set-attributes"
 
+                # Now create the image directories.
                 self.mkdirs()
-
                 self.cfg_cache = imageconfig.ImageConfig()
 
                 if is_zone:
@@ -357,12 +366,6 @@
                         self.cfg_cache.variants[
                             "variant.opensolaris.zone"] = "global"
 
-                repo = publisher.Repository()
-                repo.add_origin(pub_url, ssl_cert=ssl_cert, ssl_key=ssl_key)
-                newpub = publisher.Publisher(prefix,
-                    meta_root=self._get_publisher_meta_root(prefix),
-                    repositories=[repo])
-
                 # Retrieve metadata for new repository, if allowed.
                 if refresh_allowed:
                         self.retrieve_catalogs(full_refresh=True,