Lint: E302 expected 2 blank lines, found X
This commit is contained in:
@ -22,24 +22,40 @@
|
||||
|
||||
import datetime
|
||||
|
||||
|
||||
# ANSII colours for output
|
||||
def red():
|
||||
return '\033[91m'
|
||||
|
||||
|
||||
def blue():
|
||||
return '\033[94m'
|
||||
|
||||
|
||||
def cyan():
|
||||
return '\033[96m'
|
||||
|
||||
|
||||
def green():
|
||||
return '\033[92m'
|
||||
|
||||
|
||||
def yellow():
|
||||
return '\033[93m'
|
||||
|
||||
|
||||
def purple():
|
||||
return '\033[95m'
|
||||
|
||||
|
||||
def bold():
|
||||
return '\033[1m'
|
||||
|
||||
|
||||
def end():
|
||||
return '\033[0m'
|
||||
|
||||
|
||||
# Print function
|
||||
def echo(message, prefix, state):
|
||||
# Get the date
|
||||
|
@ -32,7 +32,7 @@ from cli_lib.common import UploadProgressBar, call_api
|
||||
# Supplemental functions
|
||||
#
|
||||
|
||||
# Format byte sizes to/from human-readable units
|
||||
# Matrix of human-to-byte values
|
||||
byte_unit_matrix = {
|
||||
'B': 1,
|
||||
'K': 1024,
|
||||
@ -41,6 +41,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):
|
||||
@ -55,6 +68,7 @@ def format_bytes_tohuman(databytes):
|
||||
|
||||
return datahuman
|
||||
|
||||
|
||||
def format_bytes_fromhuman(datahuman):
|
||||
# Trim off human-readable character
|
||||
dataunit = datahuman[-1]
|
||||
@ -64,14 +78,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):
|
||||
@ -86,6 +92,7 @@ def format_ops_tohuman(dataops):
|
||||
|
||||
return datahuman
|
||||
|
||||
|
||||
def format_ops_fromhuman(datahuman):
|
||||
# Trim off human-readable character
|
||||
dataunit = datahuman[-1]
|
||||
@ -93,10 +100,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
|
||||
#
|
||||
@ -115,6 +124,7 @@ def ceph_status(config):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_util(config):
|
||||
"""
|
||||
Get utilization of the Ceph cluster
|
||||
@ -130,6 +140,7 @@ def ceph_util(config):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def format_raw_output(status_data):
|
||||
ainformation = list()
|
||||
ainformation.append('{bold}Ceph cluster {stype} (primary node {end}{blue}{primary}{end}{bold}){end}\n'.format(bold=ansiprint.bold(), end=ansiprint.end(), blue=ansiprint.blue(), stype=status_data['type'], primary=status_data['primary_node']))
|
||||
@ -138,6 +149,7 @@ def format_raw_output(status_data):
|
||||
|
||||
return '\n'.join(ainformation)
|
||||
|
||||
|
||||
#
|
||||
# OSD functions
|
||||
#
|
||||
@ -156,6 +168,7 @@ def ceph_osd_info(config, osd):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_osd_list(config, limit):
|
||||
"""
|
||||
Get list information about Ceph OSDs (limited by {limit})
|
||||
@ -175,6 +188,7 @@ def ceph_osd_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_osd_add(config, node, device, weight):
|
||||
"""
|
||||
Add new Ceph OSD
|
||||
@ -197,6 +211,7 @@ def ceph_osd_add(config, node, device, weight):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_osd_remove(config, osdid):
|
||||
"""
|
||||
Remove Ceph OSD
|
||||
@ -217,6 +232,7 @@ def ceph_osd_remove(config, osdid):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_osd_state(config, osdid, state):
|
||||
"""
|
||||
Set state of Ceph OSD
|
||||
@ -237,6 +253,7 @@ def ceph_osd_state(config, osdid, state):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_osd_option(config, option, action):
|
||||
"""
|
||||
Set cluster option of Ceph OSDs
|
||||
@ -258,6 +275,7 @@ def ceph_osd_option(config, option, action):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def getOutputColoursOSD(osd_information):
|
||||
# Set the UP status
|
||||
if osd_information['stats']['up'] == 1:
|
||||
@ -277,6 +295,7 @@ def getOutputColoursOSD(osd_information):
|
||||
|
||||
return osd_up_flag, osd_up_colour, osd_in_flag, osd_in_colour
|
||||
|
||||
|
||||
def format_list_osd(osd_list):
|
||||
# Handle empty list
|
||||
if not osd_list:
|
||||
@ -542,6 +561,7 @@ def ceph_pool_info(config, pool):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_pool_list(config, limit):
|
||||
"""
|
||||
Get list information about Ceph OSDs (limited by {limit})
|
||||
@ -561,6 +581,7 @@ def ceph_pool_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_pool_add(config, pool, pgs, replcfg):
|
||||
"""
|
||||
Add new Ceph OSD
|
||||
@ -583,6 +604,7 @@ def ceph_pool_add(config, pool, pgs, replcfg):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_pool_remove(config, pool):
|
||||
"""
|
||||
Remove Ceph OSD
|
||||
@ -603,6 +625,7 @@ def ceph_pool_remove(config, pool):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def format_list_pool(pool_list):
|
||||
# Handle empty list
|
||||
if not pool_list:
|
||||
@ -820,6 +843,7 @@ def ceph_volume_info(config, pool, volume):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_volume_list(config, limit, pool):
|
||||
"""
|
||||
Get list information about Ceph volumes (limited by {limit} and by {pool})
|
||||
@ -841,6 +865,7 @@ def ceph_volume_list(config, limit, pool):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_volume_add(config, pool, volume, size):
|
||||
"""
|
||||
Add new Ceph volume
|
||||
@ -863,6 +888,7 @@ def ceph_volume_add(config, pool, volume, size):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_volume_upload(config, pool, volume, image_format, image_file):
|
||||
"""
|
||||
Upload a disk image to a Ceph volume
|
||||
@ -898,6 +924,7 @@ def ceph_volume_upload(config, pool, volume, image_format, image_file):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_volume_remove(config, pool, volume):
|
||||
"""
|
||||
Remove Ceph volume
|
||||
@ -915,6 +942,7 @@ def ceph_volume_remove(config, pool, volume):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_volume_modify(config, pool, volume, new_name=None, new_size=None):
|
||||
"""
|
||||
Modify Ceph volume
|
||||
@ -939,6 +967,7 @@ def ceph_volume_modify(config, pool, volume, new_name=None, new_size=None):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_volume_clone(config, pool, volume, new_volume):
|
||||
"""
|
||||
Clone Ceph volume
|
||||
@ -959,6 +988,7 @@ def ceph_volume_clone(config, pool, volume, new_volume):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def format_list_volume(volume_list):
|
||||
# Handle empty list
|
||||
if not volume_list:
|
||||
@ -1092,6 +1122,7 @@ def ceph_snapshot_info(config, pool, volume, snapshot):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_snapshot_list(config, limit, volume, pool):
|
||||
"""
|
||||
Get list information about Ceph snapshots (limited by {limit}, by {pool}, or by {volume})
|
||||
@ -1115,6 +1146,7 @@ def ceph_snapshot_list(config, limit, volume, pool):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_snapshot_add(config, pool, volume, snapshot):
|
||||
"""
|
||||
Add new Ceph snapshot
|
||||
@ -1137,6 +1169,7 @@ def ceph_snapshot_add(config, pool, volume, snapshot):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_snapshot_remove(config, pool, volume, snapshot):
|
||||
"""
|
||||
Remove Ceph snapshot
|
||||
@ -1154,6 +1187,7 @@ def ceph_snapshot_remove(config, pool, volume, snapshot):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None):
|
||||
"""
|
||||
Modify Ceph snapshot
|
||||
@ -1176,6 +1210,7 @@ def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def format_list_snapshot(snapshot_list):
|
||||
# Handle empty list
|
||||
if not snapshot_list:
|
||||
@ -1249,6 +1284,7 @@ def format_list_snapshot(snapshot_list):
|
||||
|
||||
return '\n'.join(sorted(snapshot_list_output))
|
||||
|
||||
|
||||
#
|
||||
# Benchmark functions
|
||||
#
|
||||
@ -1274,6 +1310,7 @@ def ceph_benchmark_run(config, pool):
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
|
||||
def ceph_benchmark_list(config, job):
|
||||
"""
|
||||
View results of one or more previous benchmark runs
|
||||
@ -1300,6 +1337,7 @@ def ceph_benchmark_list(config, job):
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
|
||||
def format_list_benchmark(config, benchmark_information):
|
||||
benchmark_list_output = []
|
||||
|
||||
@ -1420,6 +1458,7 @@ def format_list_benchmark(config, benchmark_information):
|
||||
|
||||
return '\n'.join(benchmark_list_output)
|
||||
|
||||
|
||||
def format_info_benchmark(config, benchmark_information):
|
||||
if benchmark_information[0]['benchmark_result'] == "Running":
|
||||
return "Benchmark test is still running."
|
||||
|
@ -25,6 +25,7 @@ import json
|
||||
import cli_lib.ansiprint as ansiprint
|
||||
from cli_lib.common import call_api
|
||||
|
||||
|
||||
def initialize(config):
|
||||
"""
|
||||
Initialize the PVC cluster
|
||||
@ -42,6 +43,7 @@ def initialize(config):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def maintenance_mode(config, state):
|
||||
"""
|
||||
Enable or disable PVC cluster maintenance mode
|
||||
@ -62,6 +64,7 @@ def maintenance_mode(config, state):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def get_info(config):
|
||||
"""
|
||||
Get status of the PVC cluster
|
||||
@ -77,6 +80,7 @@ def get_info(config):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def format_info(cluster_information, oformat):
|
||||
if oformat == 'json':
|
||||
return json.dumps(cluster_information)
|
||||
|
@ -27,6 +27,7 @@ import requests
|
||||
import click
|
||||
from urllib3 import disable_warnings
|
||||
|
||||
|
||||
def format_bytes(size_bytes):
|
||||
byte_unit_matrix = {
|
||||
'B': 1,
|
||||
@ -44,6 +45,7 @@ def format_bytes(size_bytes):
|
||||
break
|
||||
return human_bytes
|
||||
|
||||
|
||||
def format_metric(integer):
|
||||
integer_unit_matrix = {
|
||||
'': 1,
|
||||
@ -61,6 +63,7 @@ def format_metric(integer):
|
||||
break
|
||||
return human_integer
|
||||
|
||||
|
||||
class UploadProgressBar(object):
|
||||
def __init__(self, filename, end_message='', end_nl=True):
|
||||
file_size = os.path.getsize(filename)
|
||||
@ -103,6 +106,7 @@ class UploadProgressBar(object):
|
||||
if self.end_message:
|
||||
click.echo(self.end_message + self.end_suffix, nl=self.end_nl)
|
||||
|
||||
|
||||
class ErrorResponse(requests.Response):
|
||||
def __init__(self, json_data, status_code):
|
||||
self.json_data = json_data
|
||||
@ -111,6 +115,7 @@ class ErrorResponse(requests.Response):
|
||||
def json(self):
|
||||
return self.json_data
|
||||
|
||||
|
||||
def call_api(config, operation, request_uri, headers={}, params=None, data=None, files=None):
|
||||
# Craft the URI
|
||||
uri = '{}://{}{}{}'.format(
|
||||
|
@ -24,6 +24,7 @@ import re
|
||||
import cli_lib.ansiprint as ansiprint
|
||||
from cli_lib.common import call_api
|
||||
|
||||
|
||||
def isValidMAC(macaddr):
|
||||
allowed = re.compile(r"""
|
||||
(
|
||||
@ -37,6 +38,7 @@ def isValidMAC(macaddr):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def isValidIP(ipaddr):
|
||||
ip4_blocks = str(ipaddr).split(".")
|
||||
if len(ip4_blocks) == 4:
|
||||
@ -50,6 +52,7 @@ def isValidIP(ipaddr):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Primary functions
|
||||
#
|
||||
@ -68,6 +71,7 @@ def net_info(config, net):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_list(config, limit):
|
||||
"""
|
||||
Get list information about networks (limited by {limit})
|
||||
@ -87,6 +91,7 @@ def net_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_add(config, vni, description, nettype, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end):
|
||||
"""
|
||||
Add new network
|
||||
@ -118,6 +123,7 @@ def net_add(config, vni, description, nettype, domain, name_servers, ip4_network
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end):
|
||||
"""
|
||||
Modify a network
|
||||
@ -157,6 +163,7 @@ def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_remove(config, net):
|
||||
"""
|
||||
Remove a network
|
||||
@ -174,6 +181,7 @@ def net_remove(config, net):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
#
|
||||
# DHCP lease functions
|
||||
#
|
||||
@ -192,6 +200,7 @@ def net_dhcp_info(config, net, mac):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_dhcp_list(config, net, limit, only_static=False):
|
||||
"""
|
||||
Get list information about leases (limited by {limit})
|
||||
@ -216,6 +225,7 @@ def net_dhcp_list(config, net, limit, only_static=False):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_dhcp_add(config, net, ipaddr, macaddr, hostname):
|
||||
"""
|
||||
Add new network DHCP lease
|
||||
@ -238,6 +248,7 @@ def net_dhcp_add(config, net, ipaddr, macaddr, hostname):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_dhcp_remove(config, net, mac):
|
||||
"""
|
||||
Remove a network DHCP lease
|
||||
@ -255,6 +266,7 @@ def net_dhcp_remove(config, net, mac):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
#
|
||||
# ACL functions
|
||||
#
|
||||
@ -273,6 +285,7 @@ def net_acl_info(config, net, description):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_acl_list(config, net, limit, direction):
|
||||
"""
|
||||
Get list information about ACLs (limited by {limit})
|
||||
@ -294,6 +307,7 @@ def net_acl_list(config, net, limit, direction):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_acl_add(config, net, direction, description, rule, order):
|
||||
"""
|
||||
Add new network acl
|
||||
@ -318,7 +332,9 @@ def net_acl_add(config, net, direction, description, rule, order):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def net_acl_remove(config, net, description):
|
||||
|
||||
"""
|
||||
Remove a network ACL
|
||||
|
||||
@ -360,6 +376,7 @@ def getOutputColours(network_information):
|
||||
|
||||
return v6_flag_colour, v4_flag_colour, dhcp6_flag_colour, dhcp4_flag_colour
|
||||
|
||||
|
||||
def format_info(config, network_information, long_output):
|
||||
if not network_information:
|
||||
return "No network found"
|
||||
@ -418,6 +435,7 @@ def format_info(config, network_information, long_output):
|
||||
# Join it all together
|
||||
return '\n'.join(ainformation)
|
||||
|
||||
|
||||
def format_list(config, network_list):
|
||||
if not network_list:
|
||||
return "No network found"
|
||||
@ -534,6 +552,7 @@ def format_list(config, network_list):
|
||||
|
||||
return '\n'.join(sorted(network_list_output))
|
||||
|
||||
|
||||
def format_list_dhcp(dhcp_lease_list):
|
||||
dhcp_lease_list_output = []
|
||||
|
||||
@ -598,6 +617,7 @@ def format_list_dhcp(dhcp_lease_list):
|
||||
|
||||
return '\n'.join(sorted(dhcp_lease_list_output))
|
||||
|
||||
|
||||
def format_list_acl(acl_list):
|
||||
# Handle when we get an empty entry
|
||||
if not acl_list:
|
||||
|
@ -23,6 +23,7 @@
|
||||
import cli_lib.ansiprint as ansiprint
|
||||
from cli_lib.common import call_api
|
||||
|
||||
|
||||
#
|
||||
# Primary functions
|
||||
#
|
||||
@ -46,6 +47,7 @@ def node_coordinator_state(config, node, action):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def node_domain_state(config, node, action, wait):
|
||||
"""
|
||||
Set node domain state state (flush/ready)
|
||||
@ -67,6 +69,7 @@ def node_domain_state(config, node, action, wait):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def node_info(config, node):
|
||||
"""
|
||||
Get information about node
|
||||
@ -82,6 +85,7 @@ def node_info(config, node):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def node_list(config, limit, target_daemon_state, target_coordinator_state, target_domain_state):
|
||||
"""
|
||||
Get list information about nodes (limited by {limit})
|
||||
@ -107,6 +111,7 @@ def node_list(config, limit, target_daemon_state, target_coordinator_state, targ
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
#
|
||||
# Output display functions
|
||||
#
|
||||
@ -148,6 +153,7 @@ def getOutputColours(node_information):
|
||||
|
||||
return daemon_state_colour, coordinator_state_colour, domain_state_colour, mem_allocated_colour, mem_provisioned_colour
|
||||
|
||||
|
||||
def format_info(node_information, long_output):
|
||||
daemon_state_colour, coordinator_state_colour, domain_state_colour, mem_allocated_colour, mem_provisioned_colour = getOutputColours(node_information)
|
||||
|
||||
@ -178,6 +184,7 @@ def format_info(node_information, long_output):
|
||||
ainformation.append('')
|
||||
return '\n'.join(ainformation)
|
||||
|
||||
|
||||
def format_list(node_list, raw):
|
||||
# Handle single-element lists
|
||||
if not isinstance(node_list, list):
|
||||
|
@ -27,6 +27,7 @@ from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncod
|
||||
import cli_lib.ansiprint as ansiprint
|
||||
from cli_lib.common import UploadProgressBar, call_api
|
||||
|
||||
|
||||
#
|
||||
# Primary functions
|
||||
#
|
||||
@ -45,6 +46,7 @@ def template_info(config, template, template_type):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def template_list(config, limit, template_type=None):
|
||||
"""
|
||||
Get list information about templates (limited by {limit})
|
||||
@ -67,6 +69,7 @@ def template_list(config, limit, template_type=None):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def template_add(config, params, template_type=None):
|
||||
"""
|
||||
Add a new template of {template_type} with {params}
|
||||
@ -84,6 +87,7 @@ def template_add(config, params, template_type=None):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def template_modify(config, params, name, template_type):
|
||||
"""
|
||||
Modify an existing template of {template_type} with {params}
|
||||
@ -101,6 +105,7 @@ def template_modify(config, params, name, template_type):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def template_remove(config, name, template_type):
|
||||
"""
|
||||
Remove template {name} of {template_type}
|
||||
@ -118,6 +123,7 @@ def template_remove(config, name, template_type):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def template_element_add(config, name, element_id, params, element_type=None, template_type=None):
|
||||
"""
|
||||
Add a new template element of {element_type} with {params} to template {name} of {template_type}
|
||||
@ -135,6 +141,7 @@ def template_element_add(config, name, element_id, params, element_type=None, te
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def template_element_remove(config, name, element_id, element_type=None, template_type=None):
|
||||
"""
|
||||
Remove template element {element_id} of {element_type} from template {name} of {template_type}
|
||||
@ -152,6 +159,7 @@ def template_element_remove(config, name, element_id, element_type=None, templat
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def userdata_info(config, userdata):
|
||||
"""
|
||||
Get information about userdata
|
||||
@ -167,6 +175,7 @@ def userdata_info(config, userdata):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def userdata_list(config, limit):
|
||||
"""
|
||||
Get list information about userdatas (limited by {limit})
|
||||
@ -186,6 +195,7 @@ def userdata_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def userdata_show(config, name):
|
||||
"""
|
||||
Get information about userdata name
|
||||
@ -201,6 +211,7 @@ def userdata_show(config, name):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def userdata_add(config, params):
|
||||
"""
|
||||
Add a new userdata with {params}
|
||||
@ -227,6 +238,7 @@ def userdata_add(config, params):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def userdata_modify(config, name, params):
|
||||
"""
|
||||
Modify userdata {name} with {params}
|
||||
@ -252,6 +264,7 @@ def userdata_modify(config, name, params):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def userdata_remove(config, name):
|
||||
"""
|
||||
Remove userdata {name}
|
||||
@ -269,6 +282,7 @@ def userdata_remove(config, name):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def script_info(config, script):
|
||||
"""
|
||||
Get information about script
|
||||
@ -284,6 +298,7 @@ def script_info(config, script):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def script_list(config, limit):
|
||||
"""
|
||||
Get list information about scripts (limited by {limit})
|
||||
@ -303,6 +318,7 @@ def script_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def script_show(config, name):
|
||||
"""
|
||||
Get information about script name
|
||||
@ -318,6 +334,7 @@ def script_show(config, name):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def script_add(config, params):
|
||||
"""
|
||||
Add a new script with {params}
|
||||
@ -344,6 +361,7 @@ def script_add(config, params):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def script_modify(config, name, params):
|
||||
"""
|
||||
Modify script {name} with {params}
|
||||
@ -369,6 +387,7 @@ def script_modify(config, name, params):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def script_remove(config, name):
|
||||
"""
|
||||
Remove script {name}
|
||||
@ -386,6 +405,7 @@ def script_remove(config, name):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def ova_info(config, name):
|
||||
"""
|
||||
Get information about OVA image {name}
|
||||
@ -401,6 +421,7 @@ def ova_info(config, name):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ova_list(config, limit):
|
||||
"""
|
||||
Get list information about OVA images (limited by {limit})
|
||||
@ -420,6 +441,7 @@ def ova_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def ova_upload(config, name, ova_file, params):
|
||||
"""
|
||||
Upload an OVA image to the cluster
|
||||
@ -452,6 +474,7 @@ def ova_upload(config, name, ova_file, params):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def ova_remove(config, name):
|
||||
"""
|
||||
Remove OVA image {name}
|
||||
@ -469,6 +492,7 @@ def ova_remove(config, name):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def profile_info(config, profile):
|
||||
"""
|
||||
Get information about profile
|
||||
@ -484,6 +508,7 @@ def profile_info(config, profile):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def profile_list(config, limit):
|
||||
"""
|
||||
Get list information about profiles (limited by {limit})
|
||||
@ -503,6 +528,7 @@ def profile_list(config, limit):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def profile_add(config, params):
|
||||
"""
|
||||
Add a new profile with {params}
|
||||
@ -520,6 +546,7 @@ def profile_add(config, params):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def profile_modify(config, name, params):
|
||||
"""
|
||||
Modify profile {name} with {params}
|
||||
@ -537,6 +564,7 @@ def profile_modify(config, name, params):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def profile_remove(config, name):
|
||||
"""
|
||||
Remove profile {name}
|
||||
@ -554,6 +582,7 @@ def profile_remove(config, name):
|
||||
|
||||
return retvalue, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_create(config, name, profile, wait_flag, define_flag, start_flag, script_args):
|
||||
"""
|
||||
Create a new VM named {name} with profile {profile}
|
||||
@ -584,6 +613,7 @@ def vm_create(config, name, profile, wait_flag, define_flag, start_flag, script_
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
|
||||
def task_status(config, task_id=None, is_watching=False):
|
||||
"""
|
||||
Get information about provisioner job {task_id} or all tasks if None
|
||||
@ -658,6 +688,7 @@ def task_status(config, task_id=None, is_watching=False):
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
|
||||
#
|
||||
# Format functions
|
||||
#
|
||||
@ -700,6 +731,7 @@ def format_list_template(template_data, template_type=None):
|
||||
|
||||
return '\n'.join(ainformation)
|
||||
|
||||
|
||||
def format_list_template_system(template_data):
|
||||
if isinstance(template_data, dict):
|
||||
template_data = [template_data]
|
||||
@ -848,6 +880,7 @@ Meta: {template_node_limit: <{template_node_limit_length}} \
|
||||
|
||||
return True, ''
|
||||
|
||||
|
||||
def format_list_template_network(template_template):
|
||||
if isinstance(template_template, dict):
|
||||
template_template = [template_template]
|
||||
@ -922,6 +955,7 @@ def format_list_template_network(template_template):
|
||||
|
||||
return '\n'.join([template_list_output_header] + template_list_output)
|
||||
|
||||
|
||||
def format_list_template_storage(template_template):
|
||||
if isinstance(template_template, dict):
|
||||
template_template = [template_template]
|
||||
@ -1057,6 +1091,7 @@ def format_list_template_storage(template_template):
|
||||
|
||||
return '\n'.join([template_list_output_header] + template_list_output)
|
||||
|
||||
|
||||
def format_list_userdata(userdata_data, lines=None):
|
||||
if isinstance(userdata_data, dict):
|
||||
userdata_data = [userdata_data]
|
||||
@ -1131,6 +1166,7 @@ def format_list_userdata(userdata_data, lines=None):
|
||||
|
||||
return '\n'.join([userdata_list_output_header] + userdata_list_output)
|
||||
|
||||
|
||||
def format_list_script(script_data, lines=None):
|
||||
if isinstance(script_data, dict):
|
||||
script_data = [script_data]
|
||||
@ -1205,6 +1241,7 @@ def format_list_script(script_data, lines=None):
|
||||
|
||||
return '\n'.join([script_list_output_header] + script_list_output)
|
||||
|
||||
|
||||
def format_list_ova(ova_data):
|
||||
if isinstance(ova_data, dict):
|
||||
ova_data = [ova_data]
|
||||
@ -1318,6 +1355,7 @@ def format_list_ova(ova_data):
|
||||
|
||||
return '\n'.join([ova_list_output_header] + ova_list_output)
|
||||
|
||||
|
||||
def format_list_profile(profile_data):
|
||||
if isinstance(profile_data, dict):
|
||||
profile_data = [profile_data]
|
||||
@ -1442,6 +1480,7 @@ Data: {profile_userdata: <{profile_userdata_length}} \
|
||||
|
||||
return '\n'.join([profile_list_output_header] + profile_list_output)
|
||||
|
||||
|
||||
def format_list_task(task_data):
|
||||
task_list_output = []
|
||||
|
||||
|
@ -26,6 +26,7 @@ import re
|
||||
import cli_lib.ansiprint as ansiprint
|
||||
from cli_lib.common import call_api, format_bytes, format_metric
|
||||
|
||||
|
||||
#
|
||||
# Primary functions
|
||||
#
|
||||
@ -53,6 +54,7 @@ def vm_info(config, vm):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_list(config, limit, target_node, target_state):
|
||||
"""
|
||||
Get list information about VMs (limited by {limit}, {target_node}, or {target_state})
|
||||
@ -76,6 +78,7 @@ def vm_list(config, limit, target_node, target_state):
|
||||
else:
|
||||
return False, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_define(config, xml, node, node_limit, node_selector, node_autostart, migration_method):
|
||||
"""
|
||||
Define a new VM on the cluster
|
||||
@ -103,6 +106,7 @@ def vm_define(config, xml, node, node_limit, node_selector, node_autostart, migr
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_modify(config, vm, xml, restart):
|
||||
"""
|
||||
Modify the configuration of VM
|
||||
@ -126,6 +130,7 @@ def vm_modify(config, vm, xml, restart):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_metadata(config, vm, node_limit, node_selector, node_autostart, migration_method, provisioner_profile):
|
||||
"""
|
||||
Modify PVC metadata of a VM
|
||||
@ -162,6 +167,7 @@ def vm_metadata(config, vm, node_limit, node_selector, node_autostart, migration
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_remove(config, vm, delete_disks=False):
|
||||
"""
|
||||
Remove a VM
|
||||
@ -182,6 +188,7 @@ def vm_remove(config, vm, delete_disks=False):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_state(config, vm, target_state, wait=False):
|
||||
"""
|
||||
Modify the current state of VM
|
||||
@ -203,6 +210,7 @@ def vm_state(config, vm, target_state, wait=False):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_node(config, vm, target_node, action, force=False, wait=False, force_live=False):
|
||||
"""
|
||||
Modify the current node of VM via {action}
|
||||
@ -227,6 +235,7 @@ def vm_node(config, vm, target_node, action, force=False, wait=False, force_live
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def vm_locks(config, vm):
|
||||
"""
|
||||
Flush RBD locks of (stopped) VM
|
||||
@ -244,6 +253,7 @@ def vm_locks(config, vm):
|
||||
|
||||
return retstatus, response.json().get('message', '')
|
||||
|
||||
|
||||
def view_console_log(config, vm, lines=100):
|
||||
"""
|
||||
Return console log lines from the API (and display them in a pager in the main CLI)
|
||||
@ -268,6 +278,7 @@ def view_console_log(config, vm, lines=100):
|
||||
|
||||
return True, loglines
|
||||
|
||||
|
||||
def follow_console_log(config, vm, lines=10):
|
||||
"""
|
||||
Return and follow console log lines from the API
|
||||
@ -323,6 +334,7 @@ def follow_console_log(config, vm, lines=10):
|
||||
|
||||
return True, ''
|
||||
|
||||
|
||||
#
|
||||
# Output display functions
|
||||
#
|
||||
@ -478,6 +490,7 @@ def format_info(config, domain_information, long_output):
|
||||
ainformation.append('')
|
||||
return '\n'.join(ainformation)
|
||||
|
||||
|
||||
def format_list(config, vm_list, raw):
|
||||
# Handle single-element lists
|
||||
if not isinstance(vm_list, list):
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
import uuid
|
||||
|
||||
|
||||
# Exists function
|
||||
def exists(zk_conn, key):
|
||||
stat = zk_conn.exists(key)
|
||||
@ -30,21 +31,25 @@ 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)
|
||||
|
||||
|
||||
# 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
|
||||
@ -83,12 +88,14 @@ def writedata(zk_conn, kv):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
# Write lock function
|
||||
def writelock(zk_conn, key):
|
||||
lock_id = str(uuid.uuid1())
|
||||
lock = zk_conn.WriteLock('{}'.format(key), lock_id)
|
||||
return lock
|
||||
|
||||
|
||||
# Read lock function
|
||||
def readlock(zk_conn, key):
|
||||
lock_id = str(uuid.uuid1())
|
||||
|
Reference in New Issue
Block a user