diff --git a/confluent_server/bin/osdeploy b/confluent_server/bin/osdeploy new file mode 100644 index 00000000..f8e7ca94 --- /dev/null +++ b/confluent_server/bin/osdeploy @@ -0,0 +1,45 @@ +#!/usr/bin/python2 + +import argparse +import confluent.client as client +import sys +import time + +def main(args): + ap = argparse.ArgumentParser(description='Manage OS deployment resources') + sp = ap.add_subparsers(dest='command') + osip = sp.add_parser('osimport') + osip.add_argument('imagefile', help='File to use for source of importing') + cmdset = ap.parse_args() + if cmdset.command == 'osimport': + osimport(cmdset.imagefile) + +def osimport(imagefile): + c = client.Command() + importing = False + shortname = None + for rsp in c.create('/deployment/importing/', {'filename': imagefile}): + if 'target' in rsp: + importing = True + shortname = rsp['target'].split('/')[-1] + print('Importing from {0} to {1}'.format(imagefile, rsp['target'])) + else: + print(repr(rsp)) + while importing: + for rsp in c.read('/deployment/importing/{0}'.format(shortname)): + if 'progress' in rsp: + sys.stdout.write('{0}: {1:.2f}% \r'.format(rsp['phase'], + rsp['progress'])) + if rsp['phase'] == 'complete': + importing = False + sys.stdout.write('\n') + for profile in rsp['profiles']: + print('Deployment profile created: {0}'.format(profile)) + sys.stdout.flush() + else: + print(repr(rsp)) + time.sleep(0.5) + list(c.delete('/deployment/importing/{0}'.format(shortname))) + +if __name__ == '__main__': + main(sys.argv) \ No newline at end of file diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index 41882bdc..02c45128 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -316,6 +316,7 @@ class MediaImporter(object): def __init__(self, media): self.worker = None + self.profiles = [] identity = fingerprint(media) self.percent = 0.0 identity, _ = identity @@ -340,7 +341,6 @@ class MediaImporter(object): raise Exception('{0} already exists'.format(self.targpath)) self.filename = os.path.abspath(media) self.importer = eventlet.spawn(self.importmedia) - self.profiles = [] def stop(self): if self.worker and self.worker.poll() is None: @@ -348,7 +348,7 @@ class MediaImporter(object): @property def progress(self): - return {'phase': self.phase, 'progress': self.percent} + return {'phase': self.phase, 'progress': self.percent, 'profiles': self.profiles} def importmedia(self): os.environ['PYTHONPATH'] = ':'.join(sys.path)