Lint: E201 whitespace after '{'

This commit is contained in:
Joshua Boniface 2020-11-07 12:38:31 -05:00
parent 292ccdd94e
commit e333f2b935
18 changed files with 415 additions and 415 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

View File

@ -874,7 +874,7 @@ def ceph_volume_upload(config, pool, volume, image_format, image_file):
bar = UploadProgressBar(image_file, end_message="Parsing file on remote side...", end_nl=False)
upload_data = MultipartEncoder(
fields={ 'file': ('filename', open(image_file, 'rb'), 'application/octet-stream')}
fields={'file': ('filename', open(image_file, 'rb'), 'application/octet-stream')}
)
upload_monitor = MultipartEncoderMonitor(upload_data, bar.update)

View File

@ -432,7 +432,7 @@ def ova_upload(config, name, ova_file, params):
bar = UploadProgressBar(ova_file, end_message="Parsing file on remote side...", end_nl=False)
upload_data = MultipartEncoder(
fields={ 'file': ('filename', open(ova_file, 'rb'), 'application/octet-stream')}
fields={'file': ('filename', open(ova_file, 'rb'), 'application/octet-stream')}
)
upload_monitor = MultipartEncoderMonitor(upload_data, bar.update)

View File

@ -85,7 +85,7 @@ def get_config(store_data, cluster=None):
if os.path.isfile(cfgfile):
host, port, scheme, api_key = read_from_yaml(cfgfile)
else:
return { 'badcfg': True }
return {'badcfg': True }
# Handle an all-wildcard address
if host == '0.0.0.0':
host = '127.0.0.1'

View File

@ -144,8 +144,8 @@ def getClusterInformation(zk_conn):
except KeyError:
ceph_osd_in = 0
up_texts = { 1: 'up', 0: 'down' }
in_texts = { 1: 'in', 0: 'out' }
up_texts = {1: 'up', 0: 'down' }
in_texts = {1: 'in', 0: 'out' }
if not ceph_osd_up or not ceph_osd_in:
ceph_osd_healthy_status[index] = False

View File

@ -373,7 +373,7 @@ def getDomainControllers(parsed_xml):
controller_model = device.attrib.get('model')
except KeyError:
controller_model = 'none'
controller_obj = { 'type': controller_type, 'model': controller_model }
controller_obj = {'type': controller_type, 'model': controller_model }
dcontrollers.append(controller_obj)
return dcontrollers

View File

@ -274,7 +274,7 @@ def modify_vm(zk_conn, domain, restart, new_vm_config):
if restart:
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'restart' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'restart' })
lock.release()
return True, ''
@ -301,7 +301,7 @@ def undefine_vm(zk_conn, domain):
# Set the domain into stop mode
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'stop' })
lock.release()
# Wait for 2 seconds to allow state to flow to all nodes
@ -330,7 +330,7 @@ def remove_vm(zk_conn, domain):
# Set the domain into stop mode
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'stop' })
lock.release()
# Wait for 2 seconds to allow state to flow to all nodes
@ -364,7 +364,7 @@ def start_vm(zk_conn, domain):
# Set the VM to start
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'start' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'start' })
lock.release()
return True, 'Starting VM "{}".'.format(domain)
@ -385,7 +385,7 @@ def restart_vm(zk_conn, domain, wait=False):
# Set the VM to restart
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'restart' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'restart' })
lock.release()
if wait:
@ -411,7 +411,7 @@ def shutdown_vm(zk_conn, domain, wait=False):
# Set the VM to shutdown
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'shutdown' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'shutdown' })
lock.release()
if wait:
@ -430,7 +430,7 @@ def stop_vm(zk_conn, domain):
# Set the VM to start
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'stop' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'stop' })
lock.release()
return True, 'Forcibly stopping VM "{}".'.format(domain)
@ -449,7 +449,7 @@ def disable_vm(zk_conn, domain):
# Set the VM to start
lock = zkhandler.exclusivelock(zk_conn, '/domains/{}/state'.format(dom_uuid))
lock.acquire()
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'disable' })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(dom_uuid): 'disable' })
lock.release()
return True, 'Marked VM "{}" as disable.'.format(domain)

View File

@ -557,7 +557,7 @@ def cleanup():
logger.out('Terminating pvcnoded and cleaning up', state='s')
# Set shutdown state in Zookeeper
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(myhostname): 'shutdown' })
zkhandler.writedata(zk_conn, {'/nodes/{}/daemonstate'.format(myhostname): 'shutdown' })
# Waiting for any flushes to complete
logger.out('Waiting for any active flushes', state='s')
@ -599,7 +599,7 @@ def cleanup():
node_keepalive()
# Set stop state in Zookeeper
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(myhostname): 'stop' })
zkhandler.writedata(zk_conn, {'/nodes/{}/daemonstate'.format(myhostname): 'stop' })
# Forcibly terminate dnsmasq because it gets stuck sometimes
common.run_os_command('killall dnsmasq')
@ -690,7 +690,7 @@ if current_primary and current_primary != 'none':
else:
if config['daemon_mode'] == 'coordinator':
logger.out('No primary node found; creating with us as primary.', state='i')
zkhandler.writedata(zk_conn, { '/primary_node': myhostname })
zkhandler.writedata(zk_conn, {'/primary_node': myhostname })
###############################################################################
# PHASE 7a - Ensure IPMI is reachable and working
@ -742,8 +742,8 @@ if enable_networking:
flush ruleset
# Add the filter table and chains
add table inet filter
add chain inet filter forward {{ type filter hook forward priority 0; }}
add chain inet filter input {{ type filter hook input priority 0; }}
add chain inet filter forward {{type filter hook forward priority 0; }}
add chain inet filter input {{type filter hook input priority 0; }}
# Include static rules and network rules
include "{rulesdir}/static/*"
include "{rulesdir}/networks/*"
@ -1042,7 +1042,7 @@ def collect_ceph_stats(queue):
logger.out("Getting health stats from monitor", state='d', prefix='ceph-thread')
# Get Ceph cluster health for local status output
command = { "prefix": "health", "format": "json" }
command = {"prefix": "health", "format": "json" }
try:
health_status = json.loads(ceph_conn.mon_command(json.dumps(command), b'', timeout=1)[1])
ceph_health = health_status['status']
@ -1062,7 +1062,7 @@ def collect_ceph_stats(queue):
if debug:
logger.out("Set ceph health information in zookeeper (primary only)", state='d', prefix='ceph-thread')
command = { "prefix": "status", "format": "pretty" }
command = {"prefix": "status", "format": "pretty" }
ceph_status = ceph_conn.mon_command(json.dumps(command), b'', timeout=1)[1].decode('ascii')
try:
zkhandler.writedata(zk_conn, {
@ -1076,7 +1076,7 @@ def collect_ceph_stats(queue):
logger.out("Set ceph rados df information in zookeeper (primary only)", state='d', prefix='ceph-thread')
# Get rados df info
command = { "prefix": "df", "format": "pretty" }
command = {"prefix": "df", "format": "pretty" }
ceph_df = ceph_conn.mon_command(json.dumps(command), b'', timeout=1)[1].decode('ascii')
try:
zkhandler.writedata(zk_conn, {
@ -1090,7 +1090,7 @@ def collect_ceph_stats(queue):
logger.out("Set pool information in zookeeper (primary only)", state='d', prefix='ceph-thread')
# Get pool info
command = { "prefix": "df", "format": "json" }
command = {"prefix": "df", "format": "json" }
try:
ceph_pool_df_raw = json.loads(ceph_conn.mon_command(json.dumps(command), b'', timeout=1)[1])['pools']
except Exception as e:
@ -1161,7 +1161,7 @@ def collect_ceph_stats(queue):
# Parse the dump data
osd_dump = dict()
command = { "prefix": "osd dump", "format": "json" }
command = {"prefix": "osd dump", "format": "json" }
try:
retcode, stdout, stderr = common.run_os_command('ceph osd dump --format json --connect-timeout 2', timeout=2)
osd_dump_raw = json.loads(stdout)['osds']
@ -1187,7 +1187,7 @@ def collect_ceph_stats(queue):
osd_df = dict()
command = { "prefix": "osd df", "format": "json" }
command = {"prefix": "osd df", "format": "json" }
try:
osd_df_raw = json.loads(ceph_conn.mon_command(json.dumps(command), b'', timeout=1)[1])['nodes']
except Exception as e:
@ -1214,7 +1214,7 @@ def collect_ceph_stats(queue):
osd_status = dict()
command = { "prefix": "osd status", "format": "pretty" }
command = {"prefix": "osd status", "format": "pretty" }
try:
osd_status_raw = ceph_conn.mon_command(json.dumps(command), b'', timeout=1)[1].decode('ascii')
except Exception as e:
@ -1341,7 +1341,7 @@ def collect_vm_stats(queue):
raise
except Exception:
# Toggle a state "change"
zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(domain): instance.getstate() })
zkhandler.writedata(zk_conn, {'/domains/{}/state'.format(domain): instance.getstate() })
elif instance.getnode() == this_node.name:
memprov += instance.getmemory()
@ -1469,7 +1469,7 @@ def node_keepalive():
past_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(this_node.name))
if past_state != 'run':
this_node.daemon_state = 'run'
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(this_node.name): 'run' })
zkhandler.writedata(zk_conn, {'/nodes/{}/daemonstate'.format(this_node.name): 'run' })
else:
this_node.daemon_state = 'run'
@ -1638,7 +1638,7 @@ def node_keepalive():
fence_thread = Thread(target=fencing.fenceNode, args=(node_name, zk_conn, config, logger), kwargs={})
fence_thread.start()
# Write the updated data after we start the fence thread
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(node_name): 'dead' })
zkhandler.writedata(zk_conn, {'/nodes/{}/daemonstate'.format(node_name): 'dead' })
if debug:
logger.out("Keepalive finished", state='d', prefix='main-thread')

View File

@ -646,8 +646,8 @@ class NodeInstance(object):
if target_node is None:
self.logger.out('Failed to find migration target for VM "{}"; shutting down and setting autostart flag'.format(dom_uuid), state='e')
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(dom_uuid): 'shutdown' })
zkhandler.writedata(self.zk_conn, { '/domains/{}/node_autostart'.format(dom_uuid): 'True' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(dom_uuid): 'shutdown' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/node_autostart'.format(dom_uuid): 'True' })
else:
self.logger.out('Migrating VM "{}" to node "{}"'.format(dom_uuid, target_node), state='i')
zkhandler.writedata(self.zk_conn, {
@ -665,8 +665,8 @@ class NodeInstance(object):
break
time.sleep(0.2)
zkhandler.writedata(self.zk_conn, { '/nodes/{}/runningdomains'.format(self.name): '' })
zkhandler.writedata(self.zk_conn, { '/nodes/{}/domainstate'.format(self.name): 'flushed' })
zkhandler.writedata(self.zk_conn, {'/nodes/{}/runningdomains'.format(self.name): '' })
zkhandler.writedata(self.zk_conn, {'/nodes/{}/domainstate'.format(self.name): 'flushed' })
self.flush_thread = None
self.flush_stopper = False
return
@ -714,7 +714,7 @@ class NodeInstance(object):
while zkhandler.readdata(self.zk_conn, '/domains/{}/state'.format(dom_uuid)) in ['migrate', 'unmigrate', 'shutdown']:
time.sleep(0.1)
zkhandler.writedata(self.zk_conn, { '/nodes/{}/domainstate'.format(self.name): 'ready' })
zkhandler.writedata(self.zk_conn, {'/nodes/{}/domainstate'.format(self.name): 'ready' })
self.flush_thread = None
self.flush_stopper = False
return

View File

@ -86,7 +86,7 @@ class VMConsoleWatcherInstance(object):
self.fetch_lines()
# Update Zookeeper with the new loglines if they changed
if self.loglines != self.last_loglines:
zkhandler.writedata(self.zk_conn, { '/domains/{}/consolelog'.format(self.domuuid): self.loglines })
zkhandler.writedata(self.zk_conn, {'/domains/{}/consolelog'.format(self.domuuid): self.loglines })
self.last_loglines = self.loglines
def fetch_lines(self):

View File

@ -185,7 +185,7 @@ class VMInstance(object):
# Add the domain to the domain_list array
self.this_node.domain_list.append(self.domuuid)
# Push the change up to Zookeeper
zkhandler.writedata(self.zk_conn, { '/nodes/{}/runningdomains'.format(self.this_node.name): ' '.join(self.this_node.domain_list) })
zkhandler.writedata(self.zk_conn, {'/nodes/{}/runningdomains'.format(self.this_node.name): ' '.join(self.this_node.domain_list) })
except Exception as e:
self.logger.out('Error adding domain to list: {}'.format(e), state='e')
@ -195,7 +195,7 @@ class VMInstance(object):
# Remove the domain from the domain_list array
self.this_node.domain_list.remove(self.domuuid)
# Push the change up to Zookeeper
zkhandler.writedata(self.zk_conn, { '/nodes/{}/runningdomains'.format(self.this_node.name): ' '.join(self.this_node.domain_list) })
zkhandler.writedata(self.zk_conn, {'/nodes/{}/runningdomains'.format(self.this_node.name): ' '.join(self.this_node.domain_list) })
except Exception as e:
self.logger.out('Error removing domain from list: {}'.format(e), state='e')
@ -225,7 +225,7 @@ class VMInstance(object):
if curstate == libvirt.VIR_DOMAIN_RUNNING:
# If it is running just update the model
self.addDomainToList()
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): '' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/failedreason'.format(self.domuuid): '' })
else:
# Or try to create it
try:
@ -235,11 +235,11 @@ class VMInstance(object):
self.addDomainToList()
self.logger.out('Successfully started VM', state='o', prefix='Domain {}'.format(self.domuuid))
self.dom = dom
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): '' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/failedreason'.format(self.domuuid): '' })
except libvirt.libvirtError as e:
self.logger.out('Failed to create VM', state='e', prefix='Domain {}'.format(self.domuuid))
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'fail' })
zkhandler.writedata(self.zk_conn, { '/domains/{}/failedreason'.format(self.domuuid): str(e) })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'fail' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/failedreason'.format(self.domuuid): str(e) })
self.dom = None
lv_conn.close()
@ -264,7 +264,7 @@ class VMInstance(object):
self.start_vm()
self.addDomainToList()
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'start' })
lv_conn.close()
self.inrestart = False
@ -295,7 +295,7 @@ class VMInstance(object):
self.removeDomainFromList()
if self.inrestart is False:
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'stop' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'stop' })
self.logger.out('Successfully stopped VM', state='o', prefix='Domain {}'.format(self.domuuid))
self.dom = None
@ -329,7 +329,7 @@ class VMInstance(object):
if lvdomstate != libvirt.VIR_DOMAIN_RUNNING:
self.removeDomainFromList()
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'stop' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'stop' })
self.logger.out('Successfully shutdown VM', state='o', prefix='Domain {}'.format(self.domuuid))
self.dom = None
# Stop the log watcher
@ -338,7 +338,7 @@ class VMInstance(object):
if tick >= self.config['vm_shutdown_timeout']:
self.logger.out('Shutdown timeout ({}s) expired, forcing off'.format(self.config['vm_shutdown_timeout']), state='e', prefix='Domain {}'.format(self.domuuid))
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'stop' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'stop' })
break
self.inshutdown = False
@ -349,7 +349,7 @@ class VMInstance(object):
if self.inrestart:
# Wait to prevent race conditions
time.sleep(1)
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'start' })
# Migrate the VM to a target host
def migrate_vm(self, force_live=False, force_shutdown=False):
@ -458,7 +458,7 @@ class VMInstance(object):
def migrate_shutdown():
self.logger.out('Shutting down VM for offline migration', state='i', prefix='Domain {}'.format(self.domuuid))
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'shutdown' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'shutdown' })
while zkhandler.readdata(self.zk_conn, '/domains/{}/state'.format(self.domuuid)) != 'stop':
time.sleep(0.5)
return True
@ -551,7 +551,7 @@ class VMInstance(object):
self.logger.out('Receiving VM migration from node "{}"'.format(self.node), state='i', prefix='Domain {}'.format(self.domuuid))
# Ensure our lock key is populated
zkhandler.writedata(self.zk_conn, { '/locks/domain_migrate/{}'.format(self.domuuid): self.domuuid })
zkhandler.writedata(self.zk_conn, {'/locks/domain_migrate/{}'.format(self.domuuid): self.domuuid })
# Synchronize nodes A (I am writer)
lock = zkhandler.writelock(self.zk_conn, '/locks/domain_migrate/{}'.format(self.domuuid))
@ -601,11 +601,11 @@ class VMInstance(object):
if lvdomstate == libvirt.VIR_DOMAIN_RUNNING:
# VM has been received and started
self.addDomainToList()
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'start' })
self.logger.out('Successfully received migrated VM', state='o', prefix='Domain {}'.format(self.domuuid))
else:
# The receive somehow failed
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'fail' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'fail' })
else:
if self.node == self.this_node.name:
if self.state in ['start']:
@ -613,7 +613,7 @@ class VMInstance(object):
self.logger.out('Receive aborted via state change', state='w', prefix='Domain {}'.format(self.domuuid))
elif self.state in ['stop']:
# The send was shutdown-based
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'start' })
else:
# The send failed or was aborted
self.logger.out('Migrate aborted or failed; VM in state {}'.format(self.state), state='w', prefix='Domain {}'.format(self.domuuid))
@ -622,7 +622,7 @@ class VMInstance(object):
lock.release()
self.logger.out('Released write lock for synchronization phase D', state='o', prefix='Domain {}'.format(self.domuuid))
zkhandler.writedata(self.zk_conn, { '/locks/domain_migrate/{}'.format(self.domuuid): '' })
zkhandler.writedata(self.zk_conn, {'/locks/domain_migrate/{}'.format(self.domuuid): '' })
self.inreceive = False
return
@ -681,7 +681,7 @@ class VMInstance(object):
elif self.state == "migrate" or self.state == "migrate-live":
# Start the log watcher
self.console_log_instance.start()
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'start' })
# Add domain to running list
self.addDomainToList()
# VM should be restarted
@ -704,7 +704,7 @@ class VMInstance(object):
self.receive_migrate()
# VM should be restarted (i.e. started since it isn't running)
if self.state == "restart":
zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' })
zkhandler.writedata(self.zk_conn, {'/domains/{}/state'.format(self.domuuid): 'start' })
# VM should be shut down; ensure it's gone from this node's domain_list
elif self.state == "shutdown":
self.removeDomainFromList()

View File

@ -144,7 +144,7 @@ def findTargetNode(zk_conn, config, logger, dom_uuid):
node_limit = ''
except Exception:
node_limit = ''
zkhandler.writedata(zk_conn, { '/domains/{}/node_limit'.format(dom_uuid): '' })
zkhandler.writedata(zk_conn, {'/domains/{}/node_limit'.format(dom_uuid): '' })
# Determine VM search field
try:
@ -155,7 +155,7 @@ def findTargetNode(zk_conn, config, logger, dom_uuid):
# If our search field is invalid, use and set the default (for next time)
if search_field is None or search_field == 'None':
search_field = config['migration_target_selector']
zkhandler.writedata(zk_conn, { '/domains/{}/node_selector'.format(dom_uuid): config['migration_target_selector'] })
zkhandler.writedata(zk_conn, {'/domains/{}/node_selector'.format(dom_uuid): config['migration_target_selector'] })
if config['debug']:
logger.out('Migrating VM {} with selector {}'.format(dom_uuid, search_field), state='d', prefix='node-flush')

View File

@ -62,9 +62,9 @@ def fenceNode(node_name, zk_conn, config, logger):
# Force into secondary network state if needed
if node_name in config['coordinators']:
logger.out('Forcing secondary status for node "{}"'.format(node_name), state='i')
zkhandler.writedata(zk_conn, { '/nodes/{}/routerstate'.format(node_name): 'secondary' })
zkhandler.writedata(zk_conn, {'/nodes/{}/routerstate'.format(node_name): 'secondary' })
if zkhandler.readdata(zk_conn, '/primary_node') == node_name:
zkhandler.writedata(zk_conn, { '/primary_node': 'none' })
zkhandler.writedata(zk_conn, {'/primary_node': 'none' })
# If the fence succeeded and successful_fence is migrate
if fence_status and config['successful_fence'] == 'migrate':
@ -82,7 +82,7 @@ def migrateFromFencedNode(zk_conn, node_name, config, logger):
dead_node_running_domains = zkhandler.readdata(zk_conn, '/nodes/{}/runningdomains'.format(node_name)).split()
# Set the node to a custom domainstate so we know what's happening
zkhandler.writedata(zk_conn, { '/nodes/{}/domainstate'.format(node_name): 'fence-flush' })
zkhandler.writedata(zk_conn, {'/nodes/{}/domainstate'.format(node_name): 'fence-flush' })
# Migrate a VM after a flush
def fence_migrate_vm(dom_uuid):
@ -109,7 +109,7 @@ def migrateFromFencedNode(zk_conn, node_name, config, logger):
fence_migrate_vm(dom_uuid)
# Set node in flushed state for easy remigrating when it comes back
zkhandler.writedata(zk_conn, { '/nodes/{}/domainstate'.format(node_name): 'flushed' })
zkhandler.writedata(zk_conn, {'/nodes/{}/domainstate'.format(node_name): 'flushed' })
#
# Perform an IPMI fence

View File

@ -44,25 +44,25 @@ class Logger(object):
# Format maps
format_map_colourized = {
# Colourized formatting with chevron prompts (log_colours = True)
'o': { 'colour': fmt_green, 'prompt': '>>> ' },
'e': { 'colour': fmt_red, 'prompt': '>>> ' },
'w': { 'colour': fmt_yellow, 'prompt': '>>> ' },
't': { 'colour': fmt_purple, 'prompt': '>>> ' },
'i': { 'colour': fmt_blue, 'prompt': '>>> ' },
's': { 'colour': fmt_cyan, 'prompt': '>>> ' },
'd': { 'colour': fmt_white, 'prompt': '>>> ' },
'x': { 'colour': last_colour, 'prompt': last_prompt }
'o': {'colour': fmt_green, 'prompt': '>>> ' },
'e': {'colour': fmt_red, 'prompt': '>>> ' },
'w': {'colour': fmt_yellow, 'prompt': '>>> ' },
't': {'colour': fmt_purple, 'prompt': '>>> ' },
'i': {'colour': fmt_blue, 'prompt': '>>> ' },
's': {'colour': fmt_cyan, 'prompt': '>>> ' },
'd': {'colour': fmt_white, 'prompt': '>>> ' },
'x': {'colour': last_colour, 'prompt': last_prompt }
}
format_map_textual = {
# Uncolourized formatting with text prompts (log_colours = False)
'o': { 'colour': '', 'prompt': 'ok: ' },
'e': { 'colour': '', 'prompt': 'failed: ' },
'w': { 'colour': '', 'prompt': 'warning: ' },
't': { 'colour': '', 'prompt': 'tick: ' },
'i': { 'colour': '', 'prompt': 'info: ' },
's': { 'colour': '', 'prompt': 'system: ' },
'd': { 'colour': '', 'prompt': 'debug: ' },
'x': { 'colour': '', 'prompt': last_prompt }
'o': {'colour': '', 'prompt': 'ok: ' },
'e': {'colour': '', 'prompt': 'failed: ' },
'w': {'colour': '', 'prompt': 'warning: ' },
't': {'colour': '', 'prompt': 'tick: ' },
'i': {'colour': '', 'prompt': 'info: ' },
's': {'colour': '', 'prompt': 'system: ' },
'd': {'colour': '', 'prompt': 'debug: ' },
'x': {'colour': '', 'prompt': last_prompt }
}
# Initialization of instance