Add new windows sysprep for disabling hibernation
[snf-image-creator] / image_creator / dialog_menu.py
index 11dc1a7..9bc5c40 100644 (file)
@@ -157,7 +157,7 @@ def upload_image(session):
         session['upload'] = filename
         break
 
-    gauge = GaugeOutput(d, "Image Upload", "Uploading...")
+    gauge = GaugeOutput(d, "Image Upload", "Uploading ...")
     try:
         out = image.out
         out.add(gauge)
@@ -175,7 +175,7 @@ def upload_image(session):
                                       "Calculating block hashes",
                                       "Uploading missing blocks")
                 # Upload md5sum file
-                out.output("Uploading md5sum file...")
+                out.output("Uploading md5sum file ...")
                 md5str = "%s %s\n" % (session['checksum'], filename)
                 kamaki.upload(StringIO.StringIO(md5str), size=len(md5str),
                               remote_path="%s.md5sum" % filename)
@@ -243,26 +243,27 @@ def register_image(session):
             metadata[key] = 'yes'
 
     img_type = "public" if is_public else "private"
-    gauge = GaugeOutput(d, "Image Registration", "Registering image...")
+    gauge = GaugeOutput(d, "Image Registration", "Registering image ...")
     try:
         out = session['image'].out
         out.add(gauge)
         try:
             try:
-                out.output("Registering %s image with the cloud..." % img_type)
+                out.output("Registering %s image with the cloud ..." %
+                           img_type)
                 kamaki = Kamaki(session['account'], out)
                 result = kamaki.register(name, session['pithos_uri'], metadata,
                                          is_public)
                 out.success('done')
                 # Upload metadata file
-                out.output("Uploading metadata file...")
+                out.output("Uploading metadata file ...")
                 metastring = unicode(json.dumps(result, ensure_ascii=False))
                 kamaki.upload(StringIO.StringIO(metastring),
                               size=len(metastring),
                               remote_path="%s.meta" % session['upload'])
                 out.success("done")
                 if is_public:
-                    out.output("Sharing metadata and md5sum files...")
+                    out.output("Sharing metadata and md5sum files ...")
                     kamaki.share("%s.meta" % session['upload'])
                     kamaki.share("%s.md5sum" % session['upload'])
                     out.success('done')
@@ -618,6 +619,41 @@ def exclude_tasks(session):
     return True
 
 
+def sysprep_params(session):
+
+    d = session['dialog']
+    image = session['image']
+
+    available = image.os.sysprep_params
+    needed = image.os.needed_sysprep_params()
+
+    if len(needed) == 0:
+        return True
+
+    fields = []
+    for param in needed:
+        default = available[param.name] if param.name in available else ""
+        fields.append(("%s: " % param.description, default, param.length))
+
+    txt = "Please provide the following system preparation parameters:"
+    code, output = d.form(txt, height=13, width=WIDTH, form_height=len(fields),
+                          fields=fields)
+
+    if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
+        return False
+
+    sysprep_params = {}
+    for i in range(len(fields)):
+        if needed[i].validator(output[i]):
+            image.os.sysprep_params[needed[i].name] = output[i]
+        else:
+            d.msgbox("The value you provided for parameter: %s is not valid" %
+                     name, width=SMALL_WIDTH)
+            return False
+
+    return True
+
+
 def sysprep(session):
     """Perform various system preperation tasks on the image"""
     d = session['dialog']
@@ -634,9 +670,6 @@ def sysprep(session):
 
     wrapper = textwrap.TextWrapper(width=WIDTH - 5)
 
-    help_title = "System Preperation Tasks"
-    sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))
-
     syspreps = image.os.list_syspreps()
 
     if len(syspreps) == 0:
@@ -647,6 +680,10 @@ def sysprep(session):
     while 1:
         choices = []
         index = 0
+
+        help_title = "System Preperation Tasks"
+        sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))
+
         for sysprep in syspreps:
             name, descr = image.os.sysprep_info(sysprep)
             display_name = name.replace('-', ' ').capitalize()
@@ -681,6 +718,9 @@ def sysprep(session):
                          title="System Preperation", width=SMALL_WIDTH)
                 continue
 
+            if not sysprep_params(session):
+                continue
+
             infobox = InfoBoxOutput(d, "Image Configuration")
             try:
                 image.out.add(infobox)
@@ -804,7 +844,7 @@ def main_menu(session):
                 break
         elif choice == "Reset":
             if confirm_reset(d):
-                d.infobox("Resetting snf-image-creator. Please wait...",
+                d.infobox("Resetting snf-image-creator. Please wait ...",
                           width=SMALL_WIDTH)
                 raise Reset
         elif choice == "Help":