Convert node.py to new ZK schema handler
This commit is contained in:
parent
0a162b304a
commit
f6e37906a9
|
@ -29,23 +29,23 @@ def getNodeInformation(zkhandler, node_name):
|
|||
"""
|
||||
Gather information about a node from the Zookeeper database and return a dict() containing it.
|
||||
"""
|
||||
node_daemon_state = zkhandler.read('/nodes/{}/daemonstate'.format(node_name))
|
||||
node_coordinator_state = zkhandler.read('/nodes/{}/routerstate'.format(node_name))
|
||||
node_domain_state = zkhandler.read('/nodes/{}/domainstate'.format(node_name))
|
||||
node_static_data = zkhandler.read('/nodes/{}/staticdata'.format(node_name)).split()
|
||||
node_daemon_state = zkhandler.read(('node.state.daemon', node_name))
|
||||
node_coordinator_state = zkhandler.read(('node.state.router', node_name))
|
||||
node_domain_state = zkhandler.read(('node.state.domain', node_name))
|
||||
node_static_data = zkhandler.read(('node.data.static', node_name)).split()
|
||||
node_cpu_count = int(node_static_data[0])
|
||||
node_kernel = node_static_data[1]
|
||||
node_os = node_static_data[2]
|
||||
node_arch = node_static_data[3]
|
||||
node_vcpu_allocated = int(zkhandler.read('/nodes/{}/vcpualloc'.format(node_name)))
|
||||
node_mem_total = int(zkhandler.read('/nodes/{}/memtotal'.format(node_name)))
|
||||
node_mem_allocated = int(zkhandler.read('/nodes/{}/memalloc'.format(node_name)))
|
||||
node_mem_provisioned = int(zkhandler.read('/nodes/{}/memprov'.format(node_name)))
|
||||
node_mem_used = int(zkhandler.read('/nodes/{}/memused'.format(node_name)))
|
||||
node_mem_free = int(zkhandler.read('/nodes/{}/memfree'.format(node_name)))
|
||||
node_load = float(zkhandler.read('/nodes/{}/cpuload'.format(node_name)))
|
||||
node_domains_count = int(zkhandler.read('/nodes/{}/domainscount'.format(node_name)))
|
||||
node_running_domains = zkhandler.read('/nodes/{}/runningdomains'.format(node_name)).split()
|
||||
node_vcpu_allocated = int(zkhandler.read(('node.vcpu.allocated', node_name)))
|
||||
node_mem_total = int(zkhandler.read(('node.memory.total', node_name)))
|
||||
node_mem_allocated = int(zkhandler.read(('node.memory.allocated', node_name)))
|
||||
node_mem_provisioned = int(zkhandler.read(('node.memory.provisioned', node_name)))
|
||||
node_mem_used = int(zkhandler.read(('node.memory.used', node_name)))
|
||||
node_mem_free = int(zkhandler.read(('node.memory.free', node_name)))
|
||||
node_load = float(zkhandler.read(('node.cpu.load', node_name)))
|
||||
node_domains_count = int(zkhandler.read(('node.count.provisioned_domains', node_name)))
|
||||
node_running_domains = zkhandler.read(('node.running_domains', node_name)).split()
|
||||
|
||||
# Construct a data structure to represent the data
|
||||
node_information = {
|
||||
|
@ -84,23 +84,23 @@ def secondary_node(zkhandler, node):
|
|||
return False, 'ERROR: No node named "{}" is present in the cluster.'.format(node)
|
||||
|
||||
# Ensure node is a coordinator
|
||||
daemon_mode = zkhandler.read('/nodes/{}/daemonmode'.format(node))
|
||||
daemon_mode = zkhandler.read(('node.mode', node))
|
||||
if daemon_mode == 'hypervisor':
|
||||
return False, 'ERROR: Cannot change router mode on non-coordinator node "{}"'.format(node)
|
||||
|
||||
# Ensure node is in run daemonstate
|
||||
daemon_state = zkhandler.read('/nodes/{}/daemonstate'.format(node))
|
||||
daemon_state = zkhandler.read(('node.state.daemon', node))
|
||||
if daemon_state != 'run':
|
||||
return False, 'ERROR: Node "{}" is not active'.format(node)
|
||||
|
||||
# Get current state
|
||||
current_state = zkhandler.read('/nodes/{}/routerstate'.format(node))
|
||||
current_state = zkhandler.read(('node.state.router', node))
|
||||
if current_state == 'secondary':
|
||||
return True, 'Node "{}" is already in secondary router mode.'.format(node)
|
||||
|
||||
retmsg = 'Setting node {} in secondary router mode.'.format(node)
|
||||
zkhandler.write([
|
||||
('/config/primary_node', 'none')
|
||||
('base.config.primary_node', 'none')
|
||||
])
|
||||
|
||||
return True, retmsg
|
||||
|
@ -112,23 +112,23 @@ def primary_node(zkhandler, node):
|
|||
return False, 'ERROR: No node named "{}" is present in the cluster.'.format(node)
|
||||
|
||||
# Ensure node is a coordinator
|
||||
daemon_mode = zkhandler.read('/nodes/{}/daemonmode'.format(node))
|
||||
daemon_mode = zkhandler.read(('node.mode', node))
|
||||
if daemon_mode == 'hypervisor':
|
||||
return False, 'ERROR: Cannot change router mode on non-coordinator node "{}"'.format(node)
|
||||
|
||||
# Ensure node is in run daemonstate
|
||||
daemon_state = zkhandler.read('/nodes/{}/daemonstate'.format(node))
|
||||
daemon_state = zkhandler.read(('node.state.daemon', node))
|
||||
if daemon_state != 'run':
|
||||
return False, 'ERROR: Node "{}" is not active'.format(node)
|
||||
|
||||
# Get current state
|
||||
current_state = zkhandler.read('/nodes/{}/routerstate'.format(node))
|
||||
current_state = zkhandler.read(('node.state.router', node))
|
||||
if current_state == 'primary':
|
||||
return True, 'Node "{}" is already in primary router mode.'.format(node)
|
||||
|
||||
retmsg = 'Setting node {} in primary router mode.'.format(node)
|
||||
zkhandler.write([
|
||||
('/config/primary_node', node)
|
||||
('base.config.primary_node', node)
|
||||
])
|
||||
|
||||
return True, retmsg
|
||||
|
@ -139,18 +139,18 @@ def flush_node(zkhandler, node, wait=False):
|
|||
if not common.verifyNode(zkhandler, node):
|
||||
return False, 'ERROR: No node named "{}" is present in the cluster.'.format(node)
|
||||
|
||||
if zkhandler.read('/nodes/{}/domainstate'.format(node)) == 'flushed':
|
||||
if zkhandler.read(('node.state.domain', node)) == 'flushed':
|
||||
return True, 'Hypervisor {} is already flushed.'.format(node)
|
||||
|
||||
retmsg = 'Flushing hypervisor {} of running VMs.'.format(node)
|
||||
|
||||
# Add the new domain to Zookeeper
|
||||
zkhandler.write([
|
||||
('/nodes/{}/domainstate'.format(node), 'flush')
|
||||
(('node.state.domain', node), 'flush')
|
||||
])
|
||||
|
||||
if wait:
|
||||
while zkhandler.read('/nodes/{}/domainstate'.format(node)) == 'flush':
|
||||
while zkhandler.read(('node.state.domain', node)) == 'flush':
|
||||
time.sleep(1)
|
||||
retmsg = 'Flushed hypervisor {} of running VMs.'.format(node)
|
||||
|
||||
|
@ -162,18 +162,18 @@ def ready_node(zkhandler, node, wait=False):
|
|||
if not common.verifyNode(zkhandler, node):
|
||||
return False, 'ERROR: No node named "{}" is present in the cluster.'.format(node)
|
||||
|
||||
if zkhandler.read('/nodes/{}/domainstate'.format(node)) == 'ready':
|
||||
if zkhandler.read(('node.state.domain', node)) == 'ready':
|
||||
return True, 'Hypervisor {} is already ready.'.format(node)
|
||||
|
||||
retmsg = 'Restoring hypervisor {} to active service.'.format(node)
|
||||
|
||||
# Add the new domain to Zookeeper
|
||||
zkhandler.write([
|
||||
('/nodes/{}/domainstate'.format(node), 'unflush')
|
||||
(('node.state.domain', node), 'unflush')
|
||||
])
|
||||
|
||||
if wait:
|
||||
while zkhandler.read('/nodes/{}/domainstate'.format(node)) == 'unflush':
|
||||
while zkhandler.read(('node.state.domain', node)) == 'unflush':
|
||||
time.sleep(1)
|
||||
retmsg = 'Restored hypervisor {} to active service.'.format(node)
|
||||
|
||||
|
@ -195,7 +195,7 @@ def get_info(zkhandler, node):
|
|||
|
||||
def get_list(zkhandler, limit, daemon_state=None, coordinator_state=None, domain_state=None, is_fuzzy=True):
|
||||
node_list = []
|
||||
full_node_list = zkhandler.children('/nodes')
|
||||
full_node_list = zkhandler.children('base.node')
|
||||
|
||||
for node in full_node_list:
|
||||
if limit:
|
||||
|
|
Loading…
Reference in New Issue