2019-07-05 14:11:01 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-02-08 19:16:19 -05:00
|
|
|
# helper.py - PVC HTTP API helper functions
|
2019-07-05 14:11:01 -04:00
|
|
|
# Part of the Parallel Virtual Cluster (PVC) system
|
|
|
|
#
|
2023-12-29 11:16:59 -05:00
|
|
|
# Copyright (C) 2018-2024 Joshua M. Boniface <joshua@boniface.me>
|
2019-07-05 14:11:01 -04:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2021-03-25 16:57:17 -04:00
|
|
|
# the Free Software Foundation, version 3.
|
2019-07-05 14:11:01 -04:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
import flask
|
2020-11-24 02:39:06 -05:00
|
|
|
import json
|
2020-01-24 13:17:48 -05:00
|
|
|
import lxml.etree as etree
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2023-12-09 02:52:08 -05:00
|
|
|
from re import match
|
|
|
|
from requests import get
|
Improve handling of large file uploads
By default, Werkzeug would require the entire file (be it an OVA or
image file) to be uploaded and saved to a temporary, fake file under
`/tmp`, before any further processing could occur. This blocked most of
the execution of these functions until the upload was completed.
This entirely defeated the purpose of what I was trying to do, which was
to save the uploads directly to the temporary blockdev in each case,
thus avoiding any sort of memory or (host) disk usage.
The solution is two-fold:
1. First, ensure that the `location='args'` value is set in
RequestParser; without this, the `files` portion would be parsed
during the argument parsing, which was the original source of this
blocking behaviour.
2. Instead of the convoluted request handling that was being done
originally here, instead entirely defer the parsing of the `files`
arguments until the point in the code where they are ready to be
saved. Then, using an override stream_factory that simply opens the
temporary blockdev, the upload can commence while being written
directly out to it, rather than using `/tmp` space.
This does alter the error handling slightly; it is impossible to check
if the argument was passed until this point in the code, so it may take
longer to fail if the API consumer does not specify a file as they
should. This is a minor trade-off and I would expect my API consumers to
be sane here.
2020-10-19 00:47:56 -04:00
|
|
|
from werkzeug.formparser import parse_form_data
|
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
from pvcapid.Daemon import config, strtobool
|
|
|
|
|
|
|
|
from daemon_lib.zkhandler import ZKConnection
|
|
|
|
|
2020-02-08 18:48:59 -05:00
|
|
|
import daemon_lib.common as pvc_common
|
|
|
|
import daemon_lib.cluster as pvc_cluster
|
2023-12-04 01:37:54 -05:00
|
|
|
import daemon_lib.faults as pvc_faults
|
2020-02-08 18:48:59 -05:00
|
|
|
import daemon_lib.node as pvc_node
|
|
|
|
import daemon_lib.vm as pvc_vm
|
|
|
|
import daemon_lib.network as pvc_network
|
|
|
|
import daemon_lib.ceph as pvc_ceph
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
#
|
2020-11-24 02:39:06 -05:00
|
|
|
# Cluster base functions
|
2019-12-23 20:43:20 -05:00
|
|
|
#
|
2021-05-28 23:33:36 -04:00
|
|
|
@ZKConnection(config)
|
2021-05-30 23:59:17 -04:00
|
|
|
def initialize_cluster(zkhandler, overwrite=False):
|
2021-05-28 23:33:36 -04:00
|
|
|
"""
|
|
|
|
Initialize a new cluster
|
|
|
|
"""
|
2021-06-13 14:22:26 -04:00
|
|
|
retflag, retmsg = pvc_cluster.cluster_initialize(zkhandler, overwrite)
|
2019-12-25 12:18:26 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
retmsg = {"message": retmsg}
|
2021-06-13 14:22:26 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-06-13 14:22:26 -04:00
|
|
|
return retmsg, retcode
|
2020-11-24 02:39:06 -05:00
|
|
|
|
2021-05-30 23:39:37 -04:00
|
|
|
|
2021-06-13 14:22:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def backup_cluster(zkhandler):
|
|
|
|
retflag, retdata = pvc_cluster.cluster_backup(zkhandler)
|
2020-11-24 02:39:06 -05:00
|
|
|
|
2021-06-13 14:22:26 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
retdata = json.dumps(retdata)
|
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2020-11-24 02:39:06 -05:00
|
|
|
|
2021-06-13 14:22:26 -04:00
|
|
|
return retdata, retcode
|
2020-11-24 02:39:06 -05:00
|
|
|
|
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def restore_cluster(zkhandler, cluster_data_raw):
|
2020-11-24 02:39:06 -05:00
|
|
|
try:
|
|
|
|
cluster_data = json.loads(cluster_data_raw)
|
|
|
|
except Exception as e:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "ERROR: Failed to parse JSON data: {}".format(e)}, 400
|
2020-11-24 02:39:06 -05:00
|
|
|
|
2021-06-13 14:22:26 -04:00
|
|
|
retflag, retdata = pvc_cluster.cluster_restore(zkhandler, cluster_data)
|
2020-11-24 02:39:06 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2021-06-13 14:22:26 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
2021-05-28 23:33:36 -04:00
|
|
|
else:
|
2021-06-13 14:22:26 -04:00
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
return retdata, retcode
|
2020-11-24 02:39:06 -05:00
|
|
|
|
|
|
|
|
2019-12-29 20:42:02 -05:00
|
|
|
#
|
2020-01-09 10:53:27 -05:00
|
|
|
# Cluster functions
|
2019-12-29 20:42:02 -05:00
|
|
|
#
|
2021-07-01 17:35:29 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-28 23:38:53 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def cluster_status(zkhandler):
|
2019-12-29 20:42:02 -05:00
|
|
|
"""
|
|
|
|
Get the overall status of the PVC cluster
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_cluster.get_info(zkhandler)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-12-29 20:42:02 -05:00
|
|
|
return retdata, 200
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-28 23:38:53 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def cluster_maintenance(zkhandler, maint_state="false"):
|
2020-01-09 10:53:27 -05:00
|
|
|
"""
|
|
|
|
Set the cluster in or out of maintenance state
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_cluster.set_maintenance(zkhandler, maint_state)
|
2020-01-09 10:53:27 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2020-01-09 10:53:27 -05:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2023-12-08 11:45:52 -05:00
|
|
|
#
|
|
|
|
# Metrics functions
|
|
|
|
#
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
2023-12-20 16:14:28 -05:00
|
|
|
def cluster_health_metrics(zkhandler):
|
2023-12-08 11:45:52 -05:00
|
|
|
"""
|
2023-12-20 16:14:28 -05:00
|
|
|
Get cluster-wide Prometheus metrics for health
|
2023-12-08 11:45:52 -05:00
|
|
|
"""
|
|
|
|
|
2023-12-20 16:14:28 -05:00
|
|
|
retflag, retdata = pvc_cluster.get_health_metrics(zkhandler)
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def cluster_resource_metrics(zkhandler):
|
|
|
|
"""
|
|
|
|
Get cluster-wide Prometheus metrics for resource utilization
|
|
|
|
"""
|
|
|
|
|
|
|
|
retflag, retdata = pvc_cluster.get_resource_metrics(zkhandler)
|
2023-12-11 19:20:30 -05:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
return retdata, retcode
|
2023-12-09 02:52:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
2023-12-09 15:47:40 -05:00
|
|
|
def ceph_metrics(zkhandler):
|
2023-12-09 02:52:08 -05:00
|
|
|
"""
|
|
|
|
Obtain current Ceph Prometheus metrics from the active MGR
|
|
|
|
"""
|
|
|
|
# We have to parse out the *name* of the currently active MGR
|
|
|
|
# While the JSON version of the "ceph status" output provides a
|
|
|
|
# URL, this URL is in the backend (i.e. storage) network, which
|
|
|
|
# the API might not have access to. This way, we can connect to
|
|
|
|
# the node name which can be handled however.
|
|
|
|
retcode, retdata = pvc_ceph.get_status(zkhandler)
|
|
|
|
if not retcode:
|
|
|
|
ceph_mgr_node = None
|
|
|
|
else:
|
|
|
|
ceph_data = retdata["ceph_data"]
|
|
|
|
try:
|
|
|
|
ceph_mgr_line = [
|
|
|
|
n for n in ceph_data.split("\n") if match(r"^mgr:", n.strip())
|
|
|
|
][0]
|
|
|
|
ceph_mgr_node = ceph_mgr_line.split()[1].split("(")[0]
|
|
|
|
except Exception:
|
|
|
|
ceph_mgr_node = None
|
|
|
|
|
|
|
|
if ceph_mgr_node is not None:
|
|
|
|
# Get the data from the endpoint
|
|
|
|
# We use the default port of 9283
|
|
|
|
ceph_prometheus_uri = f"http://{ceph_mgr_node}:9283/metrics"
|
|
|
|
response = get(ceph_prometheus_uri)
|
|
|
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
output = response.text
|
2023-12-09 15:47:40 -05:00
|
|
|
status_code = 200
|
2023-12-09 02:52:08 -05:00
|
|
|
else:
|
|
|
|
output = (
|
|
|
|
f"Error: Failed to obtain metric data from {ceph_mgr_node} MGR daemon\n"
|
|
|
|
)
|
2023-12-09 15:47:40 -05:00
|
|
|
status_code = 400
|
2023-12-09 02:52:08 -05:00
|
|
|
else:
|
|
|
|
output = "Error: Failed to find an active MGR node\n"
|
2023-12-09 15:47:40 -05:00
|
|
|
status_code = 400
|
2023-12-09 02:52:08 -05:00
|
|
|
|
2023-12-09 15:47:40 -05:00
|
|
|
return output, status_code
|
2023-12-08 11:45:52 -05:00
|
|
|
|
|
|
|
|
2023-12-28 12:02:31 -05:00
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def zookeeper_metrics(zkhandler):
|
|
|
|
"""
|
|
|
|
Obtain current Zookeeper Prometheus metrics from the active coordinator node
|
|
|
|
"""
|
|
|
|
primary_node = zkhandler.read("base.config.primary_node")
|
|
|
|
if primary_node is not None:
|
|
|
|
# Get the data from the endpoint
|
|
|
|
# We use the default port of 9141
|
|
|
|
zookeeper_prometheus_uri = f"http://{primary_node}:9141/metrics"
|
|
|
|
response = get(zookeeper_prometheus_uri)
|
|
|
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
output = response.text
|
|
|
|
# Parse the text to remove annoying ports (":2181")
|
|
|
|
output = output.replace(":2181", "")
|
|
|
|
# Sort the output text
|
|
|
|
output_lines = output.split("\n")
|
|
|
|
output_lines.sort()
|
|
|
|
output = "\n".join(output_lines) + "\n"
|
|
|
|
status_code = 200
|
|
|
|
else:
|
|
|
|
output = f"Error: Failed to obtain metric data from {primary_node} primary node daemon\n"
|
|
|
|
status_code = 400
|
|
|
|
else:
|
|
|
|
output = "Error: Failed to find an active primary node\n"
|
|
|
|
status_code = 400
|
|
|
|
|
|
|
|
return output, status_code
|
|
|
|
|
|
|
|
|
2023-12-04 01:37:54 -05:00
|
|
|
#
|
|
|
|
# Fault functions
|
|
|
|
#
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def fault_list(zkhandler, limit=None, sort_key="last_reported"):
|
|
|
|
"""
|
|
|
|
Return a list of all faults sorted by SORT_KEY.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_faults.get_list(zkhandler, limit=limit, sort_key=sort_key)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
elif retflag and limit is not None and len(retdata) < 1:
|
|
|
|
retcode = 404
|
|
|
|
retdata = {"message": f"No fault with ID {limit} found"}
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
retdata = {"message": retdata}
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def fault_acknowledge(zkhandler, fault_id):
|
|
|
|
"""
|
|
|
|
Acknowledge a fault of FAULT_ID.
|
|
|
|
"""
|
2023-12-06 13:33:27 -05:00
|
|
|
retflag, retdata = pvc_faults.acknowledge(zkhandler, fault_id=fault_id)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
|
|
|
|
|
|
|
retdata = {"message": retdata}
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def fault_acknowledge_all(zkhandler):
|
|
|
|
"""
|
|
|
|
Acknowledge all faults.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_faults.acknowledge(zkhandler)
|
2023-12-04 01:37:54 -05:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
|
|
|
|
|
|
|
retdata = {"message": retdata}
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def fault_delete(zkhandler, fault_id):
|
|
|
|
"""
|
|
|
|
Delete a fault of FAULT_ID.
|
|
|
|
"""
|
2023-12-06 13:33:27 -05:00
|
|
|
retflag, retdata = pvc_faults.delete(zkhandler, fault_id=fault_id)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
|
|
|
|
|
|
|
retdata = {"message": retdata}
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def fault_delete_all(zkhandler):
|
|
|
|
"""
|
|
|
|
Delete all faults.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_faults.delete(zkhandler)
|
2023-12-04 01:37:54 -05:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
|
|
|
|
|
|
|
retdata = {"message": retdata}
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
#
|
|
|
|
# Node functions
|
|
|
|
#
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def node_list(
|
|
|
|
zkhandler,
|
|
|
|
limit=None,
|
|
|
|
daemon_state=None,
|
|
|
|
coordinator_state=None,
|
|
|
|
domain_state=None,
|
|
|
|
is_fuzzy=True,
|
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Return a list of nodes with limit LIMIT.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_node.get_list(
|
|
|
|
zkhandler,
|
|
|
|
limit,
|
|
|
|
daemon_state=daemon_state,
|
|
|
|
coordinator_state=coordinator_state,
|
|
|
|
domain_state=domain_state,
|
|
|
|
is_fuzzy=is_fuzzy,
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Node not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_daemon_state(zkhandler, node):
|
2019-07-28 23:31:59 -04:00
|
|
|
"""
|
|
|
|
Return the daemon state of node NODE.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.get_list(zkhandler, node, is_fuzzy=False)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-28 23:31:59 -04:00
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"name": node, "daemon_state": retdata[0]["daemon_state"]}
|
2019-07-28 23:31:59 -04:00
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Node not found."}
|
2019-07-28 23:31:59 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-28 23:31:59 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-28 23:31:59 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_coordinator_state(zkhandler, node):
|
2019-07-28 23:31:59 -04:00
|
|
|
"""
|
|
|
|
Return the coordinator state of node NODE.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.get_list(zkhandler, node, is_fuzzy=False)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-28 23:31:59 -04:00
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
retdata = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"name": node,
|
|
|
|
"coordinator_state": retdata[0]["coordinator_state"],
|
2019-07-28 23:31:59 -04:00
|
|
|
}
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Node not found."}
|
2019-07-28 23:31:59 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-28 23:31:59 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-28 23:31:59 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_domain_state(zkhandler, node):
|
2019-07-28 23:31:59 -04:00
|
|
|
"""
|
|
|
|
Return the domain state of node NODE.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.get_list(zkhandler, node, is_fuzzy=False)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-28 23:31:59 -04:00
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"name": node, "domain_state": retdata[0]["domain_state"]}
|
2019-07-28 23:31:59 -04:00
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Node not found."}
|
2019-07-28 23:31:59 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-28 23:31:59 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_secondary(zkhandler, node):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
2022-05-06 15:39:06 -04:00
|
|
|
Take NODE out of primary coordinator mode.
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.secondary_node(zkhandler, node)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_primary(zkhandler, node):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
2022-05-06 15:39:06 -04:00
|
|
|
Set NODE to primary coordinator mode.
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.primary_node(zkhandler, node)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_flush(zkhandler, node, wait):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Flush NODE of running VMs.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.flush_node(zkhandler, node, wait)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_ready(zkhandler, node, wait):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Restore NODE to active service.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_node.ready_node(zkhandler, node, wait)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-18 17:37:49 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def node_log(zkhandler, node, lines=None):
|
|
|
|
"""
|
|
|
|
Return the current logs for Node.
|
|
|
|
"""
|
|
|
|
# Default to 10 lines of log if not set
|
|
|
|
try:
|
|
|
|
lines = int(lines)
|
|
|
|
except TypeError:
|
|
|
|
lines = 10
|
|
|
|
|
|
|
|
retflag, retdata = pvc_node.get_node_log(zkhandler, node, lines)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"name": node, "data": retdata}
|
2021-07-18 17:37:49 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2021-07-18 17:37:49 -04:00
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
#
|
|
|
|
# VM functions
|
|
|
|
#
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_is_migrated(zkhandler, vm):
|
2019-07-25 15:42:17 -04:00
|
|
|
"""
|
|
|
|
Determine if a VM is migrated or not
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retdata = pvc_vm.is_migrated(zkhandler, vm)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-26 13:15:54 -04:00
|
|
|
return retdata
|
2019-07-25 15:42:17 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_state(zkhandler, vm):
|
2019-08-07 14:24:16 -04:00
|
|
|
"""
|
|
|
|
Return the state of virtual machine VM.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.get_list(
|
|
|
|
zkhandler, None, None, None, vm, is_fuzzy=False, negate=False
|
|
|
|
)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2019-08-07 14:24:16 -04:00
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"name": vm, "state": retdata["state"]}
|
2019-08-07 14:24:16 -04:00
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "VM not found."}
|
2019-08-07 14:24:16 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-08-07 14:24:16 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-08-07 14:24:16 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_node(zkhandler, vm):
|
2019-08-07 14:24:16 -04:00
|
|
|
"""
|
|
|
|
Return the current node of virtual machine VM.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.get_list(
|
|
|
|
zkhandler, None, None, None, vm, is_fuzzy=False, negate=False
|
|
|
|
)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2023-11-05 22:32:41 -05:00
|
|
|
if len(retdata) > 0:
|
|
|
|
retdata = retdata[0]
|
|
|
|
|
2019-08-07 14:24:16 -04:00
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
retdata = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"name": vm,
|
|
|
|
"node": retdata["node"],
|
|
|
|
"last_node": retdata["last_node"],
|
2019-08-07 14:24:16 -04:00
|
|
|
}
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "VM not found."}
|
2019-08-07 14:24:16 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-08-07 14:24:16 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-08-07 14:24:16 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_console(zkhandler, vm, lines=None):
|
2019-12-25 19:10:12 -05:00
|
|
|
"""
|
|
|
|
Return the current console log for VM.
|
|
|
|
"""
|
|
|
|
# Default to 10 lines of log if not set
|
2019-12-25 19:31:51 -05:00
|
|
|
try:
|
|
|
|
lines = int(lines)
|
|
|
|
except TypeError:
|
2019-12-25 19:10:12 -05:00
|
|
|
lines = 10
|
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.get_console_log(zkhandler, vm, lines)
|
2019-12-25 19:10:12 -05:00
|
|
|
|
|
|
|
if retflag:
|
2020-01-05 17:06:14 -05:00
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"name": vm, "data": retdata}
|
2019-12-25 19:10:12 -05:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-12-25 19:10:12 -05:00
|
|
|
|
2020-01-05 15:14:11 -05:00
|
|
|
return retdata, retcode
|
2019-12-25 19:10:12 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def vm_list(
|
|
|
|
zkhandler, node=None, state=None, tag=None, limit=None, is_fuzzy=True, negate=False
|
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Return a list of VMs with limit LIMIT.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.get_list(
|
|
|
|
zkhandler, node, state, tag, limit, is_fuzzy, negate
|
|
|
|
)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-05 18:24:14 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "VM not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def vm_define(
|
|
|
|
zkhandler,
|
|
|
|
xml,
|
|
|
|
node,
|
|
|
|
limit,
|
|
|
|
selector,
|
|
|
|
autostart,
|
|
|
|
migration_method,
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime=300,
|
2021-11-06 03:02:43 -04:00
|
|
|
user_tags=[],
|
|
|
|
protected_tags=[],
|
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Define a VM from Libvirt XML in the PVC cluster.
|
|
|
|
"""
|
2020-01-24 13:17:48 -05:00
|
|
|
# Verify our XML is sensible
|
|
|
|
try:
|
|
|
|
xml_data = etree.fromstring(xml)
|
2021-11-06 03:02:43 -04:00
|
|
|
new_cfg = etree.tostring(xml_data, pretty_print=True).decode("utf8")
|
2020-01-24 13:17:48 -05:00
|
|
|
except Exception as e:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "XML is malformed or incorrect: {}".format(e)}, 400
|
2020-01-24 13:17:48 -05:00
|
|
|
|
2021-07-13 19:04:56 -04:00
|
|
|
tags = list()
|
|
|
|
for tag in user_tags:
|
2021-11-06 03:02:43 -04:00
|
|
|
tags.append({"name": tag, "type": "user", "protected": False})
|
2021-07-13 19:04:56 -04:00
|
|
|
for tag in protected_tags:
|
2021-11-06 03:02:43 -04:00
|
|
|
tags.append({"name": tag, "type": "user", "protected": True})
|
2021-07-13 19:04:56 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.define_vm(
|
|
|
|
zkhandler,
|
|
|
|
new_cfg,
|
|
|
|
node,
|
|
|
|
limit,
|
|
|
|
selector,
|
|
|
|
autostart,
|
|
|
|
migration_method,
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime,
|
2021-11-06 03:02:43 -04:00
|
|
|
profile=None,
|
|
|
|
tags=tags,
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2023-10-17 10:15:06 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_backup(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path,
|
2023-10-17 10:15:06 -04:00
|
|
|
incremental_parent=None,
|
2023-10-24 00:23:12 -04:00
|
|
|
retain_snapshot=False,
|
2023-10-17 10:15:06 -04:00
|
|
|
):
|
|
|
|
"""
|
|
|
|
Back up a VM to a local (primary coordinator) filesystem path.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_vm.backup_vm(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path,
|
2023-10-17 10:15:06 -04:00
|
|
|
incremental_parent,
|
2023-10-24 00:23:12 -04:00
|
|
|
retain_snapshot,
|
2023-10-17 10:15:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2023-10-24 01:08:36 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_remove_backup(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
|
|
|
source_path,
|
|
|
|
datestring,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Remove a VM backup from snapshots and a local (primary coordinator) filesystem path.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_vm.remove_backup(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
|
|
|
source_path,
|
|
|
|
datestring,
|
|
|
|
)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2023-10-23 22:23:17 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_restore(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path,
|
2023-10-23 22:23:17 -04:00
|
|
|
datestring,
|
2023-10-24 00:23:12 -04:00
|
|
|
retain_snapshot=False,
|
2023-10-23 22:23:17 -04:00
|
|
|
):
|
|
|
|
"""
|
|
|
|
Restore a VM from a local (primary coordinator) filesystem path.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_vm.restore_vm(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path,
|
2023-10-23 22:23:17 -04:00
|
|
|
datestring,
|
2023-10-24 00:23:12 -04:00
|
|
|
retain_snapshot,
|
2023-10-23 22:23:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2024-05-16 09:23:31 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def create_vm_snapshot(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
|
|
|
snapshot_name=None,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Take a snapshot of a VM.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_vm.create_vm_snapshot(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
|
|
|
snapshot_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2024-05-17 10:55:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def remove_vm_snapshot(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
|
|
|
snapshot_name,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Take a snapshot of a VM.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_vm.remove_vm_snapshot(
|
|
|
|
zkhandler,
|
|
|
|
domain,
|
|
|
|
snapshot_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-09-12 15:41:05 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_attach_device(zkhandler, vm, device_spec_xml):
|
|
|
|
"""
|
|
|
|
Hot-attach a device (via XML spec) to a VM.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
_ = etree.fromstring(device_spec_xml)
|
|
|
|
except Exception as e:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "XML is malformed or incorrect: {}".format(e)}, 400
|
2021-09-12 15:41:05 -04:00
|
|
|
|
|
|
|
retflag, retdata = pvc_vm.attach_vm_device(zkhandler, vm, device_spec_xml)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2021-09-12 15:41:05 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "WARNING: Failed to perform hot attach; device will be added on next VM start/restart."
|
2021-09-12 15:41:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_detach_device(zkhandler, vm, device_spec_xml):
|
|
|
|
"""
|
|
|
|
Hot-detach a device (via XML spec) from a VM.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
_ = etree.fromstring(device_spec_xml)
|
|
|
|
except Exception as e:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "XML is malformed or incorrect: {}".format(e)}, 400
|
2021-09-12 15:41:05 -04:00
|
|
|
|
|
|
|
retflag, retdata = pvc_vm.detach_vm_device(zkhandler, vm, device_spec_xml)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2021-09-12 15:41:05 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "WARNING: Failed to perform hot detach; device will be removed on next VM start/restart."
|
2021-09-12 15:41:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def get_vm_meta(zkhandler, vm):
|
2019-12-23 20:43:20 -05:00
|
|
|
"""
|
|
|
|
Get metadata of a VM.
|
|
|
|
"""
|
2021-07-13 02:08:54 -04:00
|
|
|
dom_uuid = pvc_vm.getDomainUUID(zkhandler, vm)
|
|
|
|
if not dom_uuid:
|
|
|
|
return {"message": "VM not found."}, 404
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
(
|
|
|
|
domain_node_limit,
|
|
|
|
domain_node_selector,
|
|
|
|
domain_node_autostart,
|
|
|
|
domain_migrate_method,
|
2024-01-10 16:13:31 -05:00
|
|
|
domain_migrate_max_downtime,
|
2021-11-06 03:02:43 -04:00
|
|
|
) = pvc_common.getDomainMetadata(zkhandler, dom_uuid)
|
2021-07-13 02:08:54 -04:00
|
|
|
|
|
|
|
retcode = 200
|
|
|
|
retdata = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"name": vm,
|
2022-11-07 12:26:50 -05:00
|
|
|
"node_limit": domain_node_limit,
|
2022-11-07 11:59:53 -05:00
|
|
|
"node_selector": domain_node_selector.lower(),
|
2021-11-06 03:02:43 -04:00
|
|
|
"node_autostart": domain_node_autostart,
|
2022-11-07 11:59:53 -05:00
|
|
|
"migration_method": domain_migrate_method.lower(),
|
2024-01-10 16:13:31 -05:00
|
|
|
"migration_max_downtime": int(domain_migrate_max_downtime),
|
2021-07-13 02:08:54 -04:00
|
|
|
}
|
2019-12-23 20:43:20 -05:00
|
|
|
|
|
|
|
return retdata, retcode
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def update_vm_meta(
|
2024-01-10 16:13:31 -05:00
|
|
|
zkhandler,
|
|
|
|
vm,
|
|
|
|
limit,
|
|
|
|
selector,
|
|
|
|
autostart,
|
|
|
|
provisioner_profile,
|
|
|
|
migration_method,
|
|
|
|
migration_max_downtime,
|
2021-11-06 03:02:43 -04:00
|
|
|
):
|
2019-10-12 01:17:39 -04:00
|
|
|
"""
|
|
|
|
Update metadata of a VM.
|
|
|
|
"""
|
2021-07-13 02:17:30 -04:00
|
|
|
dom_uuid = pvc_vm.getDomainUUID(zkhandler, vm)
|
|
|
|
if not dom_uuid:
|
|
|
|
return {"message": "VM not found."}, 404
|
|
|
|
|
2020-01-30 11:45:46 -05:00
|
|
|
if autostart is not None:
|
|
|
|
try:
|
|
|
|
autostart = bool(strtobool(autostart))
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-01-30 11:45:46 -05:00
|
|
|
autostart = False
|
2021-07-13 02:08:54 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.modify_vm_metadata(
|
2024-01-10 16:13:31 -05:00
|
|
|
zkhandler,
|
|
|
|
vm,
|
|
|
|
limit,
|
|
|
|
selector,
|
|
|
|
autostart,
|
|
|
|
provisioner_profile,
|
|
|
|
migration_method,
|
|
|
|
migration_max_downtime,
|
2021-11-06 03:02:43 -04:00
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-10-12 01:17:39 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-10-12 01:17:39 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-13 02:17:30 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def get_vm_tags(zkhandler, vm):
|
|
|
|
"""
|
|
|
|
Get the tags of a VM.
|
|
|
|
"""
|
|
|
|
dom_uuid = pvc_vm.getDomainUUID(zkhandler, vm)
|
|
|
|
if not dom_uuid:
|
|
|
|
return {"message": "VM not found."}, 404
|
|
|
|
|
|
|
|
tags = pvc_common.getDomainTags(zkhandler, dom_uuid)
|
|
|
|
|
|
|
|
retcode = 200
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"name": vm, "tags": tags}
|
2021-07-13 02:17:30 -04:00
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@ZKConnection(config)
|
2021-07-13 19:04:56 -04:00
|
|
|
def update_vm_tag(zkhandler, vm, action, tag, protected=False):
|
2021-07-13 02:17:30 -04:00
|
|
|
"""
|
2021-07-13 19:04:56 -04:00
|
|
|
Update a tag of a VM.
|
2021-07-13 02:17:30 -04:00
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if action not in ["add", "remove"]:
|
2021-07-13 19:04:56 -04:00
|
|
|
return {"message": "Tag action must be one of 'add', 'remove'."}, 400
|
2021-07-13 02:17:30 -04:00
|
|
|
|
|
|
|
dom_uuid = pvc_vm.getDomainUUID(zkhandler, vm)
|
|
|
|
if not dom_uuid:
|
|
|
|
return {"message": "VM not found."}, 404
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.modify_vm_tag(
|
|
|
|
zkhandler, vm, action, tag, protected=protected
|
|
|
|
)
|
2021-07-13 02:17:30 -04:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2021-07-13 02:17:30 -04:00
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_modify(zkhandler, name, restart, xml):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Modify a VM Libvirt XML in the PVC cluster.
|
|
|
|
"""
|
2020-01-24 13:17:48 -05:00
|
|
|
# Verify our XML is sensible
|
|
|
|
try:
|
|
|
|
xml_data = etree.fromstring(xml)
|
2021-11-06 03:02:43 -04:00
|
|
|
new_cfg = etree.tostring(xml_data, pretty_print=True).decode("utf8")
|
2020-01-24 13:17:48 -05:00
|
|
|
except Exception as e:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "XML is malformed or incorrect: {}".format(e)}, 400
|
2021-05-29 00:16:26 -04:00
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.modify_vm(zkhandler, name, restart, new_cfg)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2021-05-23 16:41:42 -04:00
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_rename(zkhandler, name, new_name):
|
2021-05-23 16:41:42 -04:00
|
|
|
"""
|
|
|
|
Rename a VM in the PVC cluster.
|
|
|
|
"""
|
|
|
|
if new_name is None:
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": "A new VM name must be specified"}
|
2021-05-23 16:41:42 -04:00
|
|
|
return 400, output
|
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
if pvc_vm.searchClusterByName(zkhandler, new_name) is not None:
|
2021-05-23 16:41:42 -04:00
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "A VM named '{}' is already present in the cluster".format(
|
|
|
|
new_name
|
|
|
|
)
|
2021-05-23 16:41:42 -04:00
|
|
|
}
|
|
|
|
return 400, output
|
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.rename_vm(zkhandler, name, new_name)
|
2021-05-23 16:41:42 -04:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_undefine(zkhandler, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Undefine a VM from the PVC cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.undefine_vm(zkhandler, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_remove(zkhandler, name):
|
2019-07-05 18:24:14 -04:00
|
|
|
"""
|
|
|
|
Remove a VM from the PVC cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.remove_vm(zkhandler, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_start(zkhandler, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Start a VM in the PVC cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.start_vm(zkhandler, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:53:44 -04:00
|
|
|
def vm_restart(zkhandler, name, wait=False):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Restart a VM in the PVC cluster.
|
|
|
|
"""
|
2021-11-06 03:53:44 -04:00
|
|
|
retflag, retdata = pvc_vm.restart_vm(zkhandler, name, wait=wait)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_shutdown(zkhandler, name, wait):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Shutdown a VM in the PVC cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.shutdown_vm(zkhandler, name, wait)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_stop(zkhandler, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Forcibly stop a VM in the PVC cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.stop_vm(zkhandler, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:53:44 -04:00
|
|
|
def vm_disable(zkhandler, name, force=False):
|
2020-01-05 14:38:14 -05:00
|
|
|
"""
|
2021-11-06 03:53:44 -04:00
|
|
|
Disable (shutdown or force stop if required)a VM in the PVC cluster.
|
2020-01-05 14:38:14 -05:00
|
|
|
"""
|
2021-11-06 03:53:44 -04:00
|
|
|
retflag, retdata = pvc_vm.disable_vm(zkhandler, name, force=force)
|
2020-01-05 14:38:14 -05:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2020-01-05 14:38:14 -05:00
|
|
|
return output, retcode
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_move(zkhandler, name, node, wait, force_live):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Move a VM to another node.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.move_vm(zkhandler, name, node, wait, force_live)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_migrate(zkhandler, name, node, flag_force, wait, force_live):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Temporarily migrate a VM to another node.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.migrate_vm(
|
|
|
|
zkhandler, name, node, flag_force, wait, force_live
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_unmigrate(zkhandler, name, wait, force_live):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Unmigrate a migrated VM.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.unmigrate_vm(zkhandler, name, wait, force_live)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 18:24:14 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 18:24:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:16:26 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def vm_flush_locks(zkhandler, vm):
|
2019-08-07 14:24:16 -04:00
|
|
|
"""
|
|
|
|
Flush locks of a (stopped) VM.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_vm.get_list(
|
|
|
|
zkhandler, None, None, None, vm, is_fuzzy=False, negate=False
|
|
|
|
)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if retdata[0].get("state") not in ["stop", "disable"]:
|
2020-11-07 12:34:47 -05:00
|
|
|
return {"message": "VM must be stopped to flush locks"}, 400
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_vm.flush_locks(zkhandler, vm)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-08-07 14:24:16 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-08-07 14:24:16 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
#
|
|
|
|
# Network functions
|
|
|
|
#
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_list(zkhandler, limit=None, is_fuzzy=True):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Return a list of client networks with limit LIMIT.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_network.get_list(zkhandler, limit, is_fuzzy)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Network not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def net_add(
|
|
|
|
zkhandler,
|
|
|
|
vni,
|
|
|
|
description,
|
|
|
|
nettype,
|
|
|
|
mtu,
|
|
|
|
domain,
|
|
|
|
name_servers,
|
|
|
|
ip4_network,
|
|
|
|
ip4_gateway,
|
|
|
|
ip6_network,
|
|
|
|
ip6_gateway,
|
|
|
|
dhcp4_flag,
|
|
|
|
dhcp4_start,
|
|
|
|
dhcp4_end,
|
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add a virtual client network to the PVC cluster.
|
|
|
|
"""
|
2020-01-06 15:37:53 -05:00
|
|
|
if dhcp4_flag:
|
|
|
|
dhcp4_flag = bool(strtobool(dhcp4_flag))
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.add_network(
|
|
|
|
zkhandler,
|
|
|
|
vni,
|
|
|
|
description,
|
|
|
|
nettype,
|
|
|
|
mtu,
|
|
|
|
domain,
|
|
|
|
name_servers,
|
|
|
|
ip4_network,
|
|
|
|
ip4_gateway,
|
|
|
|
ip6_network,
|
|
|
|
ip6_gateway,
|
|
|
|
dhcp4_flag,
|
|
|
|
dhcp4_start,
|
|
|
|
dhcp4_end,
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def net_modify(
|
|
|
|
zkhandler,
|
|
|
|
vni,
|
|
|
|
description,
|
|
|
|
mtu,
|
|
|
|
domain,
|
|
|
|
name_servers,
|
|
|
|
ip4_network,
|
|
|
|
ip4_gateway,
|
|
|
|
ip6_network,
|
|
|
|
ip6_gateway,
|
|
|
|
dhcp4_flag,
|
|
|
|
dhcp4_start,
|
|
|
|
dhcp4_end,
|
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Modify a virtual client network in the PVC cluster.
|
|
|
|
"""
|
2020-01-30 09:38:02 -05:00
|
|
|
if dhcp4_flag is not None:
|
2020-01-06 15:37:53 -05:00
|
|
|
dhcp4_flag = bool(strtobool(dhcp4_flag))
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.modify_network(
|
|
|
|
zkhandler,
|
|
|
|
vni,
|
|
|
|
description,
|
|
|
|
mtu,
|
|
|
|
domain,
|
|
|
|
name_servers,
|
|
|
|
ip4_network,
|
|
|
|
ip4_gateway,
|
|
|
|
ip6_network,
|
|
|
|
ip6_gateway,
|
|
|
|
dhcp4_flag,
|
|
|
|
dhcp4_start,
|
|
|
|
dhcp4_end,
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_remove(zkhandler, network):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Remove a virtual client network from the PVC cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_network.remove_network(zkhandler, network)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_dhcp_list(zkhandler, network, limit=None, static=False):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Return a list of DHCP leases in network NETWORK with limit LIMIT.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_network.get_list_dhcp(zkhandler, network, limit, static)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Lease not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_dhcp_add(zkhandler, network, ipaddress, macaddress, hostname):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add a static DHCP lease to a virtual client network.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.add_dhcp_reservation(
|
|
|
|
zkhandler, network, ipaddress, macaddress, hostname
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_dhcp_remove(zkhandler, network, macaddress):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Remove a static DHCP lease from a virtual client network.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.remove_dhcp_reservation(
|
|
|
|
zkhandler, network, macaddress
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_acl_list(zkhandler, network, limit=None, direction=None, is_fuzzy=True):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Return a list of network ACLs in network NETWORK with limit LIMIT.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.get_list_acl(
|
|
|
|
zkhandler, network, limit, direction, is_fuzzy=True
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "ACL not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_acl_add(zkhandler, network, direction, description, rule, order):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add an ACL to a virtual client network.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.add_acl(
|
|
|
|
zkhandler, network, direction, description, rule, order
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def net_acl_remove(zkhandler, network, description):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Remove an ACL from a virtual client network.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_network.remove_acl(zkhandler, network, description)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 21:39:04 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 21:39:04 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-06-21 01:42:55 -04:00
|
|
|
#
|
|
|
|
# SR-IOV functions
|
|
|
|
#
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-06-21 01:42:55 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def sriov_pf_list(zkhandler, node):
|
|
|
|
"""
|
|
|
|
List all PFs on a given node.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_network.get_list_sriov_pf(zkhandler, node)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "PF not found."}
|
2021-06-21 01:42:55 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-06-21 01:42:55 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def sriov_vf_list(zkhandler, node, pf=None):
|
|
|
|
"""
|
|
|
|
List all VFs on a given node, optionally limited to PF.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_network.get_list_sriov_vf(zkhandler, node, pf)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "VF not found."}
|
2021-06-21 01:42:55 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
2021-06-21 18:40:11 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def update_sriov_vf_config(
|
|
|
|
zkhandler,
|
|
|
|
node,
|
|
|
|
vf,
|
|
|
|
vlan_id,
|
|
|
|
vlan_qos,
|
|
|
|
tx_rate_min,
|
|
|
|
tx_rate_max,
|
|
|
|
link_state,
|
|
|
|
spoof_check,
|
|
|
|
trust,
|
|
|
|
query_rss,
|
|
|
|
):
|
2021-06-21 18:40:11 -04:00
|
|
|
"""
|
|
|
|
Update configuration of a VF on NODE.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_network.set_sriov_vf_config(
|
|
|
|
zkhandler,
|
|
|
|
node,
|
|
|
|
vf,
|
|
|
|
vlan_id,
|
|
|
|
vlan_qos,
|
|
|
|
tx_rate_min,
|
|
|
|
tx_rate_max,
|
|
|
|
link_state,
|
|
|
|
spoof_check,
|
|
|
|
trust,
|
|
|
|
query_rss,
|
|
|
|
)
|
2021-06-21 18:40:11 -04:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2021-06-21 18:40:11 -04:00
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
#
|
|
|
|
# Ceph functions
|
|
|
|
#
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_status(zkhandler):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Get the current Ceph cluster status.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_status(zkhandler)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_util(zkhandler):
|
2019-07-08 10:56:33 -04:00
|
|
|
"""
|
|
|
|
Get the current Ceph cluster utilization.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_util(zkhandler)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-08 10:56:33 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-08 10:56:33 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-08 10:56:33 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_list(zkhandler, limit=None):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Get the list of OSDs in the Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_list_osd(zkhandler, limit)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "OSD not found."}
|
2023-11-09 14:05:15 -05:00
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
retdata = {"message": retdata}
|
|
|
|
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@pvc_common.Profiler(config)
|
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_node(zkhandler, osd):
|
|
|
|
"""
|
|
|
|
Return the current node of OSD OSD.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_ceph.get_list_osd(zkhandler, None)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
if retdata:
|
|
|
|
osd = [o for o in retdata if o["id"] == osd]
|
|
|
|
if len(osd) < 1:
|
|
|
|
retcode = 404
|
|
|
|
retdata = {"message": "OSD not found."}
|
|
|
|
else:
|
|
|
|
retcode = 200
|
|
|
|
retdata = {
|
|
|
|
"id": osd[0]["id"],
|
|
|
|
"node": osd[0]["node"],
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
retcode = 404
|
|
|
|
retdata = {"message": "OSD not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_state(zkhandler, osd):
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_list_osd(zkhandler, osd)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-26 11:23:19 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "OSD not found."}
|
2019-07-26 11:23:19 -04:00
|
|
|
else:
|
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-26 11:23:19 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
in_state = retdata[0]["stats"]["in"]
|
|
|
|
up_state = retdata[0]["stats"]["up"]
|
2019-07-26 11:23:19 -04:00
|
|
|
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"id": osd, "in": in_state, "up": up_state}, retcode
|
2019-07-26 11:23:19 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2021-09-23 13:59:49 -04:00
|
|
|
def ceph_osd_db_vg_add(zkhandler, node, device):
|
|
|
|
"""
|
|
|
|
Add a Ceph OSD database VG to the PVC Ceph storage cluster.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_ceph.add_osd_db_vg(zkhandler, node, device)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2021-09-23 13:59:49 -04:00
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@ZKConnection(config)
|
2023-11-01 21:17:38 -04:00
|
|
|
def ceph_osd_add(
|
|
|
|
zkhandler,
|
|
|
|
node,
|
|
|
|
device,
|
|
|
|
weight,
|
2023-11-02 13:29:47 -04:00
|
|
|
ext_db_ratio=None,
|
|
|
|
ext_db_size=None,
|
|
|
|
split_count=None,
|
2023-11-01 21:17:38 -04:00
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add a Ceph OSD to the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_ceph.add_osd(
|
2023-11-01 21:17:38 -04:00
|
|
|
zkhandler,
|
|
|
|
node,
|
|
|
|
device,
|
|
|
|
weight,
|
|
|
|
ext_db_ratio,
|
2023-11-02 13:29:47 -04:00
|
|
|
ext_db_size,
|
2023-11-01 21:17:38 -04:00
|
|
|
split_count,
|
2021-11-06 03:02:43 -04:00
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2022-05-06 15:31:58 -04:00
|
|
|
@ZKConnection(config)
|
2023-11-03 01:45:49 -04:00
|
|
|
def ceph_osd_replace(
|
|
|
|
zkhandler,
|
|
|
|
osd_id,
|
|
|
|
new_device,
|
|
|
|
old_device=None,
|
|
|
|
weight=None,
|
|
|
|
ext_db_ratio=None,
|
|
|
|
ext_db_size=None,
|
|
|
|
):
|
2022-05-06 15:31:58 -04:00
|
|
|
"""
|
|
|
|
Replace a Ceph OSD in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2023-11-03 01:45:49 -04:00
|
|
|
retflag, retdata = pvc_ceph.replace_osd(
|
|
|
|
zkhandler, osd_id, new_device, old_device, weight, ext_db_ratio, ext_db_size
|
|
|
|
)
|
2022-05-06 15:31:58 -04:00
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_refresh(zkhandler, osd_id, device):
|
|
|
|
"""
|
|
|
|
Refresh (reimport) a Ceph OSD in the PVC Ceph storage cluster.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_ceph.refresh_osd(zkhandler, osd_id, device)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2022-04-29 11:16:33 -04:00
|
|
|
def ceph_osd_remove(zkhandler, osd_id, force_flag):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Remove a Ceph OSD from the PVC Ceph storage cluster.
|
|
|
|
"""
|
2022-04-29 11:16:33 -04:00
|
|
|
retflag, retdata = pvc_ceph.remove_osd(zkhandler, osd_id, force_flag)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_in(zkhandler, osd_id):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Set in a Ceph OSD in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.in_osd(zkhandler, osd_id)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_out(zkhandler, osd_id):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Set out a Ceph OSD in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.out_osd(zkhandler, osd_id)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_set(zkhandler, option):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Set options on a Ceph OSD in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.set_osd(zkhandler, option)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_osd_unset(zkhandler, option):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Unset options on a Ceph OSD in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.unset_osd(zkhandler, option)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_pool_list(zkhandler, limit=None, is_fuzzy=True):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Get the list of RBD pools in the Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_list_pool(zkhandler, limit, is_fuzzy)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Pool not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2021-12-28 20:39:50 -05:00
|
|
|
def ceph_pool_add(zkhandler, name, pgs, replcfg, tier=None):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add a Ceph RBD pool to the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-12-28 20:39:50 -05:00
|
|
|
retflag, retdata = pvc_ceph.add_pool(zkhandler, name, pgs, replcfg, tier)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_pool_remove(zkhandler, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Remove a Ceph RBD pool to the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.remove_pool(zkhandler, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-12-28 21:41:41 -05:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_pool_set_pgs(zkhandler, name, pgs):
|
|
|
|
"""
|
|
|
|
Set the PGs of a ceph RBD pool.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_ceph.set_pgs_pool(zkhandler, name, pgs)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_list(zkhandler, pool=None, limit=None, is_fuzzy=True):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Get the list of RBD volumes in the Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_list_volume(zkhandler, pool, limit, is_fuzzy)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Volume not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2024-02-02 10:13:46 -05:00
|
|
|
def ceph_volume_add(zkhandler, pool, name, size, force_flag):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add a Ceph RBD volume to the PVC Ceph storage cluster.
|
|
|
|
"""
|
2024-02-02 10:13:46 -05:00
|
|
|
retflag, retdata = pvc_ceph.add_volume(
|
|
|
|
zkhandler, pool, name, size, force_flag=force_flag
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2024-02-02 10:29:34 -05:00
|
|
|
def ceph_volume_clone(zkhandler, pool, name, source_volume, force_flag):
|
2019-10-10 14:37:35 -04:00
|
|
|
"""
|
|
|
|
Clone a Ceph RBD volume to a new volume on the PVC Ceph storage cluster.
|
|
|
|
"""
|
2024-02-02 10:29:34 -05:00
|
|
|
retflag, retdata = pvc_ceph.clone_volume(
|
|
|
|
zkhandler, pool, source_volume, name, force_flag=force_flag
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-10-10 14:37:35 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-10-10 14:37:35 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2024-02-02 10:13:46 -05:00
|
|
|
def ceph_volume_resize(zkhandler, pool, name, size, force_flag):
|
2019-07-26 14:24:22 -04:00
|
|
|
"""
|
|
|
|
Resize an existing Ceph RBD volume in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2024-02-02 10:13:46 -05:00
|
|
|
retflag, retdata = pvc_ceph.resize_volume(
|
|
|
|
zkhandler, pool, name, size, force_flag=force_flag
|
|
|
|
)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-26 14:24:22 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-26 14:24:22 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_rename(zkhandler, pool, name, new_name):
|
2019-07-26 14:24:22 -04:00
|
|
|
"""
|
|
|
|
Rename a Ceph RBD volume in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.rename_volume(zkhandler, pool, name, new_name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-26 14:24:22 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-26 14:24:22 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_remove(zkhandler, pool, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Remove a Ceph RBD volume to the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.remove_volume(zkhandler, pool, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2023-09-29 16:13:08 -04:00
|
|
|
def ceph_volume_upload(zkhandler, pool, volume, img_type, file_size=None):
|
2020-02-09 13:43:48 -05:00
|
|
|
"""
|
|
|
|
Upload a raw file via HTTP post to a PVC Ceph volume
|
|
|
|
"""
|
2020-02-09 19:43:07 -05:00
|
|
|
# Determine the image conversion options
|
2021-11-06 03:02:43 -04:00
|
|
|
if img_type not in ["raw", "vmdk", "qcow2", "qed", "vdi", "vpc"]:
|
|
|
|
output = {"message": "Image type '{}' is not valid.".format(img_type)}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 400
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
# Get the size of the target block device
|
2021-05-28 23:33:36 -04:00
|
|
|
retcode, retdata = pvc_ceph.get_list_volume(zkhandler, pool, volume, is_fuzzy=False)
|
2020-02-09 19:43:07 -05:00
|
|
|
# If there's no target, return failure
|
|
|
|
if not retcode or len(retdata) < 1:
|
2020-02-09 13:43:48 -05:00
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "Target volume '{}' does not exist in pool '{}'.".format(
|
|
|
|
volume, pool
|
|
|
|
)
|
2020-02-09 13:43:48 -05:00
|
|
|
}
|
|
|
|
retcode = 400
|
|
|
|
return output, retcode
|
2023-09-29 16:13:08 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
dev_size = retdata[0]["stats"]["size"]
|
|
|
|
except Exception:
|
|
|
|
output = {
|
|
|
|
"message": "Target volume '{}' does not exist in pool '{}'.".format(
|
|
|
|
volume, pool
|
|
|
|
)
|
|
|
|
}
|
|
|
|
retcode = 400
|
|
|
|
return output, retcode
|
2020-02-09 19:43:07 -05:00
|
|
|
|
|
|
|
def cleanup_maps_and_volumes():
|
|
|
|
# Unmap the target blockdev
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.unmap_volume(zkhandler, pool, volume)
|
2020-02-09 19:43:07 -05:00
|
|
|
# Unmap the temporary blockdev
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_ceph.unmap_volume(
|
|
|
|
zkhandler, pool, "{}_tmp".format(volume)
|
|
|
|
)
|
2020-02-09 19:43:07 -05:00
|
|
|
# Remove the temporary blockdev
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_ceph.remove_volume(
|
|
|
|
zkhandler, pool, "{}_tmp".format(volume)
|
|
|
|
)
|
2020-02-09 19:43:07 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if img_type == "raw":
|
2023-09-29 16:13:08 -04:00
|
|
|
if file_size != dev_size:
|
|
|
|
output = {
|
|
|
|
"message": f"Image file size {file_size} does not match volume size {dev_size}"
|
|
|
|
}
|
|
|
|
retcode = 400
|
|
|
|
return output, retcode
|
|
|
|
|
2020-02-09 19:43:07 -05:00
|
|
|
# Map the target blockdev
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.map_volume(zkhandler, pool, volume)
|
2020-02-09 19:43:07 -05:00
|
|
|
if not retflag:
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
|
|
|
dest_blockdev = retdata
|
2020-02-09 13:43:48 -05:00
|
|
|
|
2020-02-09 19:43:07 -05:00
|
|
|
# Save the data to the blockdev directly
|
|
|
|
try:
|
2020-11-07 13:26:12 -05:00
|
|
|
# This sets up a custom stream_factory that writes directly into the ova_blockdev,
|
|
|
|
# rather than the standard stream_factory which writes to a temporary file waiting
|
|
|
|
# on a save() call. This will break if the API ever uploaded multiple files, but
|
|
|
|
# this is an acceptable workaround.
|
2021-11-06 03:02:43 -04:00
|
|
|
def image_stream_factory(
|
|
|
|
total_content_length, filename, content_type, content_length=None
|
|
|
|
):
|
|
|
|
return open(dest_blockdev, "wb")
|
|
|
|
|
2020-11-07 13:26:12 -05:00
|
|
|
parse_form_data(flask.request.environ, stream_factory=image_stream_factory)
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-02-09 19:43:07 -05:00
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "Failed to upload or write image file to temporary volume."
|
2020-02-09 19:43:07 -05:00
|
|
|
}
|
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
2020-02-09 13:43:48 -05:00
|
|
|
|
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "Wrote uploaded file to volume '{}' in pool '{}'.".format(
|
|
|
|
volume, pool
|
|
|
|
)
|
2020-02-09 13:43:48 -05:00
|
|
|
}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 200
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
else:
|
2023-09-29 16:13:08 -04:00
|
|
|
if file_size is None:
|
|
|
|
output = {"message": "A file size must be specified"}
|
|
|
|
retcode = 400
|
|
|
|
return output, retcode
|
|
|
|
|
2020-02-09 19:43:07 -05:00
|
|
|
# Create a temporary blockdev
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_ceph.add_volume(
|
2023-09-29 16:13:08 -04:00
|
|
|
zkhandler, pool, "{}_tmp".format(volume), file_size
|
2021-11-06 03:02:43 -04:00
|
|
|
)
|
2020-02-09 19:43:07 -05:00
|
|
|
if not retflag:
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
# Map the temporary target blockdev
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.map_volume(zkhandler, pool, "{}_tmp".format(volume))
|
2020-02-09 19:43:07 -05:00
|
|
|
if not retflag:
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
|
|
|
temp_blockdev = retdata
|
|
|
|
|
|
|
|
# Map the target blockdev
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.map_volume(zkhandler, pool, volume)
|
2020-02-09 19:43:07 -05:00
|
|
|
if not retflag:
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
|
|
|
dest_blockdev = retdata
|
|
|
|
|
|
|
|
# Save the data to the temporary blockdev directly
|
|
|
|
try:
|
Improve handling of large file uploads
By default, Werkzeug would require the entire file (be it an OVA or
image file) to be uploaded and saved to a temporary, fake file under
`/tmp`, before any further processing could occur. This blocked most of
the execution of these functions until the upload was completed.
This entirely defeated the purpose of what I was trying to do, which was
to save the uploads directly to the temporary blockdev in each case,
thus avoiding any sort of memory or (host) disk usage.
The solution is two-fold:
1. First, ensure that the `location='args'` value is set in
RequestParser; without this, the `files` portion would be parsed
during the argument parsing, which was the original source of this
blocking behaviour.
2. Instead of the convoluted request handling that was being done
originally here, instead entirely defer the parsing of the `files`
arguments until the point in the code where they are ready to be
saved. Then, using an override stream_factory that simply opens the
temporary blockdev, the upload can commence while being written
directly out to it, rather than using `/tmp` space.
This does alter the error handling slightly; it is impossible to check
if the argument was passed until this point in the code, so it may take
longer to fail if the API consumer does not specify a file as they
should. This is a minor trade-off and I would expect my API consumers to
be sane here.
2020-10-19 00:47:56 -04:00
|
|
|
# This sets up a custom stream_factory that writes directly into the ova_blockdev,
|
|
|
|
# rather than the standard stream_factory which writes to a temporary file waiting
|
|
|
|
# on a save() call. This will break if the API ever uploaded multiple files, but
|
|
|
|
# this is an acceptable workaround.
|
2021-11-06 03:02:43 -04:00
|
|
|
def image_stream_factory(
|
|
|
|
total_content_length, filename, content_type, content_length=None
|
|
|
|
):
|
|
|
|
return open(temp_blockdev, "wb")
|
|
|
|
|
2020-11-09 09:45:54 -05:00
|
|
|
parse_form_data(flask.request.environ, stream_factory=image_stream_factory)
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-02-09 19:43:07 -05:00
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "Failed to upload or write image file to temporary volume."
|
2020-02-09 19:43:07 -05:00
|
|
|
}
|
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
# Convert from the temporary to destination format on the blockdevs
|
|
|
|
retcode, stdout, stderr = pvc_common.run_os_command(
|
2021-11-06 03:02:43 -04:00
|
|
|
"qemu-img convert -C -f {} -O raw {} {}".format(
|
|
|
|
img_type, temp_blockdev, dest_blockdev
|
|
|
|
)
|
2020-02-09 19:43:07 -05:00
|
|
|
)
|
|
|
|
if retcode:
|
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "Failed to convert image format from '{}' to 'raw': {}".format(
|
|
|
|
img_type, stderr
|
|
|
|
)
|
2020-02-09 19:43:07 -05:00
|
|
|
}
|
|
|
|
retcode = 400
|
|
|
|
cleanup_maps_and_volumes()
|
|
|
|
return output, retcode
|
2020-02-09 13:43:48 -05:00
|
|
|
|
|
|
|
output = {
|
2021-11-06 03:02:43 -04:00
|
|
|
"message": "Converted and wrote uploaded file to volume '{}' in pool '{}'.".format(
|
|
|
|
volume, pool
|
|
|
|
)
|
2020-02-09 13:43:48 -05:00
|
|
|
}
|
2020-02-09 19:43:07 -05:00
|
|
|
retcode = 200
|
|
|
|
cleanup_maps_and_volumes()
|
2020-02-09 13:43:48 -05:00
|
|
|
return output, retcode
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-02 01:53:19 -04:00
|
|
|
@pvc_common.Profiler(config)
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
2021-11-06 03:02:43 -04:00
|
|
|
def ceph_volume_snapshot_list(
|
|
|
|
zkhandler, pool=None, volume=None, limit=None, is_fuzzy=True
|
|
|
|
):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Get the list of RBD volume snapshots in the Ceph storage cluster.
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
retflag, retdata = pvc_ceph.get_list_snapshot(
|
|
|
|
zkhandler, pool, volume, limit, is_fuzzy
|
|
|
|
)
|
2019-12-23 20:43:20 -05:00
|
|
|
|
2019-07-05 14:11:01 -04:00
|
|
|
if retflag:
|
2019-07-26 13:15:54 -04:00
|
|
|
if retdata:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 404
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": "Volume snapshot not found."}
|
2019-07-05 14:11:01 -04:00
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2021-11-06 03:02:43 -04:00
|
|
|
retdata = {"message": retdata}
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2019-12-23 20:43:20 -05:00
|
|
|
return retdata, retcode
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_snapshot_add(zkhandler, pool, volume, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
|
|
|
Add a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.add_snapshot(zkhandler, pool, volume, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 14:11:01 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_snapshot_rename(zkhandler, pool, volume, name, new_name):
|
2019-07-28 23:00:35 -04:00
|
|
|
"""
|
|
|
|
Rename a Ceph RBD volume snapshot in the PVC Ceph storage cluster.
|
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.rename_snapshot(zkhandler, pool, volume, name, new_name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-28 23:00:35 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|
2019-07-28 23:00:35 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2024-05-13 15:22:03 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_snapshot_rollback(zkhandler, pool, volume, name):
|
|
|
|
"""
|
|
|
|
Roll back a Ceph RBD volume to a given snapshot in the PVC Ceph storage cluster.
|
|
|
|
"""
|
|
|
|
retflag, retdata = pvc_ceph.rollback_snapshot(zkhandler, pool, volume, name)
|
|
|
|
|
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
|
|
|
retcode = 400
|
|
|
|
|
|
|
|
output = {"message": retdata.replace('"', "'")}
|
|
|
|
return output, retcode
|
|
|
|
|
|
|
|
|
2021-05-29 00:30:42 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def ceph_volume_snapshot_remove(zkhandler, pool, volume, name):
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
2019-07-05 22:14:45 -04:00
|
|
|
Remove a Ceph RBD volume snapshot from the PVC Ceph storage cluster.
|
2019-07-05 14:11:01 -04:00
|
|
|
"""
|
2021-05-28 23:33:36 -04:00
|
|
|
retflag, retdata = pvc_ceph.remove_snapshot(zkhandler, pool, volume, name)
|
2020-01-02 12:13:11 -05:00
|
|
|
|
2019-07-05 22:14:45 -04:00
|
|
|
if retflag:
|
|
|
|
retcode = 200
|
|
|
|
else:
|
2019-07-26 11:23:19 -04:00
|
|
|
retcode = 400
|
2019-07-05 22:14:45 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
output = {"message": retdata.replace('"', "'")}
|
2019-12-23 20:43:20 -05:00
|
|
|
return output, retcode
|