Lint: E302 expected 2 blank lines, found X
This commit is contained in:
@ -31,6 +31,7 @@ import daemon_lib.ansiprint as ansiprint
|
||||
import daemon_lib.zkhandler as zkhandler
|
||||
import daemon_lib.common as common
|
||||
|
||||
|
||||
#
|
||||
# Supplemental functions
|
||||
#
|
||||
@ -42,6 +43,7 @@ def verifyOSD(zk_conn, osd_id):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Verify Pool is valid in cluster
|
||||
def verifyPool(zk_conn, name):
|
||||
if zkhandler.exists(zk_conn, '/ceph/pools/{}'.format(name)):
|
||||
@ -49,6 +51,7 @@ def verifyPool(zk_conn, name):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Verify Volume is valid in cluster
|
||||
def verifyVolume(zk_conn, pool, name):
|
||||
if zkhandler.exists(zk_conn, '/ceph/volumes/{}/{}'.format(pool, name)):
|
||||
@ -56,6 +59,7 @@ def verifyVolume(zk_conn, pool, name):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Verify Snapshot is valid in cluster
|
||||
def verifySnapshot(zk_conn, pool, volume, name):
|
||||
if zkhandler.exists(zk_conn, '/ceph/snapshots/{}/{}/{}'.format(pool, volume, name)):
|
||||
@ -63,6 +67,7 @@ def verifySnapshot(zk_conn, pool, volume, name):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Verify OSD path is valid in cluster
|
||||
def verifyOSDBlock(zk_conn, node, device):
|
||||
for osd in zkhandler.listchildren(zk_conn, '/ceph/osds'):
|
||||
@ -73,7 +78,7 @@ def verifyOSDBlock(zk_conn, node, device):
|
||||
return None
|
||||
|
||||
|
||||
# Format byte sizes to/from human-readable units
|
||||
# Matrix of human-to-byte values
|
||||
byte_unit_matrix = {
|
||||
'B': 1,
|
||||
'K': 1024,
|
||||
@ -82,6 +87,19 @@ byte_unit_matrix = {
|
||||
'T': 1024*1024*1024*1024,
|
||||
'P': 1024*1024*1024*1024*1024
|
||||
}
|
||||
|
||||
# Matrix of human-to-metric values
|
||||
ops_unit_matrix = {
|
||||
'': 1,
|
||||
'K': 1000,
|
||||
'M': 1000*1000,
|
||||
'G': 1000*1000*1000,
|
||||
'T': 1000*1000*1000*1000,
|
||||
'P': 1000*1000*1000*1000*1000
|
||||
}
|
||||
|
||||
|
||||
# Format byte sizes to/from human-readable units
|
||||
def format_bytes_tohuman(databytes):
|
||||
datahuman = ''
|
||||
for unit in sorted(byte_unit_matrix, key=byte_unit_matrix.get, reverse=True):
|
||||
@ -96,6 +114,7 @@ def format_bytes_tohuman(databytes):
|
||||
|
||||
return datahuman
|
||||
|
||||
|
||||
def format_bytes_fromhuman(datahuman):
|
||||
# Trim off human-readable character
|
||||
dataunit = str(datahuman)[-1]
|
||||
@ -108,14 +127,6 @@ def format_bytes_fromhuman(datahuman):
|
||||
|
||||
|
||||
# Format ops sizes to/from human-readable units
|
||||
ops_unit_matrix = {
|
||||
'': 1,
|
||||
'K': 1000,
|
||||
'M': 1000*1000,
|
||||
'G': 1000*1000*1000,
|
||||
'T': 1000*1000*1000*1000,
|
||||
'P': 1000*1000*1000*1000*1000
|
||||
}
|
||||
def format_ops_tohuman(dataops):
|
||||
datahuman = ''
|
||||
for unit in sorted(ops_unit_matrix, key=ops_unit_matrix.get, reverse=True):
|
||||
@ -130,6 +141,7 @@ def format_ops_tohuman(dataops):
|
||||
|
||||
return datahuman
|
||||
|
||||
|
||||
def format_ops_fromhuman(datahuman):
|
||||
# Trim off human-readable character
|
||||
dataunit = datahuman[-1]
|
||||
@ -137,10 +149,12 @@ def format_ops_fromhuman(datahuman):
|
||||
dataops = datasize * ops_unit_matrix[dataunit]
|
||||
return '{}'.format(dataops)
|
||||
|
||||
|
||||
def format_pct_tohuman(datapct):
|
||||
datahuman = "{0:.1f}".format(float(datapct * 100.0))
|
||||
return datahuman
|
||||
|
||||
|
||||
#
|
||||
# Status functions
|
||||
#
|
||||
@ -156,6 +170,7 @@ def get_status(zk_conn):
|
||||
}
|
||||
return True, status_data
|
||||
|
||||
|
||||
def get_util(zk_conn):
|
||||
primary_node = zkhandler.readdata(zk_conn, '/primary_node')
|
||||
ceph_df = zkhandler.readdata(zk_conn, '/ceph/util').rstrip()
|
||||
@ -177,6 +192,7 @@ def getClusterOSDList(zk_conn):
|
||||
osd_list = zkhandler.listchildren(zk_conn, '/ceph/osds')
|
||||
return osd_list
|
||||
|
||||
|
||||
def getOSDInformation(zk_conn, osd_id):
|
||||
# Parse the stats data
|
||||
osd_stats_raw = zkhandler.readdata(zk_conn, '/ceph/osds/{}/stats'.format(osd_id))
|
||||
@ -188,6 +204,7 @@ def getOSDInformation(zk_conn, osd_id):
|
||||
}
|
||||
return osd_information
|
||||
|
||||
|
||||
def getOutputColoursOSD(osd_information):
|
||||
# Set the UP status
|
||||
if osd_information['stats']['up'] == 1:
|
||||
@ -207,6 +224,7 @@ def getOutputColoursOSD(osd_information):
|
||||
|
||||
return osd_up_flag, osd_up_colour, osd_in_flag, osd_in_colour
|
||||
|
||||
|
||||
# OSD addition and removal uses the /cmd/ceph pipe
|
||||
# These actions must occur on the specific node they reference
|
||||
def add_osd(zk_conn, node, device, weight):
|
||||
@ -247,6 +265,7 @@ def add_osd(zk_conn, node, device, weight):
|
||||
|
||||
return success, message
|
||||
|
||||
|
||||
def remove_osd(zk_conn, osd_id):
|
||||
if not verifyOSD(zk_conn, osd_id):
|
||||
return False, 'ERROR: No OSD with ID "{}" is present in the cluster.'.format(osd_id)
|
||||
@ -279,6 +298,7 @@ def remove_osd(zk_conn, osd_id):
|
||||
|
||||
return success, message
|
||||
|
||||
|
||||
def in_osd(zk_conn, osd_id):
|
||||
if not verifyOSD(zk_conn, osd_id):
|
||||
return False, 'ERROR: No OSD with ID "{}" is present in the cluster.'.format(osd_id)
|
||||
@ -289,6 +309,7 @@ def in_osd(zk_conn, osd_id):
|
||||
|
||||
return True, 'Set OSD {} online.'.format(osd_id)
|
||||
|
||||
|
||||
def out_osd(zk_conn, osd_id):
|
||||
if not verifyOSD(zk_conn, osd_id):
|
||||
return False, 'ERROR: No OSD with ID "{}" is present in the cluster.'.format(osd_id)
|
||||
@ -299,6 +320,7 @@ def out_osd(zk_conn, osd_id):
|
||||
|
||||
return True, 'Set OSD {} offline.'.format(osd_id)
|
||||
|
||||
|
||||
def set_osd(zk_conn, option):
|
||||
retcode, stdout, stderr = common.run_os_command('ceph osd set {}'.format(option))
|
||||
if retcode:
|
||||
@ -306,6 +328,7 @@ def set_osd(zk_conn, option):
|
||||
|
||||
return True, 'Set OSD property "{}".'.format(option)
|
||||
|
||||
|
||||
def unset_osd(zk_conn, option):
|
||||
retcode, stdout, stderr = common.run_os_command('ceph osd unset {}'.format(option))
|
||||
if retcode:
|
||||
@ -313,6 +336,7 @@ def unset_osd(zk_conn, option):
|
||||
|
||||
return True, 'Unset OSD property "{}".'.format(option)
|
||||
|
||||
|
||||
def get_list_osd(zk_conn, limit, is_fuzzy=True):
|
||||
osd_list = []
|
||||
full_osd_list = zkhandler.listchildren(zk_conn, '/ceph/osds')
|
||||
@ -351,6 +375,7 @@ def getPoolInformation(zk_conn, pool):
|
||||
}
|
||||
return pool_information
|
||||
|
||||
|
||||
def add_pool(zk_conn, name, pgs, replcfg):
|
||||
# Prepare the copies/mincopies variables
|
||||
try:
|
||||
@ -393,6 +418,7 @@ def add_pool(zk_conn, name, pgs, replcfg):
|
||||
|
||||
return True, 'Created RBD pool "{}" with {} PGs'.format(name, pgs)
|
||||
|
||||
|
||||
def remove_pool(zk_conn, name):
|
||||
if not verifyPool(zk_conn, name):
|
||||
return False, 'ERROR: No pool with name "{}" is present in the cluster.'.format(name)
|
||||
@ -413,6 +439,7 @@ def remove_pool(zk_conn, name):
|
||||
|
||||
return True, 'Removed RBD pool "{}" and all volumes.'.format(name)
|
||||
|
||||
|
||||
def get_list_pool(zk_conn, limit, is_fuzzy=True):
|
||||
pool_list = []
|
||||
full_pool_list = zkhandler.listchildren(zk_conn, '/ceph/pools')
|
||||
@ -450,6 +477,7 @@ def getCephVolumes(zk_conn, pool):
|
||||
|
||||
return volume_list
|
||||
|
||||
|
||||
def getVolumeInformation(zk_conn, pool, volume):
|
||||
# Parse the stats data
|
||||
volume_stats_raw = zkhandler.readdata(zk_conn, '/ceph/volumes/{}/{}/stats'.format(pool, volume))
|
||||
@ -464,6 +492,7 @@ def getVolumeInformation(zk_conn, pool, volume):
|
||||
}
|
||||
return volume_information
|
||||
|
||||
|
||||
def add_volume(zk_conn, pool, name, size):
|
||||
# 1. Create the volume
|
||||
retcode, stdout, stderr = common.run_os_command('rbd create --size {} --image-feature layering,exclusive-lock {}/{}'.format(size, pool, name))
|
||||
@ -483,6 +512,7 @@ def add_volume(zk_conn, pool, name, size):
|
||||
|
||||
return True, 'Created RBD volume "{}/{}" ({}).'.format(pool, name, size)
|
||||
|
||||
|
||||
def clone_volume(zk_conn, pool, name_src, name_new):
|
||||
if not verifyVolume(zk_conn, pool, name_src):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(name_src, pool)
|
||||
@ -505,6 +535,7 @@ def clone_volume(zk_conn, pool, name_src, name_new):
|
||||
|
||||
return True, 'Cloned RBD volume "{}" to "{}" in pool "{}"'.format(name_src, name_new, pool)
|
||||
|
||||
|
||||
def resize_volume(zk_conn, pool, name, size):
|
||||
if not verifyVolume(zk_conn, pool, name):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(name, pool)
|
||||
@ -551,6 +582,7 @@ def resize_volume(zk_conn, pool, name, size):
|
||||
|
||||
return True, 'Resized RBD volume "{}" to size "{}" in pool "{}".'.format(name, size, pool)
|
||||
|
||||
|
||||
def rename_volume(zk_conn, pool, name, new_name):
|
||||
if not verifyVolume(zk_conn, pool, name):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(name, pool)
|
||||
@ -577,6 +609,7 @@ def rename_volume(zk_conn, pool, name, new_name):
|
||||
|
||||
return True, 'Renamed RBD volume "{}" to "{}" in pool "{}".'.format(name, new_name, pool)
|
||||
|
||||
|
||||
def remove_volume(zk_conn, pool, name):
|
||||
if not verifyVolume(zk_conn, pool, name):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(name, pool)
|
||||
@ -596,6 +629,7 @@ def remove_volume(zk_conn, pool, name):
|
||||
|
||||
return True, 'Removed RBD volume "{}" in pool "{}".'.format(name, pool)
|
||||
|
||||
|
||||
def map_volume(zk_conn, pool, name):
|
||||
if not verifyVolume(zk_conn, pool, name):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(name, pool)
|
||||
@ -614,6 +648,7 @@ def map_volume(zk_conn, pool, name):
|
||||
|
||||
return True, mapped_volume
|
||||
|
||||
|
||||
def unmap_volume(zk_conn, pool, name):
|
||||
if not verifyVolume(zk_conn, pool, name):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(name, pool)
|
||||
@ -631,6 +666,7 @@ def unmap_volume(zk_conn, pool, name):
|
||||
|
||||
return True, 'Unmapped RBD volume at "{}".'.format(mapped_volume)
|
||||
|
||||
|
||||
def get_list_volume(zk_conn, pool, limit, is_fuzzy=True):
|
||||
volume_list = []
|
||||
if pool and not verifyPool(zk_conn, pool):
|
||||
@ -665,7 +701,6 @@ def get_list_volume(zk_conn, pool, limit, is_fuzzy=True):
|
||||
#
|
||||
# Snapshot functions
|
||||
#
|
||||
|
||||
def getCephSnapshots(zk_conn, pool, volume):
|
||||
snapshot_list = list()
|
||||
volume_list = list()
|
||||
@ -683,6 +718,7 @@ def getCephSnapshots(zk_conn, pool, volume):
|
||||
|
||||
return snapshot_list
|
||||
|
||||
|
||||
def add_snapshot(zk_conn, pool, volume, name):
|
||||
if not verifyVolume(zk_conn, pool, volume):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(volume, pool)
|
||||
@ -700,6 +736,7 @@ def add_snapshot(zk_conn, pool, volume, name):
|
||||
|
||||
return True, 'Created RBD snapshot "{}" of volume "{}" in pool "{}".'.format(name, volume, pool)
|
||||
|
||||
|
||||
def rename_snapshot(zk_conn, pool, volume, name, new_name):
|
||||
if not verifyVolume(zk_conn, pool, volume):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(volume, pool)
|
||||
@ -718,6 +755,7 @@ def rename_snapshot(zk_conn, pool, volume, name, new_name):
|
||||
|
||||
return True, 'Renamed RBD snapshot "{}" to "{}" for volume "{}" in pool "{}".'.format(name, new_name, volume, pool)
|
||||
|
||||
|
||||
def remove_snapshot(zk_conn, pool, volume, name):
|
||||
if not verifyVolume(zk_conn, pool, volume):
|
||||
return False, 'ERROR: No volume with name "{}" is present in pool "{}".'.format(volume, pool)
|
||||
@ -734,6 +772,7 @@ def remove_snapshot(zk_conn, pool, volume, name):
|
||||
|
||||
return True, 'Removed RBD snapshot "{}" of volume "{}" in pool "{}".'.format(name, volume, pool)
|
||||
|
||||
|
||||
def get_list_snapshot(zk_conn, pool, volume, limit, is_fuzzy=True):
|
||||
snapshot_list = []
|
||||
if pool and not verifyPool(zk_conn, pool):
|
||||
|
@ -29,6 +29,7 @@ import daemon_lib.node as pvc_node
|
||||
import daemon_lib.network as pvc_network
|
||||
import daemon_lib.ceph as pvc_ceph
|
||||
|
||||
|
||||
def set_maintenance(zk_conn, maint_state):
|
||||
try:
|
||||
if maint_state == 'true':
|
||||
@ -40,6 +41,7 @@ def set_maintenance(zk_conn, maint_state):
|
||||
except Exception:
|
||||
return False, 'Failed to set cluster maintenance state'
|
||||
|
||||
|
||||
def getClusterInformation(zk_conn):
|
||||
# Get cluster maintenance state
|
||||
try:
|
||||
@ -246,6 +248,7 @@ def getClusterInformation(zk_conn):
|
||||
|
||||
return cluster_information
|
||||
|
||||
|
||||
def get_info(zk_conn):
|
||||
# This is a thin wrapper function for naming purposes
|
||||
cluster_information = getClusterInformation(zk_conn)
|
||||
|
@ -36,6 +36,7 @@ import daemon_lib.zkhandler as zkhandler
|
||||
# Supplemental functions
|
||||
###############################################################################
|
||||
|
||||
|
||||
#
|
||||
# Run a local OS command via shell
|
||||
#
|
||||
@ -64,6 +65,7 @@ def run_os_command(command_string, background=False, environment=None, timeout=N
|
||||
stderr = ''
|
||||
return retcode, stdout, stderr
|
||||
|
||||
|
||||
#
|
||||
# Validate a UUID
|
||||
#
|
||||
@ -74,6 +76,7 @@ def validateUUID(dom_uuid):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Connect and disconnect from Zookeeper
|
||||
#
|
||||
@ -89,10 +92,13 @@ def startZKConnection(zk_host):
|
||||
exit(1)
|
||||
return zk_conn
|
||||
|
||||
|
||||
def stopZKConnection(zk_conn):
|
||||
zk_conn.stop()
|
||||
zk_conn.close()
|
||||
return 0
|
||||
|
||||
|
||||
#
|
||||
# Parse a Domain XML object
|
||||
#
|
||||
@ -106,6 +112,7 @@ def getDomainXML(zk_conn, dom_uuid):
|
||||
parsed_xml = lxml.objectify.fromstring(xml)
|
||||
return parsed_xml
|
||||
|
||||
|
||||
#
|
||||
# Get the main details for a VM object from XML
|
||||
#
|
||||
@ -131,6 +138,7 @@ def getDomainMainDetails(parsed_xml):
|
||||
|
||||
return duuid, dname, ddescription, dmemory, dvcpu, dvcputopo
|
||||
|
||||
|
||||
#
|
||||
# Get long-format details
|
||||
#
|
||||
@ -143,6 +151,7 @@ def getDomainExtraDetails(parsed_xml):
|
||||
|
||||
return dtype, darch, dmachine, dconsole, demulator
|
||||
|
||||
|
||||
#
|
||||
# Get CPU features
|
||||
#
|
||||
@ -156,6 +165,7 @@ def getDomainCPUFeatures(parsed_xml):
|
||||
|
||||
return dfeatures
|
||||
|
||||
|
||||
#
|
||||
# Get disk devices
|
||||
#
|
||||
@ -200,6 +210,7 @@ def getDomainDisks(parsed_xml, stats_data):
|
||||
|
||||
return ddisks
|
||||
|
||||
|
||||
#
|
||||
# Get a list of disk devices
|
||||
#
|
||||
@ -211,6 +222,7 @@ def getDomainDiskList(zk_conn, dom_uuid):
|
||||
|
||||
return disk_list
|
||||
|
||||
|
||||
#
|
||||
# Get domain information from XML
|
||||
#
|
||||
@ -308,6 +320,7 @@ def getInformationFromXML(zk_conn, uuid):
|
||||
|
||||
return domain_information
|
||||
|
||||
|
||||
#
|
||||
# Get network devices
|
||||
#
|
||||
@ -362,6 +375,7 @@ def getDomainNetworks(parsed_xml, stats_data):
|
||||
|
||||
return dnets
|
||||
|
||||
|
||||
#
|
||||
# Get controller devices
|
||||
#
|
||||
@ -379,6 +393,7 @@ def getDomainControllers(parsed_xml):
|
||||
|
||||
return dcontrollers
|
||||
|
||||
|
||||
#
|
||||
# Verify node is valid in cluster
|
||||
#
|
||||
@ -388,6 +403,7 @@ def verifyNode(zk_conn, node):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Get the primary coordinator node
|
||||
#
|
||||
@ -412,6 +428,7 @@ def getPrimaryNode(zk_conn):
|
||||
|
||||
return primary_node
|
||||
|
||||
|
||||
#
|
||||
# Find a migration target
|
||||
#
|
||||
@ -443,6 +460,7 @@ def findTargetNode(zk_conn, dom_uuid):
|
||||
# Nothing was found
|
||||
return None
|
||||
|
||||
|
||||
# Get the list of valid target nodes
|
||||
def getNodes(zk_conn, node_limit, dom_uuid):
|
||||
valid_node_list = []
|
||||
@ -469,6 +487,7 @@ def getNodes(zk_conn, node_limit, dom_uuid):
|
||||
|
||||
return valid_node_list
|
||||
|
||||
|
||||
# via free memory (relative to allocated memory)
|
||||
def findTargetNodeMem(zk_conn, node_limit, dom_uuid):
|
||||
most_provfree = 0
|
||||
@ -488,6 +507,7 @@ def findTargetNodeMem(zk_conn, node_limit, dom_uuid):
|
||||
|
||||
return target_node
|
||||
|
||||
|
||||
# via load average
|
||||
def findTargetNodeLoad(zk_conn, node_limit, dom_uuid):
|
||||
least_load = 9999.0
|
||||
@ -503,6 +523,7 @@ def findTargetNodeLoad(zk_conn, node_limit, dom_uuid):
|
||||
|
||||
return target_node
|
||||
|
||||
|
||||
# via total vCPUs
|
||||
def findTargetNodeVCPUs(zk_conn, node_limit, dom_uuid):
|
||||
least_vcpus = 9999
|
||||
@ -518,6 +539,7 @@ def findTargetNodeVCPUs(zk_conn, node_limit, dom_uuid):
|
||||
|
||||
return target_node
|
||||
|
||||
|
||||
# via total VMs
|
||||
def findTargetNodeVMs(zk_conn, node_limit, dom_uuid):
|
||||
least_vms = 9999
|
||||
@ -533,6 +555,7 @@ def findTargetNodeVMs(zk_conn, node_limit, dom_uuid):
|
||||
|
||||
return target_node
|
||||
|
||||
|
||||
# Connect to the primary host and run a command
|
||||
def runRemoteCommand(node, command, become=False):
|
||||
import paramiko
|
||||
|
@ -26,6 +26,7 @@ from kazoo.exceptions import NoNodeError
|
||||
|
||||
import daemon_lib.zkhandler as zkhandler
|
||||
|
||||
|
||||
#
|
||||
# Cluster search functions
|
||||
#
|
||||
@ -38,6 +39,7 @@ def getClusterNetworkList(zk_conn):
|
||||
description_list.append(zkhandler.readdata(zk_conn, '/networks/{}'.format(vni)))
|
||||
return vni_list, description_list
|
||||
|
||||
|
||||
def searchClusterByVNI(zk_conn, vni):
|
||||
try:
|
||||
# Get the lists
|
||||
@ -52,6 +54,7 @@ def searchClusterByVNI(zk_conn, vni):
|
||||
|
||||
return description
|
||||
|
||||
|
||||
def searchClusterByDescription(zk_conn, description):
|
||||
try:
|
||||
# Get the lists
|
||||
@ -66,6 +69,7 @@ def searchClusterByDescription(zk_conn, description):
|
||||
|
||||
return vni
|
||||
|
||||
|
||||
def getNetworkVNI(zk_conn, network):
|
||||
# Validate and obtain alternate passed value
|
||||
if network.isdigit():
|
||||
@ -77,6 +81,7 @@ def getNetworkVNI(zk_conn, network):
|
||||
|
||||
return net_vni
|
||||
|
||||
|
||||
def getNetworkDescription(zk_conn, network):
|
||||
# Validate and obtain alternate passed value
|
||||
if network.isdigit():
|
||||
@ -88,16 +93,19 @@ def getNetworkDescription(zk_conn, network):
|
||||
|
||||
return net_description
|
||||
|
||||
|
||||
def getNetworkDHCPLeases(zk_conn, vni):
|
||||
# Get a list of DHCP leases by listing the children of /networks/<vni>/dhcp4_leases
|
||||
dhcp4_leases = zkhandler.listchildren(zk_conn, '/networks/{}/dhcp4_leases'.format(vni))
|
||||
return sorted(dhcp4_leases)
|
||||
|
||||
|
||||
def getNetworkDHCPReservations(zk_conn, vni):
|
||||
# Get a list of DHCP reservations by listing the children of /networks/<vni>/dhcp4_reservations
|
||||
dhcp4_reservations = zkhandler.listchildren(zk_conn, '/networks/{}/dhcp4_reservations'.format(vni))
|
||||
return sorted(dhcp4_reservations)
|
||||
|
||||
|
||||
def getNetworkACLs(zk_conn, vni, _direction):
|
||||
# Get the (sorted) list of active ACLs
|
||||
if _direction == 'both':
|
||||
@ -119,6 +127,7 @@ def getNetworkACLs(zk_conn, vni, _direction):
|
||||
|
||||
return full_acl_list
|
||||
|
||||
|
||||
def getNetworkInformation(zk_conn, vni):
|
||||
description = zkhandler.readdata(zk_conn, '/networks/{}'.format(vni))
|
||||
nettype = zkhandler.readdata(zk_conn, '/networks/{}/nettype'.format(vni))
|
||||
@ -155,6 +164,7 @@ def getNetworkInformation(zk_conn, vni):
|
||||
}
|
||||
return network_information
|
||||
|
||||
|
||||
def getDHCPLeaseInformation(zk_conn, vni, mac_address):
|
||||
# Check whether this is a dynamic or static lease
|
||||
try:
|
||||
@ -180,6 +190,7 @@ def getDHCPLeaseInformation(zk_conn, vni, mac_address):
|
||||
}
|
||||
return lease_information
|
||||
|
||||
|
||||
def getACLInformation(zk_conn, vni, direction, description):
|
||||
order = zkhandler.readdata(zk_conn, '/networks/{}/firewall_rules/{}/{}/order'.format(vni, direction, description))
|
||||
rule = zkhandler.readdata(zk_conn, '/networks/{}/firewall_rules/{}/{}/rule'.format(vni, direction, description))
|
||||
@ -193,6 +204,7 @@ def getACLInformation(zk_conn, vni, direction, description):
|
||||
}
|
||||
return acl_information
|
||||
|
||||
|
||||
def isValidMAC(macaddr):
|
||||
allowed = re.compile(r"""
|
||||
(
|
||||
@ -206,6 +218,7 @@ def isValidMAC(macaddr):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def isValidIP(ipaddr):
|
||||
ip4_blocks = str(ipaddr).split(".")
|
||||
if len(ip4_blocks) == 4:
|
||||
@ -219,6 +232,7 @@ def isValidIP(ipaddr):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Direct functions
|
||||
#
|
||||
@ -272,6 +286,7 @@ def add_network(zk_conn, vni, description, nettype,
|
||||
|
||||
return True, 'Network "{}" added successfully!'.format(description)
|
||||
|
||||
|
||||
def modify_network(zk_conn, vni, description=None, domain=None, name_servers=None,
|
||||
ip4_network=None, ip4_gateway=None, ip6_network=None, ip6_gateway=None,
|
||||
dhcp4_flag=None, dhcp4_start=None, dhcp4_end=None):
|
||||
@ -313,6 +328,7 @@ def modify_network(zk_conn, vni, description=None, domain=None, name_servers=Non
|
||||
|
||||
return True, 'Network "{}" modified successfully!'.format(vni)
|
||||
|
||||
|
||||
def remove_network(zk_conn, network):
|
||||
# Validate and obtain alternate passed value
|
||||
vni = getNetworkVNI(zk_conn, network)
|
||||
@ -356,6 +372,7 @@ def add_dhcp_reservation(zk_conn, network, ipaddress, macaddress, hostname):
|
||||
|
||||
return True, 'DHCP reservation "{}" added successfully!'.format(macaddress)
|
||||
|
||||
|
||||
def remove_dhcp_reservation(zk_conn, network, reservation):
|
||||
# Validate and obtain standard passed value
|
||||
net_vni = getNetworkVNI(zk_conn, network)
|
||||
@ -395,6 +412,7 @@ def remove_dhcp_reservation(zk_conn, network, reservation):
|
||||
|
||||
return True, 'DHCP {} "{}" removed successfully!'.format(lease_type_human, match_description)
|
||||
|
||||
|
||||
def add_acl(zk_conn, network, direction, description, rule, order):
|
||||
# Validate and obtain standard passed value
|
||||
net_vni = getNetworkVNI(zk_conn, network)
|
||||
@ -458,6 +476,7 @@ def add_acl(zk_conn, network, direction, description, rule, order):
|
||||
|
||||
return True, 'Firewall rule "{}" added successfully!'.format(description)
|
||||
|
||||
|
||||
def remove_acl(zk_conn, network, description):
|
||||
# Validate and obtain standard passed value
|
||||
net_vni = getNetworkVNI(zk_conn, network)
|
||||
@ -498,6 +517,7 @@ def remove_acl(zk_conn, network, description):
|
||||
|
||||
return True, 'Firewall rule "{}" removed successfully!'.format(match_description)
|
||||
|
||||
|
||||
def get_info(zk_conn, network):
|
||||
# Validate and obtain alternate passed value
|
||||
net_vni = getNetworkVNI(zk_conn, network)
|
||||
@ -510,6 +530,7 @@ def get_info(zk_conn, network):
|
||||
|
||||
return True, network_information
|
||||
|
||||
|
||||
def get_list(zk_conn, limit, is_fuzzy=True):
|
||||
net_list = []
|
||||
full_net_list = zkhandler.listchildren(zk_conn, '/networks')
|
||||
@ -532,6 +553,7 @@ def get_list(zk_conn, limit, is_fuzzy=True):
|
||||
|
||||
return True, net_list
|
||||
|
||||
|
||||
def get_list_dhcp(zk_conn, network, limit, only_static=False, is_fuzzy=True):
|
||||
# Validate and obtain alternate passed value
|
||||
net_vni = getNetworkVNI(zk_conn, network)
|
||||
@ -574,6 +596,7 @@ def get_list_dhcp(zk_conn, network, limit, only_static=False, is_fuzzy=True):
|
||||
|
||||
return True, dhcp_list
|
||||
|
||||
|
||||
def get_list_acl(zk_conn, network, limit, direction, is_fuzzy=True):
|
||||
# Validate and obtain alternate passed value
|
||||
net_vni = getNetworkVNI(zk_conn, network)
|
||||
|
@ -26,6 +26,7 @@ import re
|
||||
import daemon_lib.zkhandler as zkhandler
|
||||
import daemon_lib.common as common
|
||||
|
||||
|
||||
def getNodeInformation(zk_conn, node_name):
|
||||
"""
|
||||
Gather information about a node from the Zookeeper database and return a dict() containing it.
|
||||
@ -75,6 +76,7 @@ def getNodeInformation(zk_conn, node_name):
|
||||
}
|
||||
return node_information
|
||||
|
||||
|
||||
#
|
||||
# Direct Functions
|
||||
#
|
||||
@ -105,6 +107,7 @@ def secondary_node(zk_conn, node):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def primary_node(zk_conn, node):
|
||||
# Verify node is valid
|
||||
if not common.verifyNode(zk_conn, node):
|
||||
@ -132,6 +135,7 @@ def primary_node(zk_conn, node):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def flush_node(zk_conn, node, wait=False):
|
||||
# Verify node is valid
|
||||
if not common.verifyNode(zk_conn, node):
|
||||
@ -151,6 +155,7 @@ def flush_node(zk_conn, node, wait=False):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def ready_node(zk_conn, node, wait=False):
|
||||
# Verify node is valid
|
||||
if not common.verifyNode(zk_conn, node):
|
||||
@ -170,6 +175,7 @@ def ready_node(zk_conn, node, wait=False):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def get_info(zk_conn, node):
|
||||
# Verify node is valid
|
||||
if not common.verifyNode(zk_conn, node):
|
||||
@ -182,6 +188,7 @@ def get_info(zk_conn, node):
|
||||
|
||||
return True, node_information
|
||||
|
||||
|
||||
def get_list(zk_conn, limit, daemon_state=None, coordinator_state=None, domain_state=None, is_fuzzy=True):
|
||||
node_list = []
|
||||
full_node_list = zkhandler.listchildren(zk_conn, '/nodes')
|
||||
|
@ -29,6 +29,7 @@ import daemon_lib.common as common
|
||||
|
||||
import daemon_lib.ceph as ceph
|
||||
|
||||
|
||||
#
|
||||
# Cluster search functions
|
||||
#
|
||||
@ -41,6 +42,7 @@ def getClusterDomainList(zk_conn):
|
||||
name_list.append(zkhandler.readdata(zk_conn, '/domains/%s' % uuid))
|
||||
return uuid_list, name_list
|
||||
|
||||
|
||||
def searchClusterByUUID(zk_conn, uuid):
|
||||
try:
|
||||
# Get the lists
|
||||
@ -55,6 +57,7 @@ def searchClusterByUUID(zk_conn, uuid):
|
||||
|
||||
return name
|
||||
|
||||
|
||||
def searchClusterByName(zk_conn, name):
|
||||
try:
|
||||
# Get the lists
|
||||
@ -69,6 +72,7 @@ def searchClusterByName(zk_conn, name):
|
||||
|
||||
return uuid
|
||||
|
||||
|
||||
def getDomainUUID(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
if common.validateUUID(domain):
|
||||
@ -80,6 +84,7 @@ def getDomainUUID(zk_conn, domain):
|
||||
|
||||
return dom_uuid
|
||||
|
||||
|
||||
def getDomainName(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
if common.validateUUID(domain):
|
||||
@ -91,6 +96,7 @@ def getDomainName(zk_conn, domain):
|
||||
|
||||
return dom_name
|
||||
|
||||
|
||||
#
|
||||
# Direct functions
|
||||
#
|
||||
@ -106,6 +112,7 @@ def is_migrated(zk_conn, domain):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def flush_locks(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -145,6 +152,7 @@ def flush_locks(zk_conn, domain):
|
||||
|
||||
return success, message
|
||||
|
||||
|
||||
def define_vm(zk_conn, config_data, target_node, node_limit, node_selector, node_autostart, migration_method=None, profile=None, initial_state='stop'):
|
||||
# Parse the XML data
|
||||
try:
|
||||
@ -204,6 +212,7 @@ def define_vm(zk_conn, config_data, target_node, node_limit, node_selector, node
|
||||
|
||||
return True, 'Added new VM with Name "{}" and UUID "{}" to database.'.format(dom_name, dom_uuid)
|
||||
|
||||
|
||||
def modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostart, provisioner_profile, migration_method):
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
if not dom_uuid:
|
||||
@ -236,6 +245,7 @@ def modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostar
|
||||
|
||||
return True, 'Successfully modified PVC metadata of VM "{}".'.format(domain)
|
||||
|
||||
|
||||
def modify_vm(zk_conn, domain, restart, new_vm_config):
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
if not dom_uuid:
|
||||
@ -277,6 +287,7 @@ def modify_vm(zk_conn, domain, restart, new_vm_config):
|
||||
|
||||
return True, ''
|
||||
|
||||
|
||||
def dump_vm(zk_conn, domain):
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
if not dom_uuid:
|
||||
@ -287,6 +298,7 @@ def dump_vm(zk_conn, domain):
|
||||
|
||||
return True, vm_xml
|
||||
|
||||
|
||||
def undefine_vm(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -314,6 +326,7 @@ def undefine_vm(zk_conn, domain):
|
||||
|
||||
return True, 'Undefined VM "{}" from the cluster.'.format(domain)
|
||||
|
||||
|
||||
def remove_vm(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -353,6 +366,7 @@ def remove_vm(zk_conn, domain):
|
||||
|
||||
return True, 'Removed VM "{}" and disks from the cluster.'.format(domain)
|
||||
|
||||
|
||||
def start_vm(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -367,6 +381,7 @@ def start_vm(zk_conn, domain):
|
||||
|
||||
return True, 'Starting VM "{}".'.format(domain)
|
||||
|
||||
|
||||
def restart_vm(zk_conn, domain, wait=False):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -393,6 +408,7 @@ def restart_vm(zk_conn, domain, wait=False):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def shutdown_vm(zk_conn, domain, wait=False):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -419,6 +435,7 @@ def shutdown_vm(zk_conn, domain, wait=False):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def stop_vm(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -433,6 +450,7 @@ def stop_vm(zk_conn, domain):
|
||||
|
||||
return True, 'Forcibly stopping VM "{}".'.format(domain)
|
||||
|
||||
|
||||
def disable_vm(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -452,6 +470,7 @@ def disable_vm(zk_conn, domain):
|
||||
|
||||
return True, 'Marked VM "{}" as disable.'.format(domain)
|
||||
|
||||
|
||||
def move_vm(zk_conn, domain, target_node, wait=False, force_live=False):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -514,6 +533,7 @@ def move_vm(zk_conn, domain, target_node, wait=False, force_live=False):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def migrate_vm(zk_conn, domain, target_node, force_migrate, wait=False, force_live=False):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -579,6 +599,7 @@ def migrate_vm(zk_conn, domain, target_node, force_migrate, wait=False, force_li
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def unmigrate_vm(zk_conn, domain, wait=False, force_live=False):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -619,6 +640,7 @@ def unmigrate_vm(zk_conn, domain, wait=False, force_live=False):
|
||||
|
||||
return True, retmsg
|
||||
|
||||
|
||||
def get_console_log(zk_conn, domain, lines=1000):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -634,6 +656,7 @@ def get_console_log(zk_conn, domain, lines=1000):
|
||||
|
||||
return True, loglines
|
||||
|
||||
|
||||
def get_info(zk_conn, domain):
|
||||
# Validate that VM exists in cluster
|
||||
dom_uuid = getDomainUUID(zk_conn, domain)
|
||||
@ -647,6 +670,7 @@ def get_info(zk_conn, domain):
|
||||
|
||||
return True, domain_information
|
||||
|
||||
|
||||
def get_list(zk_conn, node, state, limit, is_fuzzy=True):
|
||||
if node:
|
||||
# Verify node is valid
|
||||
|
@ -23,6 +23,7 @@
|
||||
import time
|
||||
import uuid
|
||||
|
||||
|
||||
# Exists function
|
||||
def exists(zk_conn, key):
|
||||
stat = zk_conn.exists(key)
|
||||
@ -31,15 +32,18 @@ def exists(zk_conn, key):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Child list function
|
||||
def listchildren(zk_conn, key):
|
||||
children = zk_conn.get_children(key)
|
||||
return children
|
||||
|
||||
|
||||
# Delete key function
|
||||
def deletekey(zk_conn, key, recursive=True):
|
||||
zk_conn.delete(key, recursive=recursive)
|
||||
|
||||
|
||||
# Rename key recursive function
|
||||
def rename_key_element(zk_conn, zk_transaction, source_key, destination_key):
|
||||
data_raw = zk_conn.get(source_key)
|
||||
@ -54,6 +58,7 @@ def rename_key_element(zk_conn, zk_transaction, source_key, destination_key):
|
||||
|
||||
zk_transaction.delete(source_key)
|
||||
|
||||
|
||||
# Rename key function
|
||||
def renamekey(zk_conn, kv):
|
||||
# Start up a transaction
|
||||
@ -79,12 +84,14 @@ def renamekey(zk_conn, kv):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
# Data read function
|
||||
def readdata(zk_conn, key):
|
||||
data_raw = zk_conn.get(key)
|
||||
data = data_raw[0].decode('utf8')
|
||||
return data
|
||||
|
||||
|
||||
# Data write function
|
||||
def writedata(zk_conn, kv):
|
||||
# Start up a transaction
|
||||
@ -123,6 +130,7 @@ def writedata(zk_conn, kv):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
# Write lock function
|
||||
def writelock(zk_conn, key):
|
||||
count = 1
|
||||
@ -140,6 +148,7 @@ def writelock(zk_conn, key):
|
||||
continue
|
||||
return lock
|
||||
|
||||
|
||||
# Read lock function
|
||||
def readlock(zk_conn, key):
|
||||
count = 1
|
||||
@ -157,6 +166,7 @@ def readlock(zk_conn, key):
|
||||
continue
|
||||
return lock
|
||||
|
||||
|
||||
# Exclusive lock function
|
||||
def exclusivelock(zk_conn, key):
|
||||
count = 1
|
||||
|
Reference in New Issue
Block a user