Revision 42ace959
b/image_creator/disk.py | ||
---|---|---|
336 | 336 |
dest.close() |
337 | 337 |
finally: |
338 | 338 |
source.close() |
339 |
|
|
340 | 339 |
output("\rDumping image file...\033[K", False) |
341 | 340 |
success('image file %s was successfully created' % outfile) |
342 | 341 |
|
b/image_creator/kamaki_wrapper.py | ||
---|---|---|
61 | 61 |
yield |
62 | 62 |
return progress_gen |
63 | 63 |
|
64 |
|
|
64 | 65 |
class Kamaki: |
65 | 66 |
def __init__(self, account, token): |
66 | 67 |
self.account = account |
... | ... | |
100 | 101 |
raise FatalError("Pithos client: %d %s" % (e.status, e.message)) |
101 | 102 |
|
102 | 103 |
def register(self, name, location, metadata): |
103 |
params = {'is_public':'true', 'disk_format':'diskdump'} |
|
104 |
|
|
105 |
params = {'is_public': 'true', 'disk_format': 'diskdump'} |
|
104 | 106 |
try: |
105 | 107 |
self.image_client.register(name, location, params, metadata) |
106 | 108 |
except ClientError as e: |
b/image_creator/main.py | ||
---|---|---|
210 | 210 |
|
211 | 211 |
output('Dumping md5sum file...', False) |
212 | 212 |
with open('%s.%s' % (options.outfile, 'md5sum'), 'w') as f: |
213 |
f.write('%s %s'% (checksum, os.path.basename(options.outfile))) |
|
213 |
f.write('%s %s' % ( |
|
214 |
checksum, os.path.basename(options.outfile))) |
|
214 | 215 |
success('done') |
215 | 216 |
|
216 | 217 |
# Destroy the device. We only need the snapshot from now on |
... | ... | |
239 | 240 |
output() |
240 | 241 |
|
241 | 242 |
if options.register: |
242 |
output('Registing image to ~okeanos...') |
|
243 |
output('Registing image to ~okeanos...', False)
|
|
243 | 244 |
kamaki.register(options.register, uploaded_obj, metadata) |
244 |
output('done')
|
|
245 |
success('done')
|
|
245 | 246 |
output() |
246 | 247 |
|
247 | 248 |
finally: |
b/image_creator/util.py | ||
---|---|---|
34 | 34 |
import sys |
35 | 35 |
import pbs |
36 | 36 |
import hashlib |
37 |
from clint.textui import colored
|
|
37 |
from colors import red, green, yellow
|
|
38 | 38 |
from progress.bar import Bar |
39 | 39 |
|
40 | 40 |
|
... | ... | |
61 | 61 |
|
62 | 62 |
def error(msg, new_line=True): |
63 | 63 |
nl = "\n" if new_line else '' |
64 |
sys.stderr.write(colored.red('Error: %s' % msg) + nl)
|
|
64 |
sys.stderr.write(red('Error: %s' % msg) + nl) |
|
65 | 65 |
|
66 | 66 |
|
67 | 67 |
def warn(msg, new_line=True): |
68 | 68 |
if not silent: |
69 | 69 |
nl = "\n" if new_line else '' |
70 |
sys.stderr.write(colored.yellow("Warning: %s" % msg) + nl)
|
|
70 |
sys.stderr.write(yellow("Warning: %s" % msg) + nl) |
|
71 | 71 |
|
72 | 72 |
|
73 | 73 |
def success(msg, new_line=True): |
74 | 74 |
if not silent: |
75 | 75 |
nl = "\n" if new_line else '' |
76 |
sys.stdout.write(colored.green(msg) + nl)
|
|
76 |
sys.stdout.write(green(msg) + nl) |
|
77 | 77 |
if not nl: |
78 | 78 |
sys.stdout.flush() |
79 | 79 |
|
... | ... | |
89 | 89 |
def progress(message='', bar_type="default"): |
90 | 90 |
|
91 | 91 |
MESSAGE_LENGTH = 30 |
92 |
|
|
93 |
suffix={'default':'%(index)d/%(max)d', |
|
94 |
'percent':'%(percent)d%%', |
|
95 |
'b':'%(index)d/%(max)d B', |
|
96 |
'kb':'%(index)d/%(max)d KB', |
|
97 |
'mb':'%(index)d/%(max)d MB'} |
|
98 | 92 |
|
99 |
return Bar(message=message.ljust(MESSAGE_LENGTH), fill='#', \ |
|
100 |
suffix=suffix[bar_type]) |
|
93 |
suffix = { |
|
94 |
'default': '%(index)d/%(max)d', |
|
95 |
'percent': '%(percent)d%%', |
|
96 |
'b': '%(index)d/%(max)d B', |
|
97 |
'kb': '%(index)d/%(max)d KB', |
|
98 |
'mb': '%(index)d/%(max)d MB' |
|
99 |
} |
|
100 |
|
|
101 |
bar = Bar() |
|
102 |
bar.message = message.ljust(MESSAGE_LENGTH) |
|
103 |
bar.fill = '#' |
|
104 |
bar.suffix = suffix[bar_type] |
|
105 |
bar.bar_prefix = ' [' |
|
106 |
bar.bar_suffix = '] ' |
|
107 |
|
|
108 |
return bar |
|
109 |
|
|
101 | 110 |
|
102 | 111 |
def md5(filename, size): |
103 | 112 |
|
... | ... | |
114 | 123 |
md5.update(data) |
115 | 124 |
left -= length |
116 | 125 |
progressbar.goto((size - left) // (2 ** 20)) |
117 |
|
|
126 |
|
|
118 | 127 |
checksum = md5.hexdigest() |
119 | 128 |
output("\rCalculating md5sum...\033[K", False) |
120 | 129 |
success(checksum) |
b/setup.py | ||
---|---|---|
47 | 47 |
license='BSD', |
48 | 48 |
packages=['image_creator', 'image_creator.os_type'], |
49 | 49 |
include_package_data=True, |
50 |
install_requires=['pbs', 'clint', 'progress','pysendfile'],
|
|
50 |
install_requires=['pbs', 'ansicolors', 'progress', 'pysendfile'],
|
|
51 | 51 |
entry_points={ |
52 | 52 |
'console_scripts': ['snf-image-creator = image_creator.main:main'] |
53 | 53 |
} |
Also available in: Unified diff