Lint: E202 whitespace before '}'

This commit is contained in:
2020-11-07 12:57:42 -05:00
parent b7daa8e1f6
commit 3f242cd437
16 changed files with 411 additions and 411 deletions

View File

@ -105,7 +105,7 @@ def list_benchmarks(job=None):
if data:
return data, 200
else:
return {'message': 'No benchmark found.' }, 404
return {'message': 'No benchmark found.'}, 404
def run_benchmark(self, pool):
# Runtime imports
@ -456,4 +456,4 @@ def run_benchmark(self, pool):
close_database(db_conn, db_cur)
pvc_common.stopZKConnection(zk_conn)
return {'status': "Storage benchmark '{}' completed successfully.", 'current': 3, 'total': 3 }
return {'status': "Storage benchmark '{}' completed successfully.", 'current': 3, 'total': 3}

File diff suppressed because it is too large Load Diff

View File

@ -439,7 +439,7 @@ def vm_define(xml, node, limit, selector, autostart, migration_method):
xml_data = etree.fromstring(xml)
new_cfg = etree.tostring(xml_data, pretty_print=True).decode('utf8')
except Exception as e:
return {'message': 'XML is malformed or incorrect: {}'.format(e) }, 400
return {'message': 'XML is malformed or incorrect: {}'.format(e)}, 400
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.define_vm(zk_conn, new_cfg, node, limit, selector, autostart, migration_method, profile=None)
@ -522,7 +522,7 @@ def vm_modify(name, restart, xml):
xml_data = etree.fromstring(xml)
new_cfg = etree.tostring(xml_data, pretty_print=True).decode('utf8')
except Exception as e:
return {'message': 'XML is malformed or incorrect: {}'.format(e) }, 400
return {'message': 'XML is malformed or incorrect: {}'.format(e)}, 400
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.modify_vm(zk_conn, name, restart, new_cfg)
pvc_common.stopZKConnection(zk_conn)
@ -1047,7 +1047,7 @@ def ceph_osd_state(osd):
in_state = retdata[0]['stats']['in']
up_state = retdata[0]['stats']['up']
return {"id": osd, "in": in_state, "up": up_state }, retcode
return {"id": osd, "in": in_state, "up": up_state}, retcode
def ceph_osd_add(node, device, weight):
"""

View File

@ -103,12 +103,12 @@ def list_ova(limit, is_fuzzy=True):
if ova_data:
return ova_data, 200
else:
return {'message': 'No OVAs found.' }, 404
return {'message': 'No OVAs found.'}, 404
def delete_ova(name):
ova_data, retcode = list_ova(name, is_fuzzy=False)
if retcode != 200:
retmsg = {'message': 'The OVA "{}" does not exist.'.format(name) }
retmsg = {'message': 'The OVA "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -146,10 +146,10 @@ def delete_ova(name):
args = (ova_id,)
cur.execute(query, args)
retmsg = {"message": 'Removed OVA image "{}".'.format(name) }
retmsg = {"message": 'Removed OVA image "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to remove OVA "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to remove OVA "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode

View File

@ -149,7 +149,7 @@ def list_template_system(limit, is_fuzzy=True):
if data:
return data, 200
else:
return {'message': 'No system templates found.' }, 404
return {'message': 'No system templates found.'}, 404
def list_template_network(limit, is_fuzzy=True):
"""
@ -159,7 +159,7 @@ def list_template_network(limit, is_fuzzy=True):
if data:
return data, 200
else:
return {'message': 'No network templates found.' }, 404
return {'message': 'No network templates found.'}, 404
def list_template_network_vnis(name):
"""
@ -170,7 +170,7 @@ def list_template_network_vnis(name):
if networks:
return networks, 200
else:
return {'message': 'No network template networks found.' }, 404
return {'message': 'No network template networks found.'}, 404
def list_template_storage(limit, is_fuzzy=True):
"""
@ -180,7 +180,7 @@ def list_template_storage(limit, is_fuzzy=True):
if data:
return data, 200
else:
return {'message': 'No storage templates found.' }, 404
return {'message': 'No storage templates found.'}, 404
def list_template_storage_disks(name):
"""
@ -191,7 +191,7 @@ def list_template_storage_disks(name):
if disks:
return disks, 200
else:
return {'message': 'No storage template disks found.' }, 404
return {'message': 'No storage template disks found.'}, 404
def template_list(limit):
system_templates, code = list_template_system(limit)
@ -204,14 +204,14 @@ def template_list(limit):
if code != 200:
storage_templates = []
return {"system_templates": system_templates, "network_templates": network_templates, "storage_templates": storage_templates }
return {"system_templates": system_templates, "network_templates": network_templates, "storage_templates": storage_templates}
#
# Template Create functions
#
def create_template_system(name, vcpu_count, vram_mb, serial=False, vnc=False, vnc_bind=None, node_limit=None, node_selector=None, node_autostart=False, migration_method=None, ova=None):
if list_template_system(name, is_fuzzy=False)[-1] != 404:
retmsg = {'message': 'The system template "{}" already exists.'.format(name) }
retmsg = {'message': 'The system template "{}" already exists.'.format(name)}
retcode = 400
return retmsg, retcode
@ -221,17 +221,17 @@ def create_template_system(name, vcpu_count, vram_mb, serial=False, vnc=False, v
conn, cur = open_database(config)
try:
cur.execute(query, args)
retmsg = {'message': 'Added new system template "{}".'.format(name) }
retmsg = {'message': 'Added new system template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create system template "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to create system template "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def create_template_network(name, mac_template=None):
if list_template_network(name, is_fuzzy=False)[-1] != 404:
retmsg = {'message': 'The network template "{}" already exists.'.format(name) }
retmsg = {'message': 'The network template "{}" already exists.'.format(name)}
retcode = 400
return retmsg, retcode
@ -240,17 +240,17 @@ def create_template_network(name, mac_template=None):
query = "INSERT INTO network_template (name, mac_template) VALUES (%s, %s);"
args = (name, mac_template)
cur.execute(query, args)
retmsg = {'message': 'Added new network template "{}".'.format(name) }
retmsg = {'message': 'Added new network template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create network template "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to create network template "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def create_template_network_element(name, vni):
if list_template_network(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The network template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The network template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -262,7 +262,7 @@ def create_template_network_element(name, vni):
if int(network['vni']) == int(vni):
found_vni = True
if found_vni:
retmsg = {'message': 'The VNI "{}" in network template "{}" already exists.'.format(vni, name) }
retmsg = {'message': 'The VNI "{}" in network template "{}" already exists.'.format(vni, name)}
retcode = 400
return retmsg, retcode
@ -275,17 +275,17 @@ def create_template_network_element(name, vni):
query = "INSERT INTO network (network_template, vni) VALUES (%s, %s);"
args = (template_id, vni)
cur.execute(query, args)
retmsg = {'message': 'Added new network "{}" to network template "{}".'.format(vni, name) }
retmsg = {'message': 'Added new network "{}" to network template "{}".'.format(vni, name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create entry "{}": {}'.format(vni, e) }
retmsg = {'message': 'Failed to create entry "{}": {}'.format(vni, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def create_template_storage(name):
if list_template_storage(name, is_fuzzy=False)[-1] != 404:
retmsg = {'message': 'The storage template "{}" already exists.'.format(name) }
retmsg = {'message': 'The storage template "{}" already exists.'.format(name)}
retcode = 400
return retmsg, retcode
@ -294,17 +294,17 @@ def create_template_storage(name):
query = "INSERT INTO storage_template (name) VALUES (%s);"
args = (name,)
cur.execute(query, args)
retmsg = {'message': 'Added new storage template "{}".'.format(name) }
retmsg = {'message': 'Added new storage template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def create_template_storage_element(name, disk_id, pool, source_volume=None, disk_size_gb=None, filesystem=None, filesystem_args=[], mountpoint=None):
if list_template_storage(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -316,17 +316,17 @@ def create_template_storage_element(name, disk_id, pool, source_volume=None, dis
if disk['disk_id'] == disk_id:
found_disk = True
if found_disk:
retmsg = {'message': 'The disk "{}" in storage template "{}" already exists.'.format(disk_id, name) }
retmsg = {'message': 'The disk "{}" in storage template "{}" already exists.'.format(disk_id, name)}
retcode = 400
return retmsg, retcode
if mountpoint and not filesystem:
retmsg = {"message": "A filesystem must be specified along with a mountpoint." }
retmsg = {"message": "A filesystem must be specified along with a mountpoint."}
retcode = 400
return retmsg, retcode
if source_volume and (disk_size_gb or filesystem or mountpoint):
retmsg = {"message": "Clone volumes are not compatible with disk size, filesystem, or mountpoint specifications." }
retmsg = {"message": "Clone volumes are not compatible with disk size, filesystem, or mountpoint specifications."}
retcode = 400
return retmsg, retcode
@ -343,10 +343,10 @@ def create_template_storage_element(name, disk_id, pool, source_volume=None, dis
fsargs = ''
args = (template_id, pool, disk_id, source_volume, disk_size_gb, mountpoint, filesystem, fsargs)
cur.execute(query, args)
retmsg = {'message': 'Added new disk "{}" to storage template "{}".'.format(disk_id, name) }
retmsg = {'message': 'Added new disk "{}" to storage template "{}".'.format(disk_id, name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create entry "{}": {}'.format(disk_id, e) }
retmsg = {'message': 'Failed to create entry "{}": {}'.format(disk_id, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
@ -356,7 +356,7 @@ def create_template_storage_element(name, disk_id, pool, source_volume=None, dis
#
def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc=None, vnc_bind=None, node_limit=None, node_selector=None, node_autostart=None, migration_method=None):
if list_template_system(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The system template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The system template "{}" does not exist.'.format(name)}
retcode = 404
return retmsg, retcode
@ -366,7 +366,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
try:
vcpu_count = int(vcpu_count)
except Exception:
retmsg = {'message': 'The vcpus value must be an integer.' }
retmsg = {'message': 'The vcpus value must be an integer.'}
retcode = 400
return retmsg, retcode
fields.append({'field': 'vcpu_count', 'data': vcpu_count})
@ -375,7 +375,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
try:
vram_mb = int(vram_mb)
except Exception:
retmsg = {'message': 'The vram value must be an integer.' }
retmsg = {'message': 'The vram value must be an integer.'}
retcode = 400
return retmsg, retcode
fields.append({'field': 'vram_mb', 'data': vram_mb})
@ -384,7 +384,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
try:
serial = bool(strtobool(serial))
except Exception:
retmsg = {'message': 'The serial value must be a boolean.' }
retmsg = {'message': 'The serial value must be a boolean.'}
retcode = 400
return retmsg, retcode
fields.append({'field': 'serial', 'data': serial})
@ -393,7 +393,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
try:
vnc = bool(strtobool(vnc))
except Exception:
retmsg = {'message': 'The vnc value must be a boolean.' }
retmsg = {'message': 'The vnc value must be a boolean.'}
retcode = 400
return retmsg, retcode
fields.append({'field': 'vnc', 'data': vnc})
@ -411,7 +411,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
try:
node_autostart = bool(strtobool(node_autostart))
except Exception:
retmsg = {'message': 'The node_autostart value must be a boolean.' }
retmsg = {'message': 'The node_autostart value must be a boolean.'}
retcode = 400
fields.append({'field': 'node_autostart', 'data': node_autostart})
@ -424,10 +424,10 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
query = "UPDATE system_template SET {} = %s WHERE name = %s;".format(field.get('field'))
args = (field.get('data'), name)
cur.execute(query, args)
retmsg = {"message": 'Modified system template "{}".'.format(name) }
retmsg = {"message": 'Modified system template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to modify entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to modify entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
@ -437,7 +437,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
#
def delete_template_system(name):
if list_template_system(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The system template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The system template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -446,17 +446,17 @@ def delete_template_system(name):
query = "DELETE FROM system_template WHERE name = %s;"
args = (name,)
cur.execute(query, args)
retmsg = {"message": 'Removed system template "{}".'.format(name) }
retmsg = {"message": 'Removed system template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_template_network(name):
if list_template_network(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The network template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The network template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -472,17 +472,17 @@ def delete_template_network(name):
query = "DELETE FROM network_template WHERE name = %s;"
args = (name,)
cur.execute(query, args)
retmsg = {"message": 'Removed network template "{}".'.format(name) }
retmsg = {"message": 'Removed network template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_template_network_element(name, vni):
if list_template_network(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The network template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The network template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -492,7 +492,7 @@ def delete_template_network_element(name, vni):
if network['vni'] == int(vni):
found_vni = True
if not found_vni:
retmsg = {'message': 'The VNI "{}" in network template "{}" does not exist.'.format(vni, name) }
retmsg = {'message': 'The VNI "{}" in network template "{}" does not exist.'.format(vni, name)}
retcode = 400
return retmsg, retcode
@ -505,17 +505,17 @@ def delete_template_network_element(name, vni):
query = "DELETE FROM network WHERE network_template = %s and vni = %s;"
args = (template_id, vni)
cur.execute(query, args)
retmsg = {"message": 'Removed network "{}" from network template "{}".'.format(vni, name) }
retmsg = {"message": 'Removed network "{}" from network template "{}".'.format(vni, name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_template_storage(name):
if list_template_storage(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -531,17 +531,17 @@ def delete_template_storage(name):
query = "DELETE FROM storage_template WHERE name = %s;"
args = (name,)
cur.execute(query, args)
retmsg = {"message": 'Removed storage template "{}".'.format(name) }
retmsg = {"message": 'Removed storage template "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_template_storage_element(name, disk_id):
if list_template_storage(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name) }
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -551,7 +551,7 @@ def delete_template_storage_element(name, disk_id):
if disk['disk_id'] == disk_id:
found_disk = True
if not found_disk:
retmsg = {'message': 'The disk "{}" in storage template "{}" does not exist.'.format(disk_id, name) }
retmsg = {'message': 'The disk "{}" in storage template "{}" does not exist.'.format(disk_id, name)}
retcode = 400
return retmsg, retcode
@ -564,10 +564,10 @@ def delete_template_storage_element(name, disk_id):
query = "DELETE FROM storage WHERE storage_template = %s and disk_id = %s;"
args = (template_id, disk_id)
cur.execute(query, args)
retmsg = {"message": 'Removed disk "{}" from storage template "{}".'.format(disk_id, name) }
retmsg = {"message": 'Removed disk "{}" from storage template "{}".'.format(disk_id, name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
@ -601,11 +601,11 @@ def list_userdata(limit, is_fuzzy=True):
if data:
return data, 200
else:
return {'message': 'No userdata documents found.' }, 404
return {'message': 'No userdata documents found.'}, 404
def create_userdata(name, userdata):
if list_userdata(name, is_fuzzy=False)[-1] != 404:
retmsg = {'message': 'The userdata document "{}" already exists.'.format(name) }
retmsg = {'message': 'The userdata document "{}" already exists.'.format(name)}
retcode = 400
return retmsg, retcode
@ -614,17 +614,17 @@ def create_userdata(name, userdata):
query = "INSERT INTO userdata (name, userdata) VALUES (%s, %s);"
args = (name, userdata)
cur.execute(query, args)
retmsg = {"message": 'Created userdata document "{}".'.format(name) }
retmsg = {"message": 'Created userdata document "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def update_userdata(name, userdata):
if list_userdata(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The userdata "{}" does not exist.'.format(name) }
retmsg = {'message': 'The userdata "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -636,17 +636,17 @@ def update_userdata(name, userdata):
query = "UPDATE userdata SET userdata = %s WHERE id = %s;"
args = (userdata, tid)
cur.execute(query, args)
retmsg = {"message": 'Updated userdata document "{}".'.format(name) }
retmsg = {"message": 'Updated userdata document "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to update entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to update entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_userdata(name):
if list_userdata(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The userdata "{}" does not exist.'.format(name) }
retmsg = {'message': 'The userdata "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -655,10 +655,10 @@ def delete_userdata(name):
query = "DELETE FROM userdata WHERE name = %s;"
args = (name,)
cur.execute(query, args)
retmsg = {"message": 'Removed userdata document "{}".'.format(name) }
retmsg = {"message": 'Removed userdata document "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
@ -692,11 +692,11 @@ def list_script(limit, is_fuzzy=True):
if data:
return data, 200
else:
return {'message': 'No scripts found.' }, 404
return {'message': 'No scripts found.'}, 404
def create_script(name, script):
if list_script(name, is_fuzzy=False)[-1] != 404:
retmsg = {'message': 'The script "{}" already exists.'.format(name) }
retmsg = {'message': 'The script "{}" already exists.'.format(name)}
retcode = 400
return retmsg, retcode
@ -705,17 +705,17 @@ def create_script(name, script):
query = "INSERT INTO script (name, script) VALUES (%s, %s);"
args = (name, script)
cur.execute(query, args)
retmsg = {"message": 'Created provisioning script "{}".'.format(name) }
retmsg = {"message": 'Created provisioning script "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def update_script(name, script):
if list_script(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The script "{}" does not exist.'.format(name) }
retmsg = {'message': 'The script "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -727,17 +727,17 @@ def update_script(name, script):
query = "UPDATE script SET script = %s WHERE id = %s;"
args = (script, tid)
cur.execute(query, args)
retmsg = {"message": 'Updated provisioning script "{}".'.format(name) }
retmsg = {"message": 'Updated provisioning script "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to update entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to update entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_script(name):
if list_script(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The script "{}" does not exist.'.format(name) }
retmsg = {'message': 'The script "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -746,10 +746,10 @@ def delete_script(name):
query = "DELETE FROM script WHERE name = %s;"
args = (name,)
cur.execute(query, args)
retmsg = {"message": 'Removed provisioning script "{}".'.format(name) }
retmsg = {"message": 'Removed provisioning script "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
@ -803,16 +803,16 @@ def list_profile(limit, is_fuzzy=True):
if data:
return data, 200
else:
return {'message': 'No profiles found.' }, 404
return {'message': 'No profiles found.'}, 404
def create_profile(name, profile_type, system_template, network_template, storage_template, userdata=None, script=None, ova=None, arguments=None):
if list_profile(name, is_fuzzy=False)[-1] != 404:
retmsg = {'message': 'The profile "{}" already exists.'.format(name) }
retmsg = {'message': 'The profile "{}" already exists.'.format(name)}
retcode = 400
return retmsg, retcode
if profile_type not in ['provisioner', 'ova']:
retmsg = {'message': 'A valid profile type (provisioner, ova) must be specified.' }
retmsg = {'message': 'A valid profile type (provisioner, ova) must be specified.'}
retcode = 400
return retmsg, retcode
@ -824,7 +824,7 @@ def create_profile(name, profile_type, system_template, network_template, storag
if template['name'] == system_template:
system_template_id = template['id']
if not system_template_id:
retmsg = {'message': 'The system template "{}" for profile "{}" does not exist.'.format(system_template, name) }
retmsg = {'message': 'The system template "{}" for profile "{}" does not exist.'.format(system_template, name)}
retcode = 400
return retmsg, retcode
@ -836,7 +836,7 @@ def create_profile(name, profile_type, system_template, network_template, storag
if template['name'] == network_template:
network_template_id = template['id']
if not network_template_id and profile_type != 'ova':
retmsg = {'message': 'The network template "{}" for profile "{}" does not exist.'.format(network_template, name) }
retmsg = {'message': 'The network template "{}" for profile "{}" does not exist.'.format(network_template, name)}
retcode = 400
return retmsg, retcode
@ -848,7 +848,7 @@ def create_profile(name, profile_type, system_template, network_template, storag
if template['name'] == storage_template:
storage_template_id = template['id']
if not storage_template_id and profile_type != 'ova':
retmsg = {'message': 'The storage template "{}" for profile "{}" does not exist.'.format(storage_template, name) }
retmsg = {'message': 'The storage template "{}" for profile "{}" does not exist.'.format(storage_template, name)}
retcode = 400
return retmsg, retcode
@ -886,17 +886,17 @@ def create_profile(name, profile_type, system_template, network_template, storag
query = "INSERT INTO profile (name, profile_type, system_template, network_template, storage_template, userdata, script, ova, arguments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s);"
args = (name, profile_type, system_template_id, network_template_id, storage_template_id, userdata_id, script_id, ova_id, arguments_formatted)
cur.execute(query, args)
retmsg = {"message": 'Created VM profile "{}".'.format(name) }
retmsg = {"message": 'Created VM profile "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to create entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def modify_profile(name, profile_type, system_template, network_template, storage_template, userdata, script, ova, arguments=None):
if list_profile(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The profile "{}" does not exist.'.format(name) }
retmsg = {'message': 'The profile "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -904,7 +904,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if profile_type is not None:
if profile_type not in ['provisioner', 'ova']:
retmsg = {'message': 'A valid profile type (provisioner, ova) must be specified.' }
retmsg = {'message': 'A valid profile type (provisioner, ova) must be specified.'}
retcode = 400
return retmsg, retcode
fields.append({'field': 'type', 'data': profile_type})
@ -916,7 +916,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if template['name'] == system_template:
system_template_id = template['id']
if not system_template_id:
retmsg = {'message': 'The system template "{}" for profile "{}" does not exist.'.format(system_template, name) }
retmsg = {'message': 'The system template "{}" for profile "{}" does not exist.'.format(system_template, name)}
retcode = 400
return retmsg, retcode
fields.append({'field': 'system_template', 'data': system_template_id})
@ -928,7 +928,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if template['name'] == network_template:
network_template_id = template['id']
if not network_template_id:
retmsg = {'message': 'The network template "{}" for profile "{}" does not exist.'.format(network_template, name) }
retmsg = {'message': 'The network template "{}" for profile "{}" does not exist.'.format(network_template, name)}
retcode = 400
return retmsg, retcode
fields.append({'field': 'network_template', 'data': network_template_id})
@ -940,7 +940,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if template['name'] == storage_template:
storage_template_id = template['id']
if not storage_template_id:
retmsg = {'message': 'The storage template "{}" for profile "{}" does not exist.'.format(storage_template, name) }
retmsg = {'message': 'The storage template "{}" for profile "{}" does not exist.'.format(storage_template, name)}
retcode = 400
return retmsg, retcode
fields.append({'field': 'storage_template', 'data': storage_template_id})
@ -952,7 +952,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if template['name'] == userdata:
userdata_id = template['id']
if not userdata_id:
retmsg = {'message': 'The userdata template "{}" for profile "{}" does not exist.'.format(userdata, name) }
retmsg = {'message': 'The userdata template "{}" for profile "{}" does not exist.'.format(userdata, name)}
retcode = 400
return retmsg, retcode
fields.append({'field': 'userdata', 'data': userdata_id})
@ -964,7 +964,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if scr['name'] == script:
script_id = scr['id']
if not script_id:
retmsg = {'message': 'The script "{}" for profile "{}" does not exist.'.format(script, name) }
retmsg = {'message': 'The script "{}" for profile "{}" does not exist.'.format(script, name)}
retcode = 400
return retmsg, retcode
fields.append({'field': 'script', 'data': script_id})
@ -976,7 +976,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
if ov['name'] == ova:
ova_id = ov['id']
if not ova_id:
retmsg = {'message': 'The OVA "{}" for profile "{}" does not exist.'.format(ova, name) }
retmsg = {'message': 'The OVA "{}" for profile "{}" does not exist.'.format(ova, name)}
retcode = 400
return retmsg, retcode
fields.append({'field': 'ova', 'data': ova_id})
@ -994,17 +994,17 @@ def modify_profile(name, profile_type, system_template, network_template, storag
query = "UPDATE profile SET {}=%s WHERE name=%s;".format(field.get('field'))
args = (field.get('data'), name)
cur.execute(query, args)
retmsg = {"message": 'Modified VM profile "{}".'.format(name) }
retmsg = {"message": 'Modified VM profile "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to modify entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to modify entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode
def delete_profile(name):
if list_profile(name, is_fuzzy=False)[-1] != 200:
retmsg = {'message': 'The profile "{}" does not exist.'.format(name) }
retmsg = {'message': 'The profile "{}" does not exist.'.format(name)}
retcode = 400
return retmsg, retcode
@ -1013,10 +1013,10 @@ def delete_profile(name):
query = "DELETE FROM profile WHERE name = %s;"
args = (name,)
cur.execute(query, args)
retmsg = {"message": 'Removed VM profile "{}".'.format(name) }
retmsg = {"message": 'Removed VM profile "{}".'.format(name)}
retcode = 200
except Exception as e:
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e) }
retmsg = {'message': 'Failed to delete entry "{}": {}'.format(name, e)}
retcode = 400
close_database(conn, cur)
return retmsg, retcode