Skip to content
Snippets Groups Projects
Commit cf4f52b6 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Read ~okeanos account/token from kamaki

If present in the kamaki configuration file, the user will read
the ~okeanos credentials using the kamaki config interface.
Whenever the user changes the ~okeanos credentians, the changes are
pushed back to kamaki.
parent 5a0399d8
No related branches found
No related tags found
No related merge requests found
...@@ -265,10 +265,10 @@ def upload_image(session): ...@@ -265,10 +265,10 @@ def upload_image(session):
break break
out = GaugeOutput(d, "Image Upload", "Uploading...") out = GaugeOutput(d, "Image Upload", "Uploading...")
if 'checksum' not in session:
md5 = MD5(out)
session['checksum'] = md5.compute(session['snapshot'], size)
try: try:
if 'checksum' not in session:
md5 = MD5(out)
session['checksum'] = md5.compute(session['snapshot'], size)
kamaki = Kamaki(session['account'], session['token'], out) kamaki = Kamaki(session['account'], session['token'], out)
try: try:
# Upload image file # Upload image file
...@@ -364,6 +364,8 @@ def register_image(session): ...@@ -364,6 +364,8 @@ def register_image(session):
def kamaki_menu(session): def kamaki_menu(session):
d = session['dialog'] d = session['dialog']
default_item = "Account" default_item = "Account"
(session['account'], session['token']) = Kamaki.saved_credentials()
while 1: while 1:
account = session["account"] if "account" in session else "<none>" account = session["account"] if "account" in session else "<none>"
token = session["token"] if "token" in session else "<none>" token = session["token"] if "token" in session else "<none>"
...@@ -395,6 +397,7 @@ def kamaki_menu(session): ...@@ -395,6 +397,7 @@ def kamaki_menu(session):
del session["account"] del session["account"]
else: else:
session["account"] = answer.strip() session["account"] = answer.strip()
Kamaki.save_account(session['account'])
default_item = "Token" default_item = "Token"
elif choice == "Token": elif choice == "Token":
default_item = "Token" default_item = "Token"
...@@ -408,6 +411,7 @@ def kamaki_menu(session): ...@@ -408,6 +411,7 @@ def kamaki_menu(session):
del session["token"] del session["token"]
else: else:
session["token"] = answer.strip() session["token"] = answer.strip()
Kamaki.save_token(session['account'])
default_item = "Upload" default_item = "Upload"
elif choice == "Upload": elif choice == "Upload":
if upload_image(session): if upload_image(session):
...@@ -855,15 +859,27 @@ def image_creator(d): ...@@ -855,15 +859,27 @@ def image_creator(d):
"image_os": image_os, "image_os": image_os,
"metadata": metadata} "metadata": metadata}
msg = "Would you like to run the snf-image-creator wizard? " \ msg = "snf-image-creator detected a %s system on the input media. " \
"Choose <Yes> if you want to run a wizards to assists " \ "Would you like to run a wizards to assists you through the " \
"you through the image creation process. Choose <No> to run " \ "image creation process?\n\nChoose <Yes> to run the wizard, " \
"the program in expert mode." "<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): exit_msg = "You have not selected if you want to run " \
main_menu(session) "snf-image-creator in wizard or expert mode."
else: if confirm_exit(d, exit_msg):
wizard(session) break
d.infobox("Thank you for using snf-image-creator. Bye", width=53) d.infobox("Thank you for using snf-image-creator. Bye", width=53)
finally: finally:
......
...@@ -44,6 +44,27 @@ CONTAINER = "images" ...@@ -44,6 +44,27 @@ CONTAINER = "images"
class Kamaki(object): 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): def __init__(self, account, token, output):
self.account = account self.account = account
self.token = token self.token = token
...@@ -53,13 +74,11 @@ class Kamaki(object): ...@@ -53,13 +74,11 @@ class Kamaki(object):
pithos_url = config.get('storage', 'url') pithos_url = config.get('storage', 'url')
self.container = CONTAINER self.container = CONTAINER
self.pithos_client = PithosClient(pithos_url, token, self.account, self.pithos_client = PithosClient(pithos_url, self.token, self.account,
self.container) self.container)
image_url = config.get('image', 'url') image_url = config.get('image', 'url')
self.image_client = ImageClient(image_url, token) self.image_client = ImageClient(image_url, self.token)
self.uploaded_object = None
def upload(self, file_obj, size=None, remote_path=None, hp=None, up=None): def upload(self, file_obj, size=None, remote_path=None, hp=None, up=None):
"""Upload a file to pithos""" """Upload a file to pithos"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment