Properly verify node inputs

This commit is contained in:
Joshua Boniface 2019-06-24 13:25:24 -04:00
parent 464c69aac6
commit 93be983b39
1 changed files with 20 additions and 10 deletions

View File

@ -168,9 +168,11 @@ def define_vm(zk_conn, config_data, target_node, selector):
if target_node == None: if target_node == None:
target_node = common.findTargetNode(zk_conn, selector, dom_uuid) target_node = common.findTargetNode(zk_conn, selector, dom_uuid)
else:
# Verify node is valid # Verify node is valid
common.verifyNode(zk_conn, target_node) valid_node = common.verifyNode(zk_conn, target_node)
if not valid_node:
return False, "Specified node {} is invalid.".format(target_node)
# Add the new domain to Zookeeper # Add the new domain to Zookeeper
zkhandler.writedata(zk_conn, { zkhandler.writedata(zk_conn, {
@ -328,13 +330,16 @@ def move_vm(zk_conn, domain, target_node, selector):
if target_node == None: if target_node == None:
target_node = common.findTargetNode(zk_conn, selector, dom_uuid) target_node = common.findTargetNode(zk_conn, selector, dom_uuid)
else: else:
# Verify node is valid
valid_node = common.verifyNode(zk_conn, target_node)
if not valid_node:
return False, "Specified node {} is invalid.".format(target_node)
# Verify if node is current node
if target_node == current_node: if target_node == current_node:
common.stopZKConnection(zk_conn) common.stopZKConnection(zk_conn)
return False, 'ERROR: VM "{}" is already running on node "{}".'.format(dom_uuid, current_node) return False, 'ERROR: VM "{}" is already running on node "{}".'.format(dom_uuid, current_node)
# Verify node is valid
common.verifyNode(zk_conn, target_node)
current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid)) current_vm_state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid))
if current_vm_state == 'start': if current_vm_state == 'start':
zkhandler.writedata(zk_conn, { zkhandler.writedata(zk_conn, {
@ -380,13 +385,16 @@ def migrate_vm(zk_conn, domain, target_node, selector, force_migrate, is_cli=Fal
if target_node == None: if target_node == None:
target_node = common.findTargetNode(zk_conn, selector, dom_uuid) target_node = common.findTargetNode(zk_conn, selector, dom_uuid)
else: else:
# Verify node is valid
valid_node = common.verifyNode(zk_conn, target_node)
if not valid_node:
return False, "Specified node {} is invalid.".format(target_node)
# Verify if node is current node
if target_node == current_node: if target_node == current_node:
common.stopZKConnection(zk_conn) common.stopZKConnection(zk_conn)
return False, 'ERROR: VM "{}" is already running on node "{}".'.format(dom_uuid, current_node) return False, 'ERROR: VM "{}" is already running on node "{}".'.format(dom_uuid, current_node)
# Verify node is valid
common.verifyNode(zk_conn, target_node)
zkhandler.writedata(zk_conn, { zkhandler.writedata(zk_conn, {
'/domains/{}/state'.format(dom_uuid): 'migrate', '/domains/{}/state'.format(dom_uuid): 'migrate',
'/domains/{}/node'.format(dom_uuid): target_node, '/domains/{}/node'.format(dom_uuid): target_node,
@ -506,7 +514,9 @@ def get_info(zk_conn, domain):
def get_list(zk_conn, node, state, limit): def get_list(zk_conn, node, state, limit):
if node != None: if node != None:
# Verify node is valid # Verify node is valid
common.verifyNode(zk_conn, node) valid_node = common.verifyNode(zk_conn, target_node)
if not valid_node:
return False, "Specified node {} is invalid.".format(target_node)
if state != None: if state != None:
valid_states = [ 'start', 'restart', 'shutdown', 'stop', 'failed', 'migrate', 'unmigrate' ] valid_states = [ 'start', 'restart', 'shutdown', 'stop', 'failed', 'migrate', 'unmigrate' ]