Make jeos_create aware of existing disk files and previous glance registrations
The user is interactively prompted for decisions to be made when: -An existing jeos disk image is found: build a fresh JEOS? -If fresh JEOS is chosen, continue as normal removing the files and existing registration if it exists. -If no fresh JEOS is chosen: register existing JEOS with glance? -If no registration is chosen, no action is taken. -If registration is chosen, continues as normal without rerunning oz in the case of the image not being previously registered with glance. -If the image is previously registered: delete existing JEOS in glance? -If the user chooses to not delete existing registration, no action is taken. -If registration deletion is chosen, the registration is deleted, rerunning oz is skipped, and the registration will occur. Fixes #50 Signed-off-by: Jeff Peeler <jpeeler@redhat.com>
This commit is contained in:
parent
1a3186dc6f
commit
2f5ec8738d
68
bin/heat
68
bin/heat
|
@ -304,6 +304,54 @@ def jeos_create(options, arguments):
|
|||
print 'The tdl for that disto/arch is not available'
|
||||
sys.exit(1)
|
||||
|
||||
creds = dict(username=options.username,
|
||||
password=options.password,
|
||||
tenant=options.tenant,
|
||||
auth_url=options.auth_url,
|
||||
strategy=options.auth_strategy)
|
||||
|
||||
client = glance_client.Client(host="0.0.0.0", port=9292,
|
||||
use_ssl=False, auth_tok=None, creds=creds)
|
||||
|
||||
parameters = {
|
||||
"filters": {},
|
||||
"limit": 10,
|
||||
}
|
||||
images = client.get_images(**parameters)
|
||||
|
||||
image_registered = False
|
||||
for image in images:
|
||||
if image['name'] == distro + '-' + arch + '-' + instance_type:
|
||||
image_registered = True
|
||||
#print ' *** image already in glance: %s > %s' % (image['name'], image['id'])
|
||||
|
||||
runoz = None
|
||||
if os.access(qcow2_filename, os.R_OK):
|
||||
while runoz not in ('y', 'n'):
|
||||
runoz = raw_input('An existing JEOS was found on disk. Do you want to build a fresh JEOS? (y/n) ').lower()
|
||||
if runoz == 'y':
|
||||
os.remove(qcow2_filename)
|
||||
os.remove(dsk_filename)
|
||||
if image_registered:
|
||||
client.delete_image(image['id'])
|
||||
elif runoz == 'n':
|
||||
answer = None
|
||||
while answer not in ('y', 'n'):
|
||||
answer = raw_input('Do you want to register your existing JEOS file with glance? (y/n) ').lower()
|
||||
if answer == 'n':
|
||||
print 'No action taken'
|
||||
sys.exit(0)
|
||||
elif answer == 'y' and image_registered:
|
||||
answer = None
|
||||
while answer not in ('y', 'n'):
|
||||
answer = raw_input('Do you want to delete the existing JEOS in glance? (y/n) ').lower()
|
||||
if answer == 'n':
|
||||
print 'No action taken'
|
||||
sys.exit(0)
|
||||
elif answer == 'y':
|
||||
client.delete_image(image['id'])
|
||||
|
||||
if runoz == None or runoz == 'y':
|
||||
print 'Creating JEOS image (%s) - this takes approximately 10 minutes.' % image_name
|
||||
extra_opts = ' '
|
||||
if options.debug:
|
||||
|
@ -321,20 +369,6 @@ def jeos_create(options, arguments):
|
|||
|
||||
print 'Registering JEOS image (%s) with OpenStack Glance.' % image_name
|
||||
|
||||
creds = dict(username=options.username,
|
||||
password=options.password,
|
||||
tenant=options.tenant,
|
||||
auth_url=options.auth_url,
|
||||
strategy=options.auth_strategy)
|
||||
|
||||
client = glance_client.Client(host="0.0.0.0", port=9292,
|
||||
use_ssl=False, auth_tok=None, creds=creds)
|
||||
|
||||
parameters = {
|
||||
"filters": {},
|
||||
"limit": 10,
|
||||
}
|
||||
|
||||
image_meta = {'name': image_name,
|
||||
'is_public': True,
|
||||
'disk_format': 'qcow2',
|
||||
|
@ -343,12 +377,6 @@ def jeos_create(options, arguments):
|
|||
'owner': options.username,
|
||||
'container_format': 'bare'}
|
||||
|
||||
images = client.get_images(**parameters)
|
||||
for image in images:
|
||||
if image['name'] == distro:
|
||||
print ' *** image already in glance: %s > %s' % (image['name'], image['id'])
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
with open(qcow2_filename) as ifile:
|
||||
image_meta = client.add_image(image_meta, ifile)
|
||||
|
|
Loading…
Reference in New Issue