break
out = GaugeOutput(d, "Image Upload", "Uploading...")
- if 'checksum' not in session:
- md5 = MD5(out)
- session['checksum'] = md5.compute(session['snapshot'], size)
try:
+ if 'checksum' not in session:
+ md5 = MD5(out)
+ session['checksum'] = md5.compute(session['snapshot'], size)
kamaki = Kamaki(session['account'], session['token'], out)
try:
# Upload image file
def kamaki_menu(session):
d = session['dialog']
default_item = "Account"
+
+ (session['account'], session['token']) = Kamaki.saved_credentials()
while 1:
account = session["account"] if "account" in session else "<none>"
token = session["token"] if "token" in session else "<none>"
del session["account"]
else:
session["account"] = answer.strip()
+ Kamaki.save_account(session['account'])
default_item = "Token"
elif choice == "Token":
default_item = "Token"
del session["token"]
else:
session["token"] = answer.strip()
+ Kamaki.save_token(session['account'])
default_item = "Upload"
elif choice == "Upload":
if upload_image(session):
"image_os": image_os,
"metadata": metadata}
- msg = "Would you like to run the snf-image-creator wizard? " \
- "Choose <Yes> if you want to run a wizards to assists " \
- "you through the image creation process. Choose <No> to run " \
- "the program in expert mode."
+ msg = "snf-image-creator detected a %s system on the input media. " \
+ "Would you like to run a wizards to assists you through the " \
+ "image creation process?\n\nChoose <Yes> to run the wizard, " \
+ "<No> to run the snf-image-creator in expert mode or press " \
+ "ESC to quit the program." \
+ % (dev.ostype if dev.ostype == dev.distro else "%s/%s" %
+ (dev.distro, dev.ostype))
+
+ while True:
+ code = d.yesno(msg, width=YESNO_WIDTH, height=12)
+ if code == d.DIALOG_OK:
+ if wizard(session):
+ break
+ elif code == d.DIALOG_CANCEL:
+ main_menu(session)
+ break
- if d.yesno(msg, width=YESNO_WIDTH):
- main_menu(session)
- else:
- wizard(session)
+ exit_msg = "You have not selected if you want to run " \
+ "snf-image-creator in wizard or expert mode."
+ if confirm_exit(d, exit_msg):
+ break
d.infobox("Thank you for using snf-image-creator. Bye", width=53)
finally:
class Kamaki(object):
+
+ @staticmethod
+ def saved_credentials():
+ config = Config()
+ account = config.get('storage', 'account')
+ token = config.get('global', 'token')
+
+ return (account, token)
+
+ @staticmethod
+ def save_account(account):
+ config = Config()
+ config.set('storage', 'account', account)
+ config.write()
+
+ @staticmethod
+ def save_token(token):
+ config = Config()
+ config.set('global', 'token', token)
+ config.write()
+
def __init__(self, account, token, output):
self.account = account
self.token = token
pithos_url = config.get('storage', 'url')
self.container = CONTAINER
- self.pithos_client = PithosClient(pithos_url, token, self.account,
+ self.pithos_client = PithosClient(pithos_url, self.token, self.account,
self.container)
image_url = config.get('image', 'url')
- self.image_client = ImageClient(image_url, token)
-
- self.uploaded_object = None
+ self.image_client = ImageClient(image_url, self.token)
def upload(self, file_obj, size=None, remote_path=None, hp=None, up=None):
"""Upload a file to pithos"""