2020-02-08 20:36:53 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Daemon.py - PVC HTTP API daemon
|
|
|
|
# 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>
|
2020-02-08 20:36:53 -05: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.
|
2020-02-08 20:36:53 -05: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
|
|
|
|
|
|
|
|
from functools import wraps
|
|
|
|
from flask_restful import Resource, Api, reqparse, abort
|
|
|
|
from celery import Celery
|
2023-11-04 14:29:59 -04:00
|
|
|
from kombu import Queue
|
2023-11-05 22:32:41 -05:00
|
|
|
from lxml.objectify import fromstring as lxml_fromstring
|
2023-11-16 13:22:14 -05:00
|
|
|
from uuid import uuid4
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2023-11-04 15:05:07 -04:00
|
|
|
from daemon_lib.common import getPrimaryNode
|
|
|
|
from daemon_lib.zkhandler import ZKConnection
|
|
|
|
from daemon_lib.node import get_list as get_node_list
|
2023-11-30 02:01:22 -05:00
|
|
|
from daemon_lib.benchmark import list_benchmarks
|
2023-11-04 15:05:07 -04:00
|
|
|
|
2021-05-30 00:09:39 -04:00
|
|
|
from pvcapid.Daemon import config, strtobool, API_VERSION
|
2021-05-28 23:33:36 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
import pvcapid.helper as api_helper
|
|
|
|
import pvcapid.provisioner as api_provisioner
|
2020-02-15 02:09:28 -05:00
|
|
|
import pvcapid.ova as api_ova
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# Create Flask app and set config values
|
|
|
|
app = flask.Flask(__name__)
|
2023-11-16 20:25:28 -05:00
|
|
|
|
|
|
|
# Set up SQLAlchemy backend
|
2024-01-10 16:13:31 -05:00
|
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
|
2023-11-16 20:25:28 -05:00
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://{}:{}@{}:{}/{}".format(
|
2023-11-29 23:35:12 -05:00
|
|
|
config["api_postgresql_user"],
|
|
|
|
config["api_postgresql_password"],
|
|
|
|
config["api_postgresql_host"],
|
|
|
|
config["api_postgresql_port"],
|
|
|
|
config["api_postgresql_dbname"],
|
2021-11-06 03:02:43 -04:00
|
|
|
)
|
2023-11-16 20:25:28 -05:00
|
|
|
|
|
|
|
if config["debug"]:
|
|
|
|
app.config["DEBUG"] = True
|
|
|
|
else:
|
|
|
|
app.config["DEBUG"] = False
|
|
|
|
|
2023-11-29 23:35:12 -05:00
|
|
|
if config["api_auth_enabled"]:
|
|
|
|
app.config["SECRET_KEY"] = config["api_auth_secret_key"]
|
2023-11-16 20:25:28 -05:00
|
|
|
|
|
|
|
# Create SQLAlchemy database
|
|
|
|
db = SQLAlchemy(app)
|
|
|
|
|
|
|
|
# Create Flask blueprint
|
|
|
|
blueprint = flask.Blueprint("api", __name__, url_prefix="/api/v1")
|
|
|
|
|
|
|
|
# Create Flask-RESTful definition
|
|
|
|
api = Api(blueprint)
|
|
|
|
app.register_blueprint(blueprint)
|
2023-11-04 15:05:07 -04:00
|
|
|
|
|
|
|
|
2023-11-05 22:32:41 -05:00
|
|
|
# Set up Celery queues
|
2023-11-04 15:05:07 -04:00
|
|
|
@ZKConnection(config)
|
|
|
|
def get_all_nodes(zkhandler):
|
|
|
|
_, all_nodes = get_node_list(zkhandler, None)
|
|
|
|
return [n["name"] for n in all_nodes]
|
|
|
|
|
|
|
|
|
2023-11-16 02:28:57 -05:00
|
|
|
@ZKConnection(config)
|
|
|
|
def get_primary_node(zkhandler):
|
|
|
|
return getPrimaryNode(zkhandler)
|
|
|
|
|
|
|
|
|
2023-11-30 00:40:09 -05:00
|
|
|
# Set up Celery task ID generator
|
|
|
|
# 1. Lets us make our own IDs (first section of UUID)
|
|
|
|
# 2. Lets us distribute jobs to the required pvcworkerd instances
|
|
|
|
def run_celery_task(task_name, **kwargs):
|
|
|
|
task_id = str(uuid4()).split("-")[0]
|
|
|
|
|
|
|
|
if "run_on" in kwargs and kwargs["run_on"] != "primary":
|
|
|
|
run_on = kwargs["run_on"]
|
2023-11-04 14:29:59 -04:00
|
|
|
else:
|
|
|
|
run_on = get_primary_node()
|
|
|
|
|
2023-11-30 00:40:09 -05:00
|
|
|
print(
|
|
|
|
f"Incoming pvcworkerd task: '{task_name}' ({task_id}) assigned to worker {run_on} with args {kwargs}"
|
|
|
|
)
|
2023-11-04 14:29:59 -04:00
|
|
|
|
2023-11-30 00:40:09 -05:00
|
|
|
task = celery.send_task(
|
|
|
|
task_name,
|
2023-11-16 13:22:14 -05:00
|
|
|
task_id=task_id,
|
2023-11-30 00:40:09 -05:00
|
|
|
kwargs=kwargs,
|
|
|
|
queue=run_on,
|
2023-11-16 13:22:14 -05:00
|
|
|
)
|
2023-11-30 00:40:09 -05:00
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
return task
|
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# Create celery definition
|
2023-11-16 20:25:28 -05:00
|
|
|
celery_task_uri = "redis://{}:{}{}".format(
|
2023-11-29 23:35:12 -05:00
|
|
|
config["keydb_host"], config["keydb_port"], config["keydb_path"]
|
2023-11-16 20:25:28 -05:00
|
|
|
)
|
2023-11-16 12:02:57 -05:00
|
|
|
celery = Celery(
|
|
|
|
app.name,
|
|
|
|
broker=celery_task_uri,
|
2024-01-09 12:06:23 -05:00
|
|
|
backend=celery_task_uri,
|
2023-11-16 12:02:57 -05:00
|
|
|
result_extended=True,
|
|
|
|
)
|
2023-11-25 15:16:56 -05:00
|
|
|
app.config["broker_url"] = celery_task_uri
|
|
|
|
app.config["result_backend"] = celery_task_uri
|
|
|
|
celery.conf.update(app.config)
|
2023-11-16 20:25:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
def celery_startup():
|
2023-11-25 15:16:56 -05:00
|
|
|
"""
|
|
|
|
Runs when the API daemon starts, but not the Celery workers or the API doc generator
|
|
|
|
"""
|
2023-11-16 20:25:28 -05:00
|
|
|
app.config["task_queues"] = tuple(
|
|
|
|
[Queue(h, routing_key=f"{h}.#") for h in get_all_nodes()]
|
|
|
|
)
|
|
|
|
celery.conf.update(app.config)
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Custom decorators
|
|
|
|
#
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# Request parser decorator
|
|
|
|
class RequestParser(object):
|
|
|
|
def __init__(self, reqargs):
|
|
|
|
self.reqargs = reqargs
|
2020-11-07 12:28:51 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
def __call__(self, function):
|
|
|
|
if not callable(function):
|
|
|
|
return
|
2020-11-07 12:17:38 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
@wraps(function)
|
|
|
|
def wrapped_function(*args, **kwargs):
|
|
|
|
parser = reqparse.RequestParser()
|
|
|
|
# Parse and add each argument
|
|
|
|
for reqarg in self.reqargs:
|
2021-11-06 03:02:43 -04:00
|
|
|
location = reqarg.get("location", None)
|
2020-11-09 10:26:01 -05:00
|
|
|
if location is None:
|
2021-11-06 03:02:43 -04:00
|
|
|
location = ["args", "form"]
|
2020-02-08 20:36:53 -05:00
|
|
|
parser.add_argument(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqarg.get("name", None),
|
|
|
|
required=reqarg.get("required", False),
|
|
|
|
action=reqarg.get("action", None),
|
|
|
|
choices=reqarg.get("choices", ()),
|
|
|
|
help=reqarg.get("helptext", None),
|
|
|
|
location=location,
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
reqargs = parser.parse_args()
|
2021-11-06 03:02:43 -04:00
|
|
|
kwargs["reqargs"] = reqargs
|
2020-02-08 20:36:53 -05:00
|
|
|
return function(*args, **kwargs)
|
2021-11-06 03:02:43 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
return wrapped_function
|
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# Authentication decorator function
|
|
|
|
def Authenticator(function):
|
|
|
|
@wraps(function)
|
|
|
|
def authenticate(*args, **kwargs):
|
|
|
|
# No authentication required
|
2023-11-29 23:35:12 -05:00
|
|
|
if not config["api_auth_enabled"]:
|
2020-02-08 20:36:53 -05:00
|
|
|
return function(*args, **kwargs)
|
|
|
|
# Session-based authentication
|
2021-11-06 03:02:43 -04:00
|
|
|
if "token" in flask.session:
|
2020-02-08 20:36:53 -05:00
|
|
|
return function(*args, **kwargs)
|
|
|
|
# Key header-based authentication
|
2021-11-06 03:02:43 -04:00
|
|
|
if "X-Api-Key" in flask.request.headers:
|
|
|
|
if any(
|
|
|
|
token
|
2023-11-29 23:35:12 -05:00
|
|
|
for token in config["api_auth_tokens"]
|
2021-11-06 03:02:43 -04:00
|
|
|
if flask.request.headers.get("X-Api-Key") == token.get("token")
|
|
|
|
):
|
2020-02-08 20:36:53 -05:00
|
|
|
return function(*args, **kwargs)
|
|
|
|
else:
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "X-Api-Key Authentication failed."}, 401
|
2020-02-08 20:36:53 -05:00
|
|
|
# All authentications failed
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "X-Api-Key Authentication required."}, 401
|
2021-11-06 03:02:43 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
return authenticate
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# API Root/Authentication
|
|
|
|
##########################################################
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /
|
|
|
|
class API_Root(Resource):
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return the PVC API version string
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: API-Version
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
example: "PVC API version 1.0"
|
|
|
|
"""
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "PVC API version {}".format(API_VERSION)}
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Root, "/")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /doc - NOTE: Until flask_swagger is packaged for Debian this must be disabled
|
2020-11-06 21:32:17 -05:00
|
|
|
# class API_Doc(Resource):
|
|
|
|
# def get(self):
|
|
|
|
# """
|
|
|
|
# Provide the Swagger API documentation
|
|
|
|
# ---
|
|
|
|
# tags:
|
|
|
|
# - root
|
|
|
|
# responses:
|
|
|
|
# 200:
|
|
|
|
# description: OK
|
|
|
|
# """
|
|
|
|
# swagger_data = swagger(pvc_api.app)
|
|
|
|
# swagger_data['info']['version'] = API_VERSION
|
|
|
|
# swagger_data['info']['title'] = "PVC Client and Provisioner API"
|
|
|
|
# swagger_data['host'] = "{}:{}".format(config['listen_address'], config['listen_port'])
|
|
|
|
# return swagger_data
|
2020-11-07 13:47:02 -05:00
|
|
|
#
|
2020-11-07 13:26:59 -05:00
|
|
|
#
|
|
|
|
# api.add_resource(API_Doc, '/doc')
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /login
|
|
|
|
class API_Login(Resource):
|
|
|
|
def post(self):
|
|
|
|
"""
|
|
|
|
Log in to the PVC API with an authentication key
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: token
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
302:
|
|
|
|
description: Authentication disabled
|
|
|
|
401:
|
|
|
|
description: Unauthorized
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-29 23:35:12 -05:00
|
|
|
if not config["api_auth_enabled"]:
|
2020-02-08 20:36:53 -05:00
|
|
|
return flask.redirect(Api.url_for(api, API_Root))
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if any(
|
|
|
|
token
|
2023-11-29 23:35:12 -05:00
|
|
|
for token in config["api_auth_tokens"]
|
2021-11-06 03:02:43 -04:00
|
|
|
if flask.request.values["token"] in token["token"]
|
|
|
|
):
|
|
|
|
flask.session["token"] = flask.request.form["token"]
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "Authentication successful"}, 200
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
2020-11-07 12:57:42 -05:00
|
|
|
{"message": "Authentication failed"}, 401
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Login, "/login")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /logout
|
|
|
|
class API_Logout(Resource):
|
|
|
|
def post(self):
|
|
|
|
"""
|
|
|
|
Log out of an existing PVC API session
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
302:
|
|
|
|
description: Authentication disabled
|
|
|
|
"""
|
2023-11-29 23:35:12 -05:00
|
|
|
if not config["api_auth_enabled"]:
|
2020-02-08 20:36:53 -05:00
|
|
|
return flask.redirect(Api.url_for(api, API_Root))
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
flask.session.pop("token", None)
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "Deauthentication successful"}, 200
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Logout, "/logout")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /initialize
|
|
|
|
class API_Initialize(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "overwrite", "required": False},
|
|
|
|
{
|
|
|
|
"name": "yes-i-really-mean-it",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "Initialization is destructive; please confirm with the argument 'yes-i-really-mean-it'.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2020-11-24 02:39:06 -05:00
|
|
|
def post(self, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
Initialize a new PVC cluster
|
2021-05-30 23:59:17 -04:00
|
|
|
|
2021-06-01 10:40:32 -04:00
|
|
|
If the 'overwrite' option is not True, the cluster will return 400 if the `/config/primary_node` key is found. If 'overwrite' is True, the existing cluster
|
2021-05-30 23:59:17 -04:00
|
|
|
data will be erased and new, empty data written in its place.
|
|
|
|
|
|
|
|
All node daemons should be stopped before running this command, and the API daemon started manually to avoid undefined behavior.
|
2020-02-08 20:36:53 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
2020-11-24 02:39:06 -05:00
|
|
|
parameters:
|
2021-05-30 23:59:17 -04:00
|
|
|
- in: query
|
|
|
|
name: overwrite
|
|
|
|
type: bool
|
|
|
|
required: false
|
|
|
|
description: A flag to enable or disable (default) overwriting existing data
|
2020-11-24 02:39:06 -05:00
|
|
|
- in: query
|
|
|
|
name: yes-i-really-mean-it
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A confirmation string to ensure that the API consumer really means it
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("overwrite", "False") == "True":
|
2021-05-30 23:59:17 -04:00
|
|
|
overwrite_flag = True
|
2021-06-29 18:22:01 -04:00
|
|
|
else:
|
|
|
|
overwrite_flag = False
|
2021-05-30 23:59:17 -04:00
|
|
|
|
2021-06-29 18:31:56 -04:00
|
|
|
return api_helper.initialize_cluster(overwrite=overwrite_flag)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Initialize, "/initialize")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-11-24 02:39:06 -05:00
|
|
|
# /backup
|
|
|
|
class API_Backup(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Back up the Zookeeper data of a cluster in JSON format
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Cluster Data
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
|
|
|
return api_helper.backup_cluster()
|
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Backup, "/backup")
|
2020-11-24 02:39:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
# /restore
|
|
|
|
class API_Restore(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "yes-i-really-mean-it",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "Restore is destructive; please confirm with the argument 'yes-i-really-mean-it'.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "cluster_data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A cluster JSON backup must be provided.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-11-24 02:39:06 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Restore a backup over the cluster; destroys the existing data
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: yes-i-really-mean-it
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A confirmation string to ensure that the API consumer really means it
|
|
|
|
- in: query
|
|
|
|
name: cluster_data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw JSON cluster backup data
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
500:
|
|
|
|
description: Restore error or code failure
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
cluster_data = reqargs.get("cluster_data")
|
2020-11-24 02:39:06 -05:00
|
|
|
except Exception as e:
|
|
|
|
return {"message": "Failed to load JSON backup: {}.".format(e)}, 400
|
|
|
|
|
|
|
|
return api_helper.restore_cluster(cluster_data)
|
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Restore, "/restore")
|
2020-11-24 02:39:06 -05:00
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /status
|
|
|
|
class API_Status(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return the current PVC cluster status
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: ClusterStatus
|
|
|
|
properties:
|
2023-02-22 00:06:52 -05:00
|
|
|
cluster_health:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
health:
|
|
|
|
type: integer
|
|
|
|
description: The overall health (%) of the cluster
|
|
|
|
example: 100
|
|
|
|
messages:
|
|
|
|
type: array
|
|
|
|
description: A list of health event strings
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
example: "hv1: plugin 'nics': bond0 DEGRADED with 1 active slaves, bond0 OK at 10000 Mbps"
|
|
|
|
node_health:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
hvX:
|
|
|
|
type: object
|
|
|
|
description: A node entry for per-node health details, one per node in the cluster
|
|
|
|
properties:
|
|
|
|
health:
|
|
|
|
type: integer
|
|
|
|
description: The health (%) of the node
|
|
|
|
example: 100
|
|
|
|
messages:
|
|
|
|
type: array
|
|
|
|
description: A list of health event strings
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
example: "'nics': bond0 DEGRADED with 1 active slaves, bond0 OK at 10000 Mbps"
|
|
|
|
maintenance:
|
2020-08-13 15:06:19 -04:00
|
|
|
type: string
|
2023-02-22 00:06:52 -05:00
|
|
|
description: Whether the cluster is in maintenance mode or not (string boolean)
|
|
|
|
example: true
|
2020-02-08 20:36:53 -05:00
|
|
|
primary_node:
|
|
|
|
type: string
|
|
|
|
description: The current primary coordinator node
|
|
|
|
example: pvchv1
|
2023-02-22 16:05:28 -05:00
|
|
|
pvc_version:
|
|
|
|
type: string
|
|
|
|
description: The PVC version of the current primary coordinator node
|
|
|
|
example: 0.9.61
|
2020-02-08 20:36:53 -05:00
|
|
|
upstream_ip:
|
|
|
|
type: string
|
|
|
|
description: The cluster upstream IP address in CIDR format
|
|
|
|
example: 10.0.0.254/24
|
|
|
|
nodes:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
total:
|
|
|
|
type: integer
|
|
|
|
description: The total number of nodes in the cluster
|
|
|
|
example: 3
|
|
|
|
state-combination:
|
|
|
|
type: integer
|
|
|
|
description: The total number of nodes in {state-combination} state, where {state-combination} is the node daemon and domain states in CSV format, e.g. "run,ready", "stop,flushed", etc.
|
|
|
|
vms:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
total:
|
|
|
|
type: integer
|
|
|
|
description: The total number of VMs in the cluster
|
|
|
|
example: 6
|
|
|
|
state:
|
|
|
|
type: integer
|
|
|
|
description: The total number of VMs in {state} state, e.g. "start", "stop", etc.
|
|
|
|
networks:
|
|
|
|
type: integer
|
|
|
|
description: The total number of networks in the cluster
|
|
|
|
osds:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
total:
|
|
|
|
type: integer
|
|
|
|
description: The total number of OSDs in the storage cluster
|
|
|
|
example: 3
|
|
|
|
state-combination:
|
|
|
|
type: integer
|
|
|
|
description: The total number of OSDs in {state-combination} state, where {state-combination} is the OSD up and in states in CSV format, e.g. "up,in", "down,out", etc.
|
|
|
|
pools:
|
|
|
|
type: integer
|
|
|
|
description: The total number of pools in the storage cluster
|
|
|
|
volumes:
|
|
|
|
type: integer
|
|
|
|
description: The total number of volumes in the storage cluster
|
|
|
|
snapshots:
|
|
|
|
type: integer
|
|
|
|
description: The total number of snapshots in the storage cluster
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
|
|
|
return api_helper.cluster_status()
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "state",
|
|
|
|
"choices": ("true", "false"),
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid state must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Set the cluster maintenance mode
|
|
|
|
---
|
|
|
|
tags:
|
2024-08-19 17:15:52 -04:00
|
|
|
- root
|
2020-02-08 20:36:53 -05:00
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: state
|
|
|
|
type: boolean
|
|
|
|
required: true
|
|
|
|
description: The cluster maintenance state
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.cluster_maintenance(reqargs.get("state", "false"))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 13:17:49 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Status, "/status")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
|
2024-08-19 17:15:52 -04:00
|
|
|
# /status/primary_node
|
|
|
|
class API_Status_Primary(Resource):
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return the name of the current primary node.
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
primary_node:
|
|
|
|
type: string
|
|
|
|
description: The name of the current primary node
|
|
|
|
204:
|
|
|
|
description: No content
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
primary_node:
|
|
|
|
type: string
|
|
|
|
description: An empty response; there is not currently a primary node, try again later
|
|
|
|
"""
|
|
|
|
primary_node = get_primary_node()
|
|
|
|
if primary_node is None:
|
|
|
|
retdata = None
|
|
|
|
retcode = 204
|
|
|
|
else:
|
|
|
|
retdata = {"primary_node": primary_node}
|
|
|
|
retcode = 200
|
|
|
|
return retdata, retcode
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_Status_Primary, "/status/primary_node")
|
|
|
|
|
|
|
|
|
2023-12-08 11:45:52 -05:00
|
|
|
# /metrics
|
|
|
|
class API_Metrics(Resource):
|
|
|
|
def get(self):
|
|
|
|
"""
|
2023-12-09 15:47:40 -05:00
|
|
|
Return the current PVC cluster status in Prometheus-compatible metrics format and
|
|
|
|
the Ceph cluster metrics as one document.
|
2023-12-08 11:45:52 -05:00
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
Endpoint is UNAUTHENTICATED to allow metrics exfiltration without having to deal
|
|
|
|
with Prometheus compatibility (only basic auth support). Ensure this API endpoint
|
|
|
|
is only opened to trusted networks that cannot abuse the data provided!
|
2023-12-08 11:45:52 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
2023-12-20 16:14:28 -05:00
|
|
|
health_output, health_retcode = api_helper.cluster_health_metrics()
|
|
|
|
resource_output, resource_retcode = api_helper.cluster_resource_metrics()
|
2023-12-09 15:47:40 -05:00
|
|
|
ceph_output, ceph_retcode = api_helper.ceph_metrics()
|
2023-12-28 12:02:31 -05:00
|
|
|
zookeeper_output, zookeeper_retcode = api_helper.zookeeper_metrics()
|
2023-12-09 15:47:40 -05:00
|
|
|
|
2023-12-20 16:14:28 -05:00
|
|
|
if health_retcode != 200 or resource_retcode != 200 or ceph_retcode != 200:
|
2023-12-09 15:47:40 -05:00
|
|
|
output = "Error: Failed to obtain data"
|
|
|
|
retcode = 400
|
|
|
|
else:
|
2023-12-28 12:02:31 -05:00
|
|
|
output = health_output + resource_output + ceph_output + zookeeper_output
|
2023-12-09 15:47:40 -05:00
|
|
|
retcode = 200
|
|
|
|
|
|
|
|
response = flask.make_response(output, retcode)
|
|
|
|
response.mimetype = "text/plain"
|
|
|
|
return response
|
2023-12-08 11:45:52 -05:00
|
|
|
|
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
if config["enable_prometheus"]:
|
|
|
|
api.add_resource(API_Metrics, "/metrics")
|
2023-12-08 11:45:52 -05:00
|
|
|
|
|
|
|
|
2023-12-20 16:14:28 -05:00
|
|
|
# /metrics/health
|
|
|
|
class API_Metrics_Health(Resource):
|
2023-12-09 15:47:40 -05:00
|
|
|
def get(self):
|
|
|
|
"""
|
2023-12-20 16:14:28 -05:00
|
|
|
Return the current PVC cluster health status in Prometheus-compatible metrics format
|
2023-12-09 15:47:40 -05:00
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
Endpoint is UNAUTHENTICATED to allow metrics exfiltration without having to deal
|
|
|
|
with Prometheus compatibility (only basic auth support). Ensure this API endpoint
|
|
|
|
is only opened to trusted networks that cannot abuse the data provided!
|
2023-12-09 15:47:40 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
2023-12-20 16:14:28 -05:00
|
|
|
health_output, health_retcode = api_helper.cluster_health_metrics()
|
2023-12-09 15:47:40 -05:00
|
|
|
|
2023-12-20 16:14:28 -05:00
|
|
|
if health_retcode != 200:
|
2023-12-09 15:47:40 -05:00
|
|
|
output = "Error: Failed to obtain data"
|
|
|
|
retcode = 400
|
|
|
|
else:
|
2023-12-20 16:14:28 -05:00
|
|
|
output = health_output
|
2023-12-09 15:47:40 -05:00
|
|
|
retcode = 200
|
|
|
|
|
|
|
|
response = flask.make_response(output, retcode)
|
|
|
|
response.mimetype = "text/plain"
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
if config["enable_prometheus"]:
|
|
|
|
api.add_resource(API_Metrics_Health, "/metrics/health")
|
2023-12-20 16:14:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
# /metrics/resource
|
|
|
|
class API_Metrics_Resource(Resource):
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return the current PVC cluster resource utilizations in Prometheus-compatible metrics format
|
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
Endpoint is UNAUTHENTICATED to allow metrics exfiltration without having to deal
|
|
|
|
with Prometheus compatibility (only basic auth support). Ensure this API endpoint
|
|
|
|
is only opened to trusted networks that cannot abuse the data provided!
|
2023-12-20 16:14:28 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
|
|
|
resource_output, resource_retcode = api_helper.cluster_resource_metrics()
|
|
|
|
|
|
|
|
if resource_retcode != 200:
|
|
|
|
output = "Error: Failed to obtain data"
|
|
|
|
retcode = 400
|
|
|
|
else:
|
|
|
|
output = resource_output
|
|
|
|
retcode = 200
|
|
|
|
|
|
|
|
response = flask.make_response(output, retcode)
|
|
|
|
response.mimetype = "text/plain"
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
if config["enable_prometheus"]:
|
|
|
|
api.add_resource(API_Metrics_Resource, "/metrics/resource")
|
2023-12-09 15:47:40 -05:00
|
|
|
|
|
|
|
|
2023-12-09 02:52:08 -05:00
|
|
|
# /metrics/ceph
|
|
|
|
class API_Metrics_Ceph(Resource):
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return the current PVC Ceph Prometheus metrics
|
|
|
|
|
|
|
|
Proxies a metrics request to the current active MGR, since this is dynamic
|
|
|
|
and can't be controlled by PVC easily.
|
2023-12-29 09:23:35 -05:00
|
|
|
|
|
|
|
Endpoint is UNAUTHENTICATED to allow metrics exfiltration without having to deal
|
|
|
|
with Prometheus compatibility (only basic auth support). Ensure this API endpoint
|
|
|
|
is only opened to trusted networks that cannot abuse the data provided!
|
2023-12-09 02:52:08 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
2023-12-09 15:47:40 -05:00
|
|
|
ceph_output, ceph_retcode = api_helper.ceph_metrics()
|
|
|
|
|
|
|
|
if ceph_retcode != 200:
|
|
|
|
output = "Error: Failed to obtain data"
|
|
|
|
retcode = 400
|
|
|
|
else:
|
|
|
|
output = ceph_output
|
|
|
|
retcode = 200
|
|
|
|
|
|
|
|
response = flask.make_response(output, retcode)
|
|
|
|
response.mimetype = "text/plain"
|
|
|
|
return response
|
2023-12-09 02:52:08 -05:00
|
|
|
|
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
if config["enable_prometheus"]:
|
|
|
|
api.add_resource(API_Metrics_Ceph, "/metrics/ceph")
|
2023-12-09 02:52:08 -05:00
|
|
|
|
|
|
|
|
2023-12-28 12:02:31 -05:00
|
|
|
# /metrics/zookeeper
|
|
|
|
class API_Metrics_Zookeeper(Resource):
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return the current PVC Zookeeper Prometheus metrics
|
|
|
|
|
|
|
|
Proxies a metrics request to the current primary node, since all coordinators
|
|
|
|
run an active Zookeeper instance and we want one central location.
|
2023-12-29 09:23:35 -05:00
|
|
|
|
|
|
|
Endpoint is UNAUTHENTICATED to allow metrics exfiltration without having to deal
|
|
|
|
with Prometheus compatibility (only basic auth support). Ensure this API endpoint
|
|
|
|
is only opened to trusted networks that cannot abuse the data provided!
|
2023-12-28 12:02:31 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
"""
|
|
|
|
zookeeper_output, zookeeper_retcode = api_helper.zookeeper_metrics()
|
|
|
|
|
|
|
|
if zookeeper_retcode != 200:
|
|
|
|
output = "Error: Failed to obtain data"
|
|
|
|
retcode = 400
|
|
|
|
else:
|
|
|
|
output = zookeeper_output
|
|
|
|
retcode = 200
|
|
|
|
|
|
|
|
response = flask.make_response(output, retcode)
|
|
|
|
response.mimetype = "text/plain"
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2023-12-29 09:23:35 -05:00
|
|
|
if config["enable_prometheus"]:
|
|
|
|
api.add_resource(API_Metrics_Zookeeper, "/metrics/zookeeper")
|
2023-12-28 12:02:31 -05:00
|
|
|
|
|
|
|
|
2023-12-04 01:37:54 -05:00
|
|
|
# /faults
|
|
|
|
class API_Faults(Resource):
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "sort_key",
|
|
|
|
"choices": (
|
|
|
|
"first_reported",
|
|
|
|
"last_reported",
|
|
|
|
"acknowledged_at",
|
|
|
|
"status",
|
|
|
|
"health_delta",
|
|
|
|
"message",
|
|
|
|
),
|
|
|
|
"helptext": "A valid sort key must be specified",
|
|
|
|
"required": False,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of cluster faults
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- faults
|
2024-08-19 16:55:13 -04:00
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: fault
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: string
|
|
|
|
description: The ID of the fault
|
|
|
|
example: "10ae144b78b4cc5fdf09e2ebbac51235"
|
|
|
|
first_reported:
|
|
|
|
type: date
|
|
|
|
description: The first time the fault was reported
|
|
|
|
example: "2023-12-01 16:47:59.849742"
|
|
|
|
last_reported:
|
|
|
|
type: date
|
|
|
|
description: The last time the fault was reported
|
|
|
|
example: "2023-12-01 17:39:45.188398"
|
|
|
|
acknowledged_at:
|
|
|
|
type: date
|
|
|
|
description: The time the fault was acknowledged, or empty if not acknowledged
|
|
|
|
example: "2023-12-01 17:50:00.000000"
|
|
|
|
status:
|
|
|
|
type: string
|
|
|
|
description: The current state of the fault, either "new" or "ack" (acknowledged)
|
|
|
|
example: "new"
|
|
|
|
health_delta:
|
|
|
|
type: integer
|
|
|
|
description: The health delta (amount it reduces cluster health from 100%) of the fault
|
|
|
|
example: 25
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: The textual description of the fault
|
|
|
|
example: "Node hv1 was at 40% (psur@-10%, psql@-50%) <= 50% health"
|
2023-12-04 01:37:54 -05:00
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: sort_key
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The fault object key to sort results by
|
|
|
|
enum:
|
|
|
|
- first_reported
|
|
|
|
- last_reported
|
|
|
|
- acknowledged_at
|
|
|
|
- status
|
|
|
|
- health_delta
|
|
|
|
- message
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
2024-08-19 16:55:13 -04:00
|
|
|
$ref: '#/definitions/fault'
|
2023-12-04 01:37:54 -05:00
|
|
|
"""
|
|
|
|
return api_helper.fault_list(sort_key=reqargs.get("sort_key", "last_reported"))
|
|
|
|
|
2023-12-06 13:33:27 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self):
|
|
|
|
"""
|
|
|
|
Acknowledge all cluster faults
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- faults
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
"""
|
|
|
|
return api_helper.fault_acknowledge_all()
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self):
|
|
|
|
"""
|
|
|
|
Delete all cluster faults
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- faults
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
"""
|
|
|
|
return api_helper.fault_delete_all()
|
|
|
|
|
2023-12-04 01:37:54 -05:00
|
|
|
|
|
|
|
api.add_resource(API_Faults, "/faults")
|
|
|
|
|
|
|
|
|
|
|
|
# /faults/<fault_id>
|
|
|
|
class API_Faults_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, fault_id):
|
|
|
|
"""
|
|
|
|
Return a single cluster fault
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- faults
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/fault'
|
|
|
|
"""
|
|
|
|
return api_helper.fault_list(limit=fault_id)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def put(self, fault_id):
|
|
|
|
"""
|
|
|
|
Acknowledge a cluster fault
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- faults
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
"""
|
|
|
|
return api_helper.fault_acknowledge(fault_id)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, fault_id):
|
|
|
|
"""
|
|
|
|
Delete a cluster fault
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- faults
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: A text message
|
|
|
|
"""
|
|
|
|
return api_helper.fault_delete(fault_id)
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_Faults_Element, "/faults/<fault_id>")
|
|
|
|
|
|
|
|
|
2023-11-05 22:32:41 -05:00
|
|
|
# /tasks
|
|
|
|
class API_Tasks(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return a list of active Celery worker tasks
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- root
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
active:
|
|
|
|
type: object
|
|
|
|
description: Celery app.control.inspect active tasks
|
|
|
|
reserved:
|
|
|
|
type: object
|
|
|
|
description: Celery app.control.inspect reserved tasks
|
|
|
|
scheduled:
|
|
|
|
type: object
|
|
|
|
description: Celery app.control.inspect scheduled tasks
|
|
|
|
"""
|
|
|
|
queue = celery.control.inspect()
|
|
|
|
response = {
|
|
|
|
"scheduled": queue.scheduled(),
|
|
|
|
"active": queue.active(),
|
|
|
|
"reserved": queue.reserved(),
|
|
|
|
}
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_Tasks, "/tasks")
|
|
|
|
|
|
|
|
|
|
|
|
# /tasks/<task_id>
|
|
|
|
class API_Tasks_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, task_id):
|
|
|
|
"""
|
|
|
|
View status of a Celery worker task {task_id}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
total:
|
|
|
|
type: integer
|
|
|
|
description: Total number of steps
|
|
|
|
current:
|
|
|
|
type: integer
|
|
|
|
description: Current steps completed
|
|
|
|
state:
|
|
|
|
type: string
|
|
|
|
description: Current job state
|
|
|
|
status:
|
|
|
|
type: string
|
|
|
|
description: Status details about job
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
task = celery.AsyncResult(task_id)
|
|
|
|
if task.state == "PENDING":
|
|
|
|
response = {
|
|
|
|
"state": task.state,
|
|
|
|
"current": 0,
|
|
|
|
"total": 1,
|
|
|
|
"status": "Pending job start",
|
|
|
|
}
|
2023-11-09 14:05:15 -05:00
|
|
|
elif task.state == "FAILURE":
|
|
|
|
response = {
|
|
|
|
"state": task.state,
|
|
|
|
"current": 1,
|
|
|
|
"total": 1,
|
|
|
|
"status": str(task.info),
|
|
|
|
}
|
|
|
|
else:
|
2023-11-05 22:32:41 -05:00
|
|
|
response = {
|
|
|
|
"state": task.state,
|
|
|
|
"current": task.info.get("current", 0),
|
|
|
|
"total": task.info.get("total", 1),
|
|
|
|
"status": task.info.get("status", ""),
|
|
|
|
}
|
|
|
|
if "result" in task.info:
|
|
|
|
response["result"] = task.info["result"]
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_Tasks_Element, "/tasks/<task_id>")
|
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
##########################################################
|
|
|
|
# Client API - Node
|
|
|
|
##########################################################
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /node
|
|
|
|
class API_Node_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
{"name": "daemon_state"},
|
|
|
|
{"name": "coordinator_state"},
|
|
|
|
{"name": "domain_state"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of nodes in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: node
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the node
|
|
|
|
daemon_state:
|
|
|
|
type: string
|
|
|
|
description: The current daemon state
|
|
|
|
coordinator_state:
|
|
|
|
type: string
|
|
|
|
description: The current coordinator state
|
|
|
|
domain_state:
|
|
|
|
type: string
|
|
|
|
description: The current domain (VM) state
|
2021-07-05 09:57:38 -04:00
|
|
|
pvc_version:
|
|
|
|
type: string
|
|
|
|
description: The current running PVC node daemon version
|
2020-02-08 20:36:53 -05:00
|
|
|
cpu_count:
|
|
|
|
type: integer
|
|
|
|
description: The number of available CPU cores
|
|
|
|
kernel:
|
|
|
|
type: string
|
|
|
|
desription: The running kernel version from uname
|
|
|
|
os:
|
|
|
|
type: string
|
|
|
|
description: The current operating system type
|
|
|
|
arch:
|
|
|
|
type: string
|
|
|
|
description: The architecture of the CPU
|
2023-02-22 00:06:52 -05:00
|
|
|
health:
|
|
|
|
type: integer
|
|
|
|
description: The overall health (%) of the node
|
|
|
|
example: 100
|
2023-02-22 00:25:27 -05:00
|
|
|
health_plugins:
|
|
|
|
type: array
|
|
|
|
description: A list of health plugin names currently loaded on the node
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
example: "nics"
|
2023-02-22 00:06:52 -05:00
|
|
|
health_details:
|
|
|
|
type: array
|
|
|
|
description: A list of health plugin results
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the health plugin
|
|
|
|
example: nics
|
|
|
|
last_run:
|
|
|
|
type: integer
|
|
|
|
description: The UNIX timestamp (s) of the last plugin run
|
|
|
|
example: 1676786078
|
|
|
|
health_delta:
|
|
|
|
type: integer
|
|
|
|
description: The health delta (negatively applied to the health percentage) of the plugin's current state
|
|
|
|
example: 10
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
description: The output message of the plugin
|
|
|
|
example: "bond0 DEGRADED with 1 active slaves, bond0 OK at 10000 Mbps"
|
2020-02-08 20:36:53 -05:00
|
|
|
load:
|
|
|
|
type: number
|
|
|
|
format: float
|
|
|
|
description: The current 5-minute CPU load
|
|
|
|
domains_count:
|
|
|
|
type: integer
|
|
|
|
description: The number of running domains (VMs)
|
|
|
|
running_domains:
|
|
|
|
type: string
|
|
|
|
description: The list of running domains (VMs) by UUID
|
|
|
|
vcpu:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
total:
|
|
|
|
type: integer
|
|
|
|
description: The total number of real CPU cores available
|
|
|
|
allocated:
|
|
|
|
type: integer
|
|
|
|
description: The total number of allocated vCPU cores
|
|
|
|
memory:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
total:
|
|
|
|
type: integer
|
|
|
|
description: The total amount of node RAM in MB
|
|
|
|
used:
|
|
|
|
type: integer
|
|
|
|
description: The total used RAM on the node in MB
|
|
|
|
free:
|
|
|
|
type: integer
|
|
|
|
description: The total free RAM on the node in MB
|
2020-10-18 14:02:34 -04:00
|
|
|
allocated:
|
|
|
|
type: integer
|
|
|
|
description: The total amount of RAM allocated to running domains in MB
|
|
|
|
provisioned:
|
|
|
|
type: integer
|
|
|
|
description: The total amount of RAM provisioned to all domains (regardless of state) on this node in MB
|
2023-12-21 15:12:20 -05:00
|
|
|
interfaces:
|
|
|
|
type: object
|
|
|
|
description: Details on speed, bytes, and packets per second of each node physical network interface
|
2020-02-08 20:36:53 -05:00
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
2021-07-14 00:51:48 -04:00
|
|
|
description: A search limit in the name, tags, or an exact UUID; fuzzy by default, use ^/$ to force exact matches
|
2020-06-25 11:38:30 -04:00
|
|
|
- in: query
|
|
|
|
name: daemon_state
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Limit results to nodes in the specified daemon state
|
|
|
|
- in: query
|
|
|
|
name: coordinator_state
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Limit results to nodes in the specified coordinator state
|
|
|
|
- in: query
|
|
|
|
name: domain_state
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Limit results to nodes in the specified domain state
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/node'
|
|
|
|
"""
|
2020-06-25 11:38:30 -04:00
|
|
|
return api_helper.node_list(
|
2021-11-06 03:02:43 -04:00
|
|
|
limit=reqargs.get("limit", None),
|
|
|
|
daemon_state=reqargs.get("daemon_state", None),
|
|
|
|
coordinator_state=reqargs.get("coordinator_state", None),
|
|
|
|
domain_state=reqargs.get("domain_state", None),
|
2020-06-25 11:38:30 -04:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Node_Root, "/node")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /node/<node>
|
|
|
|
class API_Node_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, node):
|
|
|
|
"""
|
|
|
|
Return information about {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/node'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.node_list(node, is_fuzzy=False)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Node_Element, "/node/<node>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /node/<node>/daemon-state
|
|
|
|
class API_Node_DaemonState(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, node):
|
|
|
|
"""
|
|
|
|
Return the daemon state of {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: NodeDaemonState
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the node
|
|
|
|
daemon_state:
|
|
|
|
type: string
|
|
|
|
description: The current daemon state
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.node_daemon_state(node)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Node_DaemonState, "/node/<node>/daemon-state")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /node/<node>/coordinator-state
|
|
|
|
class API_Node_CoordinatorState(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, node):
|
|
|
|
"""
|
|
|
|
Return the coordinator state of {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: NodeCoordinatorState
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the node
|
|
|
|
coordinator_state:
|
|
|
|
type: string
|
|
|
|
description: The current coordinator state
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.node_coordinator_state(node)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "state",
|
|
|
|
"choices": ("primary", "secondary"),
|
|
|
|
"helptext": "A valid state must be specified",
|
|
|
|
"required": True,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, node, reqargs):
|
|
|
|
"""
|
|
|
|
Set the coordinator state of {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: action
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The new coordinator state of the node
|
|
|
|
enum:
|
|
|
|
- primary
|
|
|
|
- secondary
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs["state"] == "primary":
|
2020-02-19 10:50:21 -05:00
|
|
|
return api_helper.node_primary(node)
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs["state"] == "secondary":
|
2020-02-19 10:50:21 -05:00
|
|
|
return api_helper.node_secondary(node)
|
2020-02-08 20:36:53 -05:00
|
|
|
abort(400)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Node_CoordinatorState, "/node/<node>/coordinator-state")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /node/<node>/domain-state
|
|
|
|
class API_Node_DomainState(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, node):
|
|
|
|
"""
|
|
|
|
Return the domain state of {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: NodeDomainState
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the node
|
|
|
|
domain_state:
|
|
|
|
type: string
|
|
|
|
description: The current domain state
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.node_domain_state(node)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "state",
|
|
|
|
"choices": ("ready", "flush"),
|
|
|
|
"helptext": "A valid state must be specified",
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
{"name": "wait"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, node, reqargs):
|
|
|
|
"""
|
|
|
|
Set the domain state of {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: action
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The new domain state of the node
|
|
|
|
enum:
|
|
|
|
- flush
|
|
|
|
- ready
|
|
|
|
- in: query
|
|
|
|
name: wait
|
|
|
|
type: boolean
|
|
|
|
description: Whether to block waiting for the full flush/ready state
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs["state"] == "flush":
|
|
|
|
return api_helper.node_flush(
|
|
|
|
node, bool(strtobool(reqargs.get("wait", "false")))
|
|
|
|
)
|
|
|
|
if reqargs["state"] == "ready":
|
|
|
|
return api_helper.node_ready(
|
|
|
|
node, bool(strtobool(reqargs.get("wait", "false")))
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
abort(400)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Node_DomainState, "/node/<node>/domain-state")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
|
2021-07-18 17:37:49 -04:00
|
|
|
# /node/<node</log
|
|
|
|
class API_Node_Log(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "lines"}])
|
2021-07-18 17:37:49 -04:00
|
|
|
@Authenticator
|
|
|
|
def get(self, node, reqargs):
|
|
|
|
"""
|
|
|
|
Return the recent logs of {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- node
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: lines
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The number of lines to retrieve
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: NodeLog
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the Node
|
|
|
|
data:
|
|
|
|
type: string
|
|
|
|
description: The recent log text
|
|
|
|
404:
|
|
|
|
description: Node not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.node_log(node, reqargs.get("lines", None))
|
2021-07-18 17:37:49 -04:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Node_Log, "/node/<node>/log")
|
2021-07-18 17:37:49 -04:00
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
##########################################################
|
|
|
|
# Client API - VM
|
|
|
|
##########################################################
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /vm
|
|
|
|
class API_VM_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
{"name": "node"},
|
|
|
|
{"name": "state"},
|
|
|
|
{"name": "tag"},
|
|
|
|
{"name": "negate"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of VMs in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: vm
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the VM
|
|
|
|
uuid:
|
|
|
|
type: string
|
|
|
|
description: The UUID of the VM
|
|
|
|
state:
|
|
|
|
type: string
|
|
|
|
description: The current state of the VM
|
|
|
|
node:
|
|
|
|
type: string
|
|
|
|
description: The node the VM is currently assigned to
|
|
|
|
last_node:
|
|
|
|
type: string
|
|
|
|
description: The last node the VM was assigned to before migrating
|
|
|
|
migrated:
|
|
|
|
type: string
|
|
|
|
description: Whether the VM has been migrated, either "no" or "from <last_node>"
|
|
|
|
failed_reason:
|
|
|
|
type: string
|
|
|
|
description: Information about why the VM failed to start
|
|
|
|
node_limit:
|
|
|
|
type: array
|
|
|
|
description: The node(s) the VM is permitted to be assigned to
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
node_selector:
|
|
|
|
type: string
|
2022-06-10 02:14:15 -04:00
|
|
|
description: The selector used to determine candidate nodes during migration; see 'target_selector' in the node daemon configuration reference
|
2020-02-08 20:36:53 -05:00
|
|
|
node_autostart:
|
|
|
|
type: boolean
|
|
|
|
description: Whether to autostart the VM when its node returns to ready domain state
|
2020-10-29 11:31:32 -04:00
|
|
|
migration_method:
|
|
|
|
type: string
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime:
|
|
|
|
type: integer
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
2021-07-13 19:04:56 -04:00
|
|
|
tags:
|
|
|
|
type: array
|
|
|
|
description: The tag(s) of the VM
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
id: VMTag
|
2024-05-21 15:10:28 -04:00
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the tag
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of the tag (user, system)
|
|
|
|
protected:
|
|
|
|
type: boolean
|
|
|
|
description: Whether the tag is protected or not
|
|
|
|
snapshots:
|
|
|
|
type: array
|
|
|
|
description: The snapshot(s) of the VM
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
id: VMSnapshot
|
2024-05-21 13:14:55 -04:00
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the snapshot
|
|
|
|
timestamp:
|
|
|
|
type: string
|
|
|
|
descrpition: Unix timestamp of the snapshot
|
2024-05-21 15:10:28 -04:00
|
|
|
age:
|
|
|
|
type: string
|
2024-08-19 16:55:13 -04:00
|
|
|
description: Human-readable age of the snapshot in the largest viable unit (seconds, minutes, hours, days)
|
2024-05-21 13:14:55 -04:00
|
|
|
rbd_snapshots:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: A list of RBD volume snapshots belonging to this VM snapshot, in '<pool>/<volume>@<snapshot>' format
|
|
|
|
xml_diff_lines:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: A list of strings representing the lines of an (n=1) unified diff between the current VM XML specification and the snapshot VM XML specification
|
2020-02-08 20:36:53 -05:00
|
|
|
description:
|
|
|
|
type: string
|
|
|
|
description: The description of the VM
|
|
|
|
profile:
|
|
|
|
type: string
|
|
|
|
description: The provisioner profile used to create the VM
|
|
|
|
memory:
|
|
|
|
type: integer
|
|
|
|
description: The assigned RAM of the VM in MB
|
2020-06-07 02:15:33 -04:00
|
|
|
memory_stats:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
actual:
|
|
|
|
type: integer
|
|
|
|
description: The total active memory of the VM in kB
|
|
|
|
swap_in:
|
|
|
|
type: integer
|
|
|
|
description: The amount of swapped in data in kB
|
|
|
|
swap_out:
|
|
|
|
type: integer
|
|
|
|
description: The amount of swapped out data in kB
|
|
|
|
major_fault:
|
|
|
|
type: integer
|
|
|
|
description: The number of major page faults
|
|
|
|
minor_fault:
|
|
|
|
type: integer
|
|
|
|
description: The number of minor page faults
|
|
|
|
unused:
|
|
|
|
type: integer
|
|
|
|
description: The amount of memory left completely unused by the system in kB
|
|
|
|
available:
|
|
|
|
type: integer
|
|
|
|
description: The total amount of usable memory as seen by the domain in kB
|
|
|
|
usable:
|
|
|
|
type: integer
|
|
|
|
description: How much the balloon can be inflated without pushing the guest system to swap in kB
|
|
|
|
last_update:
|
|
|
|
type: integer
|
|
|
|
description: Timestamp of the last update of statistics, in seconds
|
|
|
|
rss:
|
|
|
|
type: integer
|
|
|
|
description: The Resident Set Size of the process running the domain in kB
|
2020-02-08 20:36:53 -05:00
|
|
|
vcpu:
|
|
|
|
type: integer
|
|
|
|
description: The assigned vCPUs of the VM
|
|
|
|
vcpu_topology:
|
|
|
|
type: string
|
|
|
|
description: The topology of the assigned vCPUs in Sockets/Cores/Threads format
|
2020-06-07 02:15:33 -04:00
|
|
|
vcpu_stats:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
cpu_time:
|
|
|
|
type: integer
|
|
|
|
description: The active CPU time for all vCPUs
|
|
|
|
user_time:
|
|
|
|
type: integer
|
|
|
|
description: vCPU user time
|
|
|
|
system_time:
|
|
|
|
type: integer
|
|
|
|
description: vCPU system time
|
2020-02-08 20:36:53 -05:00
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of the VM
|
|
|
|
arch:
|
|
|
|
type: string
|
|
|
|
description: The architecture of the VM
|
|
|
|
machine:
|
|
|
|
type: string
|
|
|
|
description: The QEMU machine type of the VM
|
|
|
|
console:
|
|
|
|
type: string
|
|
|
|
descritpion: The serial console type of the VM
|
2020-12-20 16:00:55 -05:00
|
|
|
vnc:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
listen:
|
|
|
|
type: string
|
|
|
|
description: The active VNC listen address or 'None'
|
|
|
|
port:
|
|
|
|
type: string
|
|
|
|
description: The active VNC port or 'None'
|
2020-02-08 20:36:53 -05:00
|
|
|
emulator:
|
|
|
|
type: string
|
|
|
|
description: The binary emulator of the VM
|
|
|
|
features:
|
|
|
|
type: array
|
|
|
|
description: The available features of the VM
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
networks:
|
|
|
|
type: array
|
|
|
|
description: The PVC networks attached to the VM
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The PVC network type
|
|
|
|
mac:
|
|
|
|
type: string
|
|
|
|
description: The MAC address of the VM network interface
|
|
|
|
source:
|
|
|
|
type: string
|
|
|
|
description: The parent network bridge on the node
|
2020-12-01 04:44:33 -05:00
|
|
|
vni:
|
|
|
|
type: integer
|
|
|
|
description: The VNI (PVC network) of the network bridge
|
2020-02-08 20:36:53 -05:00
|
|
|
model:
|
|
|
|
type: string
|
|
|
|
description: The virtual network device model
|
2020-06-07 02:15:33 -04:00
|
|
|
rd_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The number of read bytes on the interface
|
|
|
|
rd_packets:
|
|
|
|
type: integer
|
|
|
|
description: The number of read packets on the interface
|
|
|
|
rd_errors:
|
|
|
|
type: integer
|
|
|
|
description: The number of read errors on the interface
|
|
|
|
rd_drops:
|
|
|
|
type: integer
|
|
|
|
description: The number of read drops on the interface
|
|
|
|
wr_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The number of write bytes on the interface
|
|
|
|
wr_packets:
|
|
|
|
type: integer
|
|
|
|
description: The number of write packets on the interface
|
|
|
|
wr_errors:
|
|
|
|
type: integer
|
|
|
|
description: The number of write errors on the interface
|
|
|
|
wr_drops:
|
|
|
|
type: integer
|
|
|
|
description: The number of write drops on the interface
|
2020-02-08 20:36:53 -05:00
|
|
|
disks:
|
|
|
|
type: array
|
|
|
|
description: The PVC storage volumes attached to the VM
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of volume
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The full name of the volume in "pool/volume" format
|
|
|
|
dev:
|
|
|
|
type: string
|
|
|
|
description: The device ID of the volume in the VM
|
|
|
|
bus:
|
|
|
|
type: string
|
|
|
|
description: The virtual bus of the volume in the VM
|
2020-06-07 02:15:33 -04:00
|
|
|
rd_req:
|
|
|
|
type: integer
|
|
|
|
description: The number of read requests from the volume
|
|
|
|
rd_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The number of read bytes from the volume
|
|
|
|
wr_req:
|
|
|
|
type: integer
|
|
|
|
description: The number of write requests to the volume
|
|
|
|
wr_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The number of write bytes to the volume
|
2020-02-08 20:36:53 -05:00
|
|
|
controllers:
|
|
|
|
type: array
|
|
|
|
description: The device controllers attached to the VM
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of the controller
|
|
|
|
model:
|
|
|
|
type: string
|
|
|
|
description: The model of the controller
|
|
|
|
xml:
|
|
|
|
type: string
|
|
|
|
description: The raw Libvirt XML definition of the VM
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
2021-07-14 00:51:48 -04:00
|
|
|
description: A search limit in the name, tags, or an exact UUID; fuzzy by default, use ^/$ to force exact matches
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: node
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Limit list to VMs assigned to this node
|
|
|
|
- in: query
|
|
|
|
name: state
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Limit list to VMs in this state
|
2021-07-14 00:51:48 -04:00
|
|
|
- in: query
|
|
|
|
name: tag
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Limit list to VMs with this tag
|
2021-10-07 11:13:30 -04:00
|
|
|
- in: query
|
|
|
|
name: negate
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Negate the specified node, state, or tag limit(s)
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/vm'
|
|
|
|
"""
|
|
|
|
return api_helper.vm_list(
|
2021-11-06 03:02:43 -04:00
|
|
|
node=reqargs.get("node", None),
|
|
|
|
state=reqargs.get("state", None),
|
|
|
|
tag=reqargs.get("tag", None),
|
|
|
|
limit=reqargs.get("limit", None),
|
|
|
|
negate=bool(strtobool(reqargs.get("negate", "False"))),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
{"name": "node"},
|
|
|
|
{
|
|
|
|
"name": "selector",
|
2022-11-15 15:45:59 -05:00
|
|
|
"choices": ("mem", "memprov", "vcpus", "load", "vms", "none"),
|
2021-11-06 03:02:43 -04:00
|
|
|
"helptext": "A valid selector must be specified",
|
|
|
|
},
|
|
|
|
{"name": "autostart"},
|
|
|
|
{
|
|
|
|
"name": "migration_method",
|
|
|
|
"choices": ("live", "shutdown", "none"),
|
|
|
|
"helptext": "A valid migration_method must be specified",
|
|
|
|
},
|
2024-01-10 16:13:31 -05:00
|
|
|
{
|
|
|
|
"name": "migration_max_downtime",
|
|
|
|
"helptext": "A valid migration_max_downtime must be specified",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "user_tags", "action": "append"},
|
|
|
|
{"name": "protected_tags", "action": "append"},
|
|
|
|
{
|
|
|
|
"name": "xml",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A Libvirt XML document must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new virtual machine
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: xml
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw Libvirt XML definition of the VM
|
|
|
|
- in: query
|
|
|
|
name: node
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The node the VM should be assigned to; autoselect if empty or invalid
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The CSV list of node(s) the VM is permitted to be assigned to; should include "node" and any other valid target nodes; this limit will be used for autoselection on definition and migration
|
|
|
|
- in: query
|
|
|
|
name: selector
|
|
|
|
type: string
|
|
|
|
required: false
|
2022-06-10 02:14:15 -04:00
|
|
|
description: The selector used to determine candidate nodes during migration; see 'target_selector' in the node daemon configuration reference
|
2022-06-10 02:03:12 -04:00
|
|
|
default: none
|
2020-02-08 20:36:53 -05:00
|
|
|
enum:
|
|
|
|
- mem
|
2022-11-15 15:45:59 -05:00
|
|
|
- memprov
|
2020-02-08 20:36:53 -05:00
|
|
|
- vcpus
|
|
|
|
- load
|
|
|
|
- vms
|
2022-06-10 02:03:12 -04:00
|
|
|
- none (cluster default)
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: autostart
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to autostart the VM when its node returns to ready domain state
|
2020-10-29 11:31:32 -04:00
|
|
|
- in: query
|
|
|
|
name: migration_method
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
|
|
|
default: none
|
|
|
|
enum:
|
|
|
|
- live
|
|
|
|
- shutdown
|
|
|
|
- none
|
2024-01-10 16:13:31 -05:00
|
|
|
- in: query
|
|
|
|
name: migration_max_downtime
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
|
|
|
default: 300
|
2021-07-13 02:17:30 -04:00
|
|
|
- in: query
|
2021-07-13 19:04:56 -04:00
|
|
|
name: user_tags
|
|
|
|
type: array
|
|
|
|
required: false
|
|
|
|
description: The user tag(s) of the VM
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
- in: query
|
|
|
|
name: protected_tags
|
2021-07-13 02:17:30 -04:00
|
|
|
type: array
|
|
|
|
required: false
|
2021-07-13 19:04:56 -04:00
|
|
|
description: The protected user tag(s) of the VM
|
2021-07-13 02:17:30 -04:00
|
|
|
items:
|
|
|
|
type: string
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
user_tags = reqargs.get("user_tags", None)
|
2021-07-13 19:04:56 -04:00
|
|
|
if user_tags is None:
|
|
|
|
user_tags = []
|
2021-11-06 03:02:43 -04:00
|
|
|
protected_tags = reqargs.get("protected_tags", None)
|
2021-07-13 19:04:56 -04:00
|
|
|
if protected_tags is None:
|
|
|
|
protected_tags = []
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.vm_define(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("xml"),
|
|
|
|
reqargs.get("node", None),
|
|
|
|
reqargs.get("limit", None),
|
|
|
|
reqargs.get("selector", "none"),
|
|
|
|
bool(strtobool(reqargs.get("autostart", "false"))),
|
|
|
|
reqargs.get("migration_method", "none"),
|
2024-01-10 16:13:31 -05:00
|
|
|
reqargs.get("migration_max_downtime", 300),
|
2021-07-13 19:04:56 -04:00
|
|
|
user_tags,
|
2021-11-06 03:02:43 -04:00
|
|
|
protected_tags,
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Root, "/vm")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /vm/<vm>
|
|
|
|
class API_VM_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vm):
|
|
|
|
"""
|
|
|
|
Return information about {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/vm'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.vm_list(
|
|
|
|
node=None, state=None, tag=None, limit=vm, is_fuzzy=False, negate=False
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
{"name": "node"},
|
|
|
|
{
|
|
|
|
"name": "selector",
|
2022-11-15 15:45:59 -05:00
|
|
|
"choices": ("mem", "memprov", "vcpus", "load", "vms", "none"),
|
2021-11-06 03:02:43 -04:00
|
|
|
"helptext": "A valid selector must be specified",
|
|
|
|
},
|
|
|
|
{"name": "autostart"},
|
|
|
|
{
|
|
|
|
"name": "migration_method",
|
|
|
|
"choices": ("live", "shutdown", "none"),
|
|
|
|
"helptext": "A valid migration_method must be specified",
|
|
|
|
},
|
2024-01-10 16:13:31 -05:00
|
|
|
{
|
|
|
|
"name": "migration_max_downtime",
|
|
|
|
"helptext": "A valid migration_max_downtime must be specified",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "user_tags", "action": "append"},
|
|
|
|
{"name": "protected_tags", "action": "append"},
|
|
|
|
{
|
|
|
|
"name": "xml",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A Libvirt XML document must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Create new {vm}
|
|
|
|
Note: The name {vm} is ignored; only the "name" value from the Libvirt XML is used
|
|
|
|
This endpoint is identical to "POST /api/v1/vm"
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: xml
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw Libvirt XML definition of the VM
|
|
|
|
- in: query
|
|
|
|
name: node
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The node the VM should be assigned to; autoselect if empty or invalid
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The CSV list of node(s) the VM is permitted to be assigned to; should include "node" and any other valid target nodes; this limit will be used for autoselection on definition and migration
|
|
|
|
- in: query
|
|
|
|
name: selector
|
|
|
|
type: string
|
|
|
|
required: false
|
2022-06-10 02:14:15 -04:00
|
|
|
description: The selector used to determine candidate nodes during migration; see 'target_selector' in the node daemon configuration reference
|
2022-06-10 02:03:12 -04:00
|
|
|
default: none
|
2020-02-08 20:36:53 -05:00
|
|
|
enum:
|
|
|
|
- mem
|
2022-11-15 15:45:59 -05:00
|
|
|
- memprov
|
2020-02-08 20:36:53 -05:00
|
|
|
- vcpus
|
|
|
|
- load
|
|
|
|
- vms
|
2021-06-01 11:05:15 -04:00
|
|
|
- none (cluster default)
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: autostart
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to autostart the VM when its node returns to ready domain state
|
2020-10-29 11:31:32 -04:00
|
|
|
- in: query
|
|
|
|
name: migration_method
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
|
|
|
default: none
|
|
|
|
enum:
|
|
|
|
- live
|
|
|
|
- shutdown
|
|
|
|
- none
|
2024-01-10 16:13:31 -05:00
|
|
|
- in: query
|
|
|
|
name: migration_max_downtime
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
|
|
|
default: 300
|
2021-07-13 02:17:30 -04:00
|
|
|
- in: query
|
2021-07-13 19:04:56 -04:00
|
|
|
name: user_tags
|
2021-07-13 02:17:30 -04:00
|
|
|
type: array
|
|
|
|
required: false
|
2021-07-13 19:04:56 -04:00
|
|
|
description: The user tag(s) of the VM
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
- in: query
|
|
|
|
name: protected_tags
|
|
|
|
type: array
|
|
|
|
required: false
|
|
|
|
description: The protected user tag(s) of the VM
|
2021-07-13 02:17:30 -04:00
|
|
|
items:
|
|
|
|
type: string
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
user_tags = reqargs.get("user_tags", None)
|
2021-07-13 19:04:56 -04:00
|
|
|
if user_tags is None:
|
|
|
|
user_tags = []
|
2021-11-06 03:02:43 -04:00
|
|
|
protected_tags = reqargs.get("protected_tags", None)
|
2021-07-13 19:04:56 -04:00
|
|
|
if protected_tags is None:
|
|
|
|
protected_tags = []
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.vm_define(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("xml"),
|
|
|
|
reqargs.get("node", None),
|
|
|
|
reqargs.get("limit", None),
|
|
|
|
reqargs.get("selector", "none"),
|
|
|
|
bool(strtobool(reqargs.get("autostart", "false"))),
|
|
|
|
reqargs.get("migration_method", "none"),
|
2024-01-10 16:13:31 -05:00
|
|
|
reqargs.get("migration_max_downtime", 300),
|
2021-07-13 19:04:56 -04:00
|
|
|
user_tags,
|
2021-11-06 03:02:43 -04:00
|
|
|
protected_tags,
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "restart"},
|
|
|
|
{
|
|
|
|
"name": "xml",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A Libvirt XML document must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Update the Libvirt XML of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: xml
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw Libvirt XML definition of the VM
|
|
|
|
- in: query
|
|
|
|
name: restart
|
|
|
|
type: boolean
|
|
|
|
description: Whether to automatically restart the VM to apply the new configuration
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.vm_modify(
|
|
|
|
vm,
|
2021-11-06 03:02:43 -04:00
|
|
|
bool(strtobool(reqargs.get("restart", "false"))),
|
|
|
|
reqargs.get("xml", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "delete_disks"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def delete(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Remove {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: delete_disks
|
|
|
|
type: boolean
|
|
|
|
default: false
|
|
|
|
description: Whether to automatically delete all VM disk volumes
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: VM not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("delete_disks", "false"))):
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.vm_remove(vm)
|
|
|
|
else:
|
|
|
|
return api_helper.vm_undefine(vm)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Element, "/vm/<vm>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /vm/<vm>/meta
|
|
|
|
class API_VM_Metadata(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vm):
|
|
|
|
"""
|
|
|
|
Return the metadata of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: VMMetadata
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the VM
|
|
|
|
node_limit:
|
|
|
|
type: array
|
|
|
|
description: The node(s) the VM is permitted to be assigned to
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
node_selector:
|
|
|
|
type: string
|
2022-06-10 02:14:15 -04:00
|
|
|
description: The selector used to determine candidate nodes during migration; see 'target_selector' in the node daemon configuration reference
|
2020-02-08 20:36:53 -05:00
|
|
|
node_autostart:
|
|
|
|
type: string
|
|
|
|
description: Whether to autostart the VM when its node returns to ready domain state
|
2020-10-29 11:31:32 -04:00
|
|
|
migration_method:
|
|
|
|
type: string
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime:
|
|
|
|
type: integer
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
2020-02-08 20:36:53 -05:00
|
|
|
404:
|
2021-07-13 02:17:30 -04:00
|
|
|
description: VM not found
|
2020-02-08 20:36:53 -05:00
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.get_vm_meta(vm)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
{
|
|
|
|
"name": "selector",
|
2022-11-15 15:45:59 -05:00
|
|
|
"choices": ("mem", "memprov", "vcpus", "load", "vms", "none"),
|
2021-11-06 03:02:43 -04:00
|
|
|
"helptext": "A valid selector must be specified",
|
|
|
|
},
|
|
|
|
{"name": "autostart"},
|
|
|
|
{"name": "profile"},
|
|
|
|
{
|
|
|
|
"name": "migration_method",
|
|
|
|
"choices": ("live", "shutdown", "none"),
|
|
|
|
"helptext": "A valid migration_method must be specified",
|
|
|
|
},
|
2024-01-10 16:13:31 -05:00
|
|
|
{
|
|
|
|
"name": "migration_max_downtime",
|
|
|
|
"helptext": "A valid migration_max_downtime must be specified",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Set the metadata of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The CSV list of node(s) the VM is permitted to be assigned to; should include "node" and any other valid target nodes; this limit will be used for autoselection on definition and migration
|
|
|
|
- in: query
|
|
|
|
name: selector
|
|
|
|
type: string
|
|
|
|
required: false
|
2022-06-10 02:14:15 -04:00
|
|
|
description: The selector used to determine candidate nodes during migration; see 'target_selector' in the node daemon configuration reference
|
2020-02-08 20:36:53 -05:00
|
|
|
enum:
|
|
|
|
- mem
|
2022-11-15 15:45:59 -05:00
|
|
|
- memprov
|
2020-02-08 20:36:53 -05:00
|
|
|
- vcpus
|
|
|
|
- load
|
|
|
|
- vms
|
2022-06-10 02:03:12 -04:00
|
|
|
- none (cluster default)
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: autostart
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to autostart the VM when its node returns to ready domain state
|
|
|
|
- in: query
|
|
|
|
name: profile
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The PVC provisioner profile for the VM
|
2020-10-29 11:31:32 -04:00
|
|
|
- in: query
|
|
|
|
name: migration_method
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
|
|
|
default: none
|
|
|
|
enum:
|
|
|
|
- live
|
|
|
|
- shutdown
|
|
|
|
- none
|
2024-01-10 16:13:31 -05:00
|
|
|
- in: query
|
|
|
|
name: migration_max_downtime
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
|
|
|
default: none
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
2021-07-13 02:17:30 -04:00
|
|
|
404:
|
|
|
|
description: VM not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
return api_helper.update_vm_meta(
|
|
|
|
vm,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("limit", None),
|
|
|
|
reqargs.get("selector", None),
|
|
|
|
reqargs.get("autostart", None),
|
|
|
|
reqargs.get("profile", None),
|
|
|
|
reqargs.get("migration_method", None),
|
2024-01-10 16:13:31 -05:00
|
|
|
reqargs.get("migration_max_downtime", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Metadata, "/vm/<vm>/meta")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-07-13 02:17:30 -04:00
|
|
|
# /vm/<vm>/tags
|
|
|
|
class API_VM_Tags(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vm):
|
|
|
|
"""
|
|
|
|
Return the tags of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: VMTags
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the VM
|
|
|
|
tags:
|
|
|
|
type: array
|
|
|
|
description: The tag(s) of the VM
|
|
|
|
items:
|
2021-07-13 19:04:56 -04:00
|
|
|
type: object
|
|
|
|
id: VMTag
|
2021-07-13 02:17:30 -04:00
|
|
|
404:
|
|
|
|
description: VM not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.get_vm_tags(vm)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "action",
|
|
|
|
"choices": ("add", "remove"),
|
|
|
|
"helptext": "A valid action must be specified",
|
|
|
|
},
|
|
|
|
{"name": "tag"},
|
|
|
|
{"name": "protected"},
|
|
|
|
]
|
|
|
|
)
|
2021-07-13 02:17:30 -04:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Set the tags of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: action
|
|
|
|
type: string
|
|
|
|
required: true
|
2021-07-13 19:04:56 -04:00
|
|
|
description: The action to perform with the tag
|
2021-07-13 02:17:30 -04:00
|
|
|
enum:
|
|
|
|
- add
|
|
|
|
- remove
|
|
|
|
- in: query
|
2021-07-13 19:04:56 -04:00
|
|
|
name: tag
|
|
|
|
type: string
|
2021-07-13 02:17:30 -04:00
|
|
|
required: true
|
2021-07-13 19:04:56 -04:00
|
|
|
description: The text value of the tag
|
|
|
|
- in: query
|
|
|
|
name: protected
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: false
|
|
|
|
description: Set the protected state of the tag
|
2021-07-13 02:17:30 -04:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: VM not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-07-13 19:04:56 -04:00
|
|
|
return api_helper.update_vm_tag(
|
2021-07-13 02:17:30 -04:00
|
|
|
vm,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("action"),
|
|
|
|
reqargs.get("tag"),
|
|
|
|
reqargs.get("protected", False),
|
2021-07-13 02:17:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Tags, "/vm/<vm>/tags")
|
2021-07-13 02:17:30 -04:00
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /vm/<vm</state
|
|
|
|
class API_VM_State(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vm):
|
|
|
|
"""
|
|
|
|
Return the state information of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: VMState
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the VM
|
|
|
|
state:
|
|
|
|
type: string
|
|
|
|
description: The current state of the VM
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.vm_state(vm)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "state",
|
|
|
|
"choices": ("start", "shutdown", "stop", "restart", "disable"),
|
|
|
|
"helptext": "A valid state must be specified",
|
|
|
|
"required": True,
|
|
|
|
},
|
2021-11-06 03:53:44 -04:00
|
|
|
{"name": "force"},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "wait"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Set the state of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: state
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The new state of the VM
|
|
|
|
enum:
|
|
|
|
- start
|
|
|
|
- shutdown
|
|
|
|
- stop
|
|
|
|
- restart
|
|
|
|
- disable
|
2021-11-06 03:53:44 -04:00
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
description: Whether to force stop instead of shutdown VM during disable
|
2020-02-19 09:51:19 -05:00
|
|
|
- in: query
|
|
|
|
name: wait
|
|
|
|
type: boolean
|
|
|
|
description: Whether to block waiting for the state change to complete
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
state = reqargs.get("state", None)
|
2021-11-06 03:53:44 -04:00
|
|
|
force = bool(strtobool(reqargs.get("force", "false")))
|
2021-11-06 03:02:43 -04:00
|
|
|
wait = bool(strtobool(reqargs.get("wait", "false")))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if state == "start":
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.vm_start(vm)
|
2021-11-06 03:02:43 -04:00
|
|
|
if state == "shutdown":
|
2020-02-19 09:51:19 -05:00
|
|
|
return api_helper.vm_shutdown(vm, wait)
|
2021-11-06 03:02:43 -04:00
|
|
|
if state == "stop":
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.vm_stop(vm)
|
2021-11-06 03:02:43 -04:00
|
|
|
if state == "restart":
|
2020-02-19 09:51:19 -05:00
|
|
|
return api_helper.vm_restart(vm, wait)
|
2021-11-06 03:02:43 -04:00
|
|
|
if state == "disable":
|
2021-11-06 03:53:44 -04:00
|
|
|
return api_helper.vm_disable(vm, force)
|
2020-02-08 20:36:53 -05:00
|
|
|
abort(400)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_State, "/vm/<vm>/state")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /vm/<vm>/node
|
|
|
|
class API_VM_Node(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vm):
|
|
|
|
"""
|
|
|
|
Return the node information of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: VMNode
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the VM
|
|
|
|
node:
|
|
|
|
type: string
|
|
|
|
description: The node the VM is currently assigned to
|
|
|
|
last_node:
|
|
|
|
type: string
|
|
|
|
description: The last node the VM was assigned to before migrating
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.vm_node(vm)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "action",
|
|
|
|
"choices": ("migrate", "unmigrate", "move"),
|
|
|
|
"helptext": "A valid action must be specified",
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
{"name": "node"},
|
|
|
|
{"name": "force"},
|
|
|
|
{"name": "wait"},
|
|
|
|
{"name": "force_live"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Set the node of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: action
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The action to take to change nodes
|
|
|
|
enum:
|
|
|
|
- migrate
|
|
|
|
- unmigrate
|
|
|
|
- move
|
|
|
|
- in: query
|
|
|
|
name: node
|
|
|
|
type: string
|
|
|
|
description: The node the VM should be assigned to; autoselect if empty or invalid
|
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
description: Whether to force an already-migrated VM to a new node
|
2020-02-19 09:51:19 -05:00
|
|
|
- in: query
|
|
|
|
name: wait
|
|
|
|
type: boolean
|
|
|
|
description: Whether to block waiting for the migration to complete
|
2020-06-06 11:49:21 -04:00
|
|
|
- in: query
|
|
|
|
name: force_live
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enforce live migration and disable shutdown-based fallback migration
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
action = reqargs.get("action", None)
|
|
|
|
node = reqargs.get("node", None)
|
|
|
|
force = bool(strtobool(reqargs.get("force", "false")))
|
|
|
|
wait = bool(strtobool(reqargs.get("wait", "false")))
|
|
|
|
force_live = bool(strtobool(reqargs.get("force_live", "false")))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if action == "move":
|
2020-06-06 11:49:21 -04:00
|
|
|
return api_helper.vm_move(vm, node, wait, force_live)
|
2021-11-06 03:02:43 -04:00
|
|
|
if action == "migrate":
|
2020-06-06 11:49:21 -04:00
|
|
|
return api_helper.vm_migrate(vm, node, force, wait, force_live)
|
2021-11-06 03:02:43 -04:00
|
|
|
if action == "unmigrate":
|
2020-06-06 11:49:21 -04:00
|
|
|
return api_helper.vm_unmigrate(vm, wait, force_live)
|
2020-02-08 20:36:53 -05:00
|
|
|
abort(400)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Node, "/vm/<vm>/node")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /vm/<vm>/locks
|
|
|
|
class API_VM_Locks(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def post(self, vm):
|
|
|
|
"""
|
|
|
|
Flush disk locks of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
responses:
|
2023-11-05 22:32:41 -05:00
|
|
|
202:
|
2020-02-08 20:36:53 -05:00
|
|
|
description: OK
|
|
|
|
schema:
|
2023-11-05 22:32:41 -05:00
|
|
|
type: string
|
|
|
|
description: The Celery job ID of the task
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
2023-11-05 22:32:41 -05:00
|
|
|
vm_node_detail, retcode = api_helper.vm_node(vm)
|
|
|
|
if retcode == 200:
|
|
|
|
vm_node = vm_node_detail["node"]
|
|
|
|
else:
|
|
|
|
return vm_node_detail, retcode
|
|
|
|
|
2023-11-30 00:40:09 -05:00
|
|
|
task = run_celery_task("vm.flush_locks", domain=vm, run_on=vm_node)
|
2023-11-05 22:32:41 -05:00
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "vm.flush_locks", "run_on": vm_node},
|
2023-11-05 22:32:41 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Locks, "/vm/<vm>/locks")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2023-10-17 10:15:06 -04:00
|
|
|
# /vm/<vm>/console
|
2020-02-08 20:36:53 -05:00
|
|
|
class API_VM_Console(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "lines"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Return the recent console log of {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: lines
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The number of lines to retrieve
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: VMLog
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the VM
|
|
|
|
data:
|
|
|
|
type: string
|
|
|
|
description: The recent console log text
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.vm_console(vm, reqargs.get("lines", None))
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Console, "/vm/<vm>/console")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
|
2021-05-23 16:41:42 -04:00
|
|
|
# /vm/<vm>/rename
|
|
|
|
class API_VM_Rename(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "new_name"}])
|
2021-05-23 16:41:42 -04:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Rename VM {vm}, and all connected disk volumes which include this name, to {new_name}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: new_name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The new name of the VM
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.vm_rename(vm, reqargs.get("new_name", None))
|
2021-05-23 16:41:42 -04:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Rename, "/vm/<vm>/rename")
|
2021-05-23 16:41:42 -04:00
|
|
|
|
|
|
|
|
2021-09-12 15:41:05 -04:00
|
|
|
# /vm/<vm>/device
|
|
|
|
class API_VM_Device(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "xml",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A Libvirt XML device document must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2021-09-12 15:41:05 -04:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Hot-attach device XML to {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: xml
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw Libvirt XML definition of the device to attach
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-05 22:32:41 -05:00
|
|
|
try:
|
|
|
|
xml = reqargs.get("xml", None)
|
|
|
|
lxml_fromstring(xml)
|
|
|
|
except Exception:
|
|
|
|
return {"message": "Specified XML document is not valid"}, 400
|
|
|
|
|
|
|
|
vm_node_detail, retcode = api_helper.vm_node(vm)
|
|
|
|
if retcode == 200:
|
|
|
|
vm_node = vm_node_detail["node"]
|
|
|
|
else:
|
|
|
|
return vm_node_detail, retcode
|
|
|
|
|
2023-11-30 00:40:09 -05:00
|
|
|
task = run_celery_task("vm.device_attach", domain=vm, xml=xml, run_on=vm_node)
|
2023-11-05 22:32:41 -05:00
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "vm.device_attach", "run_on": vm_node},
|
2023-11-05 22:32:41 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
|
|
|
)
|
2021-09-12 15:41:05 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "xml",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A Libvirt XML device document must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2021-09-12 15:41:05 -04:00
|
|
|
@Authenticator
|
|
|
|
def delete(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Hot-detach device XML to {vm}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: xml
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw Libvirt XML definition of the device to detach
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-05 22:32:41 -05:00
|
|
|
try:
|
|
|
|
xml = reqargs.get("xml", None)
|
|
|
|
lxml_fromstring(xml)
|
|
|
|
except Exception:
|
|
|
|
return {"message": "Specified XML document is not valid"}, 400
|
|
|
|
|
|
|
|
vm_node_detail, retcode = api_helper.vm_node(vm)
|
|
|
|
if retcode == 200:
|
|
|
|
vm_node = vm_node_detail["node"]
|
|
|
|
else:
|
|
|
|
return vm_node_detail, retcode
|
|
|
|
|
2023-11-30 00:40:09 -05:00
|
|
|
task = run_celery_task("vm.device_detach", domain=vm, xml=xml, run_on=vm_node)
|
2023-11-05 22:32:41 -05:00
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "vm.device_detach", "run_on": vm_node},
|
2023-11-05 22:32:41 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
|
|
|
)
|
2021-09-12 15:41:05 -04:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_VM_Device, "/vm/<vm>/device")
|
2021-09-12 15:41:05 -04:00
|
|
|
|
|
|
|
|
2023-10-17 10:15:06 -04:00
|
|
|
# /vm/<vm>/backup
|
|
|
|
class API_VM_Backup(Resource):
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
2023-10-24 01:20:44 -04:00
|
|
|
"name": "backup_path",
|
2023-10-17 10:15:06 -04:00
|
|
|
"required": True,
|
|
|
|
"helptext": "A local filesystem path on the primary coordinator must be specified",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "incremental_parent",
|
|
|
|
"required": False,
|
|
|
|
},
|
|
|
|
{
|
2023-10-24 00:23:12 -04:00
|
|
|
"name": "retain_snapshot",
|
2023-10-17 10:15:06 -04:00
|
|
|
"required": False,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
2023-10-23 22:23:17 -04:00
|
|
|
def post(self, vm, reqargs):
|
2023-10-17 10:15:06 -04:00
|
|
|
"""
|
|
|
|
Create a backup of {vm} and its volumes to a local primary coordinator filesystem path
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
2023-10-24 01:20:44 -04:00
|
|
|
name: backup_path
|
2023-10-17 10:15:06 -04:00
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A local filesystem path on the primary coordinator to store the backup
|
|
|
|
- in: query
|
|
|
|
name: incremental_parent
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A previous backup datestamp to use as an incremental parent; if unspecified a full backup is taken
|
|
|
|
- in: query
|
2023-10-24 00:23:12 -04:00
|
|
|
name: retain_snapshot
|
2023-10-17 10:15:06 -04:00
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: false
|
2023-10-24 00:23:12 -04:00
|
|
|
description: Whether or not to retain this backup's volume snapshots to use as a future incremental parent; full backups only
|
2023-10-17 10:15:06 -04:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path = reqargs.get("backup_path", None)
|
2023-10-17 10:15:06 -04:00
|
|
|
incremental_parent = reqargs.get("incremental_parent", None)
|
2023-10-24 00:23:12 -04:00
|
|
|
retain_snapshot = bool(strtobool(reqargs.get("retain_snapshot", "false")))
|
2023-10-17 10:56:32 -04:00
|
|
|
return api_helper.vm_backup(
|
2023-10-24 01:20:44 -04:00
|
|
|
vm, backup_path, incremental_parent, retain_snapshot
|
2023-10-17 10:15:06 -04:00
|
|
|
)
|
|
|
|
|
2023-10-24 01:08:36 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
2023-10-24 01:20:44 -04:00
|
|
|
"name": "backup_path",
|
2023-10-24 01:08:36 -04:00
|
|
|
"required": True,
|
|
|
|
"helptext": "A local filesystem path on the primary coordinator must be specified",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "backup_datestring",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A backup datestring must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Remove a backup of {vm}, including snapshots, from a local primary coordinator filesystem path
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
2023-10-24 01:20:44 -04:00
|
|
|
name: backup_path
|
2023-10-24 01:08:36 -04:00
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A local filesystem path on the primary coordinator where the backup is stored
|
|
|
|
- in: query
|
|
|
|
name: backup_datestring
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The backup datestring identifier (e.g. 20230102030405)
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path = reqargs.get("backup_path", None)
|
2023-10-24 01:08:36 -04:00
|
|
|
backup_datestring = reqargs.get("backup_datestring", None)
|
2023-10-24 01:20:44 -04:00
|
|
|
return api_helper.vm_remove_backup(vm, backup_path, backup_datestring)
|
2023-10-24 01:08:36 -04:00
|
|
|
|
2023-10-17 10:15:06 -04:00
|
|
|
|
|
|
|
api.add_resource(API_VM_Backup, "/vm/<vm>/backup")
|
|
|
|
|
|
|
|
|
2023-10-23 22:23:17 -04:00
|
|
|
# /vm/<vm>/restore
|
|
|
|
class API_VM_Restore(Resource):
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
2023-10-24 01:20:44 -04:00
|
|
|
"name": "backup_path",
|
2023-10-23 22:23:17 -04:00
|
|
|
"required": True,
|
|
|
|
"helptext": "A local filesystem path on the primary coordinator must be specified",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "backup_datestring",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A backup datestring must be specified",
|
2023-10-24 00:23:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "retain_snapshot",
|
|
|
|
"required": False,
|
|
|
|
},
|
2023-10-23 22:23:17 -04:00
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Restore a backup of {vm} and its volumes from a local primary coordinator filesystem path
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
2023-10-24 01:20:44 -04:00
|
|
|
name: backup_path
|
2023-10-23 22:23:17 -04:00
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A local filesystem path on the primary coordinator where the backup is stored
|
|
|
|
- in: query
|
|
|
|
name: backup_datestring
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The backup datestring identifier (e.g. 20230102030405)
|
2023-10-24 00:23:12 -04:00
|
|
|
- in: query
|
|
|
|
name: retain_snapshot
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: true
|
|
|
|
description: Whether or not to retain the (parent, if incremental) volume snapshot after restore
|
2023-10-23 22:23:17 -04:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-10-24 01:20:44 -04:00
|
|
|
backup_path = reqargs.get("backup_path", None)
|
2023-10-23 22:23:17 -04:00
|
|
|
backup_datestring = reqargs.get("backup_datestring", None)
|
2023-10-24 00:23:12 -04:00
|
|
|
retain_snapshot = bool(strtobool(reqargs.get("retain_snapshot", "true")))
|
2023-10-23 22:23:17 -04:00
|
|
|
return api_helper.vm_restore(
|
2023-10-24 01:20:44 -04:00
|
|
|
vm, backup_path, backup_datestring, retain_snapshot
|
2023-10-23 22:23:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_VM_Restore, "/vm/<vm>/restore")
|
|
|
|
|
|
|
|
|
2024-05-16 09:23:31 -04:00
|
|
|
# /vm/<vm>/snapshot
|
|
|
|
class API_VM_Snapshot(Resource):
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "snapshot_name",
|
|
|
|
"required": False,
|
|
|
|
"helptext": "",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Take a snapshot of a VM's disks and configuration
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot_name
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A custom name for the snapshot instead of autogeneration by date
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
snapshot_name = reqargs.get("snapshot_name", None)
|
|
|
|
return api_helper.create_vm_snapshot(vm, snapshot_name=snapshot_name)
|
|
|
|
|
2024-05-17 10:55:42 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "snapshot_name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A snapshot name must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Remove a snapshot of a VM's disks and configuration
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot_name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the snapshot to remove
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
snapshot_name = reqargs.get("snapshot_name", None)
|
|
|
|
return api_helper.remove_vm_snapshot(vm, snapshot_name)
|
|
|
|
|
2024-05-16 09:23:31 -04:00
|
|
|
|
|
|
|
api.add_resource(API_VM_Snapshot, "/vm/<vm>/snapshot")
|
|
|
|
|
|
|
|
|
2024-08-05 13:21:41 -04:00
|
|
|
# /vm/<vm>/snapshot/rollback
|
|
|
|
class API_VM_Snapshot_Rollback(Resource):
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "snapshot_name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A snapshot name must be specified",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Roll back to a snapshot of a VM's disks and configuration
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot_name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the snapshot to roll back to
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
snapshot_name = reqargs.get("snapshot_name", None)
|
|
|
|
return api_helper.rollback_vm_snapshot(vm, snapshot_name)
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_VM_Snapshot_Rollback, "/vm/<vm>/snapshot/rollback")
|
|
|
|
|
|
|
|
|
2024-08-19 18:46:07 -04:00
|
|
|
# /vm/<vm>/snapshot/export
|
|
|
|
class API_VM_Snapshot_Export(Resource):
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "snapshot_name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A snapshot name must be specified",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "export_path",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "An absolute directory path on the PVC primary coordinator to export files to",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "incremental_parent",
|
|
|
|
"required": False,
|
|
|
|
"helptext": "A snapshot name to generate an incremental diff from",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def post(self, vm, reqargs):
|
|
|
|
"""
|
|
|
|
Roll back to a snapshot of a VM's disks and configuration
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- vm
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot_name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the snapshot to roll back to
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Execution error
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
snapshot_name = reqargs.get("snapshot_name", None)
|
|
|
|
export_path = reqargs.get("export_path", None)
|
|
|
|
incremental_parent = reqargs.get("incremental_parent", None)
|
|
|
|
return api_helper.export_vm_snapshot(
|
|
|
|
vm, snapshot_name, export_path, incremental_parent
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(API_VM_Snapshot_Export, "/vm/<vm>/snapshot/export")
|
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
##########################################################
|
|
|
|
# Client API - Network
|
|
|
|
##########################################################
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /network
|
|
|
|
class API_Network_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of networks in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: network
|
|
|
|
properties:
|
|
|
|
vni:
|
|
|
|
type: integer
|
|
|
|
description: The VNI of the network
|
|
|
|
description:
|
|
|
|
type: string
|
|
|
|
description: The description of the network
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of network
|
|
|
|
enum:
|
|
|
|
- managed
|
|
|
|
- bridged
|
2021-10-09 17:43:56 -04:00
|
|
|
mtu:
|
|
|
|
type: integer
|
|
|
|
description: The MTU of the network, if set; empty otherwise
|
2020-02-08 20:36:53 -05:00
|
|
|
domain:
|
|
|
|
type: string
|
|
|
|
description: The DNS domain of the network ("managed" networks only)
|
|
|
|
name_servers:
|
|
|
|
type: array
|
|
|
|
description: The configured DNS nameservers of the network for NS records ("managed" networks only)
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
ip4:
|
|
|
|
type: object
|
|
|
|
description: The IPv4 details of the network ("managed" networks only)
|
|
|
|
properties:
|
|
|
|
network:
|
|
|
|
type: string
|
|
|
|
description: The IPv4 network subnet in CIDR format
|
|
|
|
gateway:
|
|
|
|
type: string
|
|
|
|
description: The IPv4 default gateway address
|
|
|
|
dhcp_flag:
|
|
|
|
type: boolean
|
|
|
|
description: Whether DHCP is enabled
|
|
|
|
dhcp_start:
|
|
|
|
type: string
|
|
|
|
description: The IPv4 DHCP pool start address
|
|
|
|
dhcp_end:
|
|
|
|
type: string
|
|
|
|
description: The IPv4 DHCP pool end address
|
|
|
|
ip6:
|
|
|
|
type: object
|
|
|
|
description: The IPv6 details of the network ("managed" networks only)
|
|
|
|
properties:
|
|
|
|
network:
|
|
|
|
type: string
|
|
|
|
description: The IPv6 network subnet in CIDR format
|
|
|
|
gateway:
|
|
|
|
type: string
|
|
|
|
description: The IPv6 default gateway address
|
|
|
|
dhcp_flag:
|
|
|
|
type: boolean
|
|
|
|
description: Whether DHCPv6 is enabled
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A VNI or description search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/network'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.net_list(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "vni", "required": True},
|
|
|
|
{"name": "description", "required": True},
|
|
|
|
{
|
|
|
|
"name": "nettype",
|
|
|
|
"choices": ("managed", "bridged"),
|
|
|
|
"helptext": "A valid nettype must be specified",
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
{"name": "mtu"},
|
|
|
|
{"name": "domain"},
|
|
|
|
{"name": "name_servers"},
|
|
|
|
{"name": "ip4_network"},
|
|
|
|
{"name": "ip4_gateway"},
|
|
|
|
{"name": "ip6_network"},
|
|
|
|
{"name": "ip6_gateway"},
|
|
|
|
{"name": "dhcp4"},
|
|
|
|
{"name": "dhcp4_start"},
|
|
|
|
{"name": "dhcp4_end"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new network
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: vni
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The VNI of the network
|
|
|
|
- in: query
|
|
|
|
name: description
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The description of the network
|
|
|
|
- in: query
|
|
|
|
name: nettype
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The type of network
|
|
|
|
enum:
|
|
|
|
- managed
|
|
|
|
- bridged
|
2021-10-09 17:43:56 -04:00
|
|
|
- in: query
|
|
|
|
name: mtu
|
|
|
|
type: integer
|
|
|
|
description: The MTU of the network; defaults to the underlying interface MTU if not set
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: domain
|
|
|
|
type: string
|
|
|
|
description: The DNS domain of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: name_servers
|
|
|
|
type: string
|
|
|
|
description: The CSV list of DNS nameservers for network NS records ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip4_network
|
|
|
|
type: string
|
|
|
|
description: The IPv4 network subnet of the network in CIDR format; IPv4 disabled if unspecified ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip4_gateway
|
|
|
|
type: string
|
|
|
|
description: The IPv4 default gateway address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable DHCPv4 for the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4_start
|
|
|
|
type: string
|
|
|
|
description: The DHCPv4 pool start address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4_end
|
|
|
|
type: string
|
|
|
|
description: The DHCPv4 pool end address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip6_network
|
|
|
|
type: string
|
|
|
|
description: The IPv6 network subnet of the network in CIDR format; IPv6 disabled if unspecified; DHCPv6 is always used in IPv6 managed networks ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip6_gateway
|
|
|
|
type: string
|
|
|
|
description: The IPv6 default gateway address of the network ("managed" networks only)
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("name_servers", None):
|
|
|
|
name_servers = ",".join(reqargs.get("name_servers", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
2021-11-06 03:02:43 -04:00
|
|
|
name_servers = ""
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.net_add(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("vni", None),
|
|
|
|
reqargs.get("description", None),
|
|
|
|
reqargs.get("nettype", None),
|
|
|
|
reqargs.get("mtu", ""),
|
|
|
|
reqargs.get("domain", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
name_servers,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("ip4_network", None),
|
|
|
|
reqargs.get("ip4_gateway", None),
|
|
|
|
reqargs.get("ip6_network", None),
|
|
|
|
reqargs.get("ip6_gateway", None),
|
|
|
|
bool(strtobool(reqargs.get("dhcp4", "false"))),
|
|
|
|
reqargs.get("dhcp4_start", None),
|
|
|
|
reqargs.get("dhcp4_end", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Network_Root, "/network")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /network/<vni>
|
|
|
|
class API_Network_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vni):
|
|
|
|
"""
|
|
|
|
Return information about network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/network'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_list(vni, is_fuzzy=False)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "description", "required": True},
|
|
|
|
{
|
|
|
|
"name": "nettype",
|
|
|
|
"choices": ("managed", "bridged"),
|
|
|
|
"helptext": "A valid nettype must be specified",
|
|
|
|
"required": True,
|
|
|
|
},
|
|
|
|
{"name": "mtu"},
|
|
|
|
{"name": "domain"},
|
|
|
|
{"name": "name_servers"},
|
|
|
|
{"name": "ip4_network"},
|
|
|
|
{"name": "ip4_gateway"},
|
|
|
|
{"name": "ip6_network"},
|
|
|
|
{"name": "ip6_gateway"},
|
|
|
|
{"name": "dhcp4"},
|
|
|
|
{"name": "dhcp4_start"},
|
|
|
|
{"name": "dhcp4_end"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vni, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: description
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The description of the network
|
|
|
|
- in: query
|
|
|
|
name: nettype
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The type of network
|
|
|
|
enum:
|
|
|
|
- managed
|
|
|
|
- bridged
|
2021-10-09 17:43:56 -04:00
|
|
|
- in: query
|
|
|
|
name: mtu
|
|
|
|
type: integer
|
|
|
|
description: The MTU of the network; defaults to the underlying interface MTU if not set
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: domain
|
|
|
|
type: string
|
|
|
|
description: The DNS domain of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: name_servers
|
|
|
|
type: string
|
|
|
|
description: The CSV list of DNS nameservers for network NS records ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip4_network
|
|
|
|
type: string
|
|
|
|
description: The IPv4 network subnet of the network in CIDR format; IPv4 disabled if unspecified ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip4_gateway
|
|
|
|
type: string
|
|
|
|
description: The IPv4 default gateway address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable DHCPv4 for the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4_start
|
|
|
|
type: string
|
|
|
|
description: The DHCPv4 pool start address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4_end
|
|
|
|
type: string
|
|
|
|
description: The DHCPv4 pool end address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip6_network
|
|
|
|
type: string
|
|
|
|
description: The IPv6 network subnet of the network in CIDR format; IPv6 disabled if unspecified; DHCPv6 is always used in IPv6 managed networks ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip6_gateway
|
|
|
|
type: string
|
|
|
|
description: The IPv6 default gateway address of the network ("managed" networks only)
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("name_servers", None):
|
|
|
|
name_servers = ",".join(reqargs.get("name_servers", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
2021-11-06 03:02:43 -04:00
|
|
|
name_servers = ""
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.net_add(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("vni", None),
|
|
|
|
reqargs.get("description", None),
|
|
|
|
reqargs.get("nettype", None),
|
|
|
|
reqargs.get("mtu", ""),
|
|
|
|
reqargs.get("domain", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
name_servers,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("ip4_network", None),
|
|
|
|
reqargs.get("ip4_gateway", None),
|
|
|
|
reqargs.get("ip6_network", None),
|
|
|
|
reqargs.get("ip6_gateway", None),
|
|
|
|
bool(strtobool(reqargs.get("dhcp4", "false"))),
|
|
|
|
reqargs.get("dhcp4_start", None),
|
|
|
|
reqargs.get("dhcp4_end", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "description"},
|
|
|
|
{"name": "mtu"},
|
|
|
|
{"name": "domain"},
|
|
|
|
{"name": "name_servers"},
|
|
|
|
{"name": "ip4_network"},
|
|
|
|
{"name": "ip4_gateway"},
|
|
|
|
{"name": "ip6_network"},
|
|
|
|
{"name": "ip6_gateway"},
|
|
|
|
{"name": "dhcp4"},
|
|
|
|
{"name": "dhcp4_start"},
|
|
|
|
{"name": "dhcp4_end"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, vni, reqargs):
|
|
|
|
"""
|
|
|
|
Update details of network {vni}
|
|
|
|
Note: A network's type cannot be changed; the network must be removed and recreated as the new type
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: description
|
|
|
|
type: string
|
|
|
|
description: The description of the network
|
2021-10-09 17:43:56 -04:00
|
|
|
- in: query
|
|
|
|
name: mtu
|
|
|
|
type: integer
|
|
|
|
description: The MTU of the network
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: domain
|
|
|
|
type: string
|
|
|
|
description: The DNS domain of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: name_servers
|
|
|
|
type: string
|
|
|
|
description: The CSV list of DNS nameservers for network NS records ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip4_network
|
|
|
|
type: string
|
|
|
|
description: The IPv4 network subnet of the network in CIDR format; IPv4 disabled if unspecified ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip4_gateway
|
|
|
|
type: string
|
|
|
|
description: The IPv4 default gateway address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable DHCPv4 for the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4_start
|
|
|
|
type: string
|
|
|
|
description: The DHCPv4 pool start address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: dhcp4_end
|
|
|
|
type: string
|
|
|
|
description: The DHCPv4 pool end address of the network ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip6_network
|
|
|
|
type: string
|
|
|
|
description: The IPv6 network subnet of the network in CIDR format; IPv6 disabled if unspecified; DHCPv6 is always used in IPv6 managed networks ("managed" networks only)
|
|
|
|
- in: query
|
|
|
|
name: ip6_gateway
|
|
|
|
type: string
|
|
|
|
description: The IPv6 default gateway address of the network ("managed" networks only)
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("name_servers", None):
|
|
|
|
name_servers = ",".join(reqargs.get("name_servers", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
2021-11-06 03:02:43 -04:00
|
|
|
name_servers = ""
|
2020-02-08 20:36:53 -05:00
|
|
|
return api_helper.net_modify(
|
|
|
|
vni,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("description", None),
|
|
|
|
reqargs.get("mtu", None),
|
|
|
|
reqargs.get("domain", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
name_servers,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("ip4_network", None),
|
|
|
|
reqargs.get("ip4_gateway", None),
|
|
|
|
reqargs.get("ip6_network", None),
|
|
|
|
reqargs.get("ip6_gateway", None),
|
|
|
|
reqargs.get("dhcp4", None),
|
|
|
|
reqargs.get("dhcp4_start", None),
|
|
|
|
reqargs.get("dhcp4_end", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, vni):
|
|
|
|
"""
|
|
|
|
Remove network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_remove(vni)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Network_Element, "/network/<vni>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /network/<vni>/lease
|
|
|
|
class API_Network_Lease_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}, {"name": "static"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, vni, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of DHCP leases in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: lease
|
|
|
|
properties:
|
|
|
|
hostname:
|
|
|
|
type: string
|
|
|
|
description: The (short) hostname of the lease
|
|
|
|
ip4_address:
|
|
|
|
type: string
|
|
|
|
description: The IPv4 address of the lease
|
|
|
|
mac_address:
|
|
|
|
type: string
|
|
|
|
description: The MAC address of the lease
|
|
|
|
timestamp:
|
|
|
|
type: integer
|
|
|
|
description: The UNIX timestamp of the lease creation
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A MAC address search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
- in: query
|
|
|
|
name: static
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: false
|
|
|
|
description: Whether to show only static leases
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/lease'
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_dhcp_list(
|
|
|
|
vni,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("limit", None),
|
|
|
|
bool(strtobool(reqargs.get("static", "false"))),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "macaddress", "required": True},
|
|
|
|
{"name": "ipaddress", "required": True},
|
|
|
|
{"name": "hostname"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vni, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new static DHCP lease in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: macaddress
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A MAC address for the lease
|
|
|
|
- in: query
|
|
|
|
name: ipaddress
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: An IPv4 address for the lease
|
|
|
|
- in: query
|
|
|
|
name: hostname
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: An optional hostname for the lease
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_dhcp_add(
|
|
|
|
vni,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("ipaddress", None),
|
|
|
|
reqargs.get("macaddress", None),
|
|
|
|
reqargs.get("hostname", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Network_Lease_Root, "/network/<vni>/lease")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /network/<vni>/lease/{mac}
|
|
|
|
class API_Network_Lease_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vni, mac):
|
|
|
|
"""
|
|
|
|
Return information about DHCP lease {mac} in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: lease
|
|
|
|
properties:
|
|
|
|
hostname:
|
|
|
|
type: string
|
|
|
|
description: The (short) hostname of the lease
|
|
|
|
ip4_address:
|
|
|
|
type: string
|
|
|
|
description: The IPv4 address of the lease
|
|
|
|
mac_address:
|
|
|
|
type: string
|
|
|
|
description: The MAC address of the lease
|
|
|
|
timestamp:
|
|
|
|
type: integer
|
|
|
|
description: The UNIX timestamp of the lease creation
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/lease'
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.net_dhcp_list(vni, mac, False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "ipaddress", "required": True}, {"name": "hostname"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2020-11-07 13:28:59 -05:00
|
|
|
def post(self, vni, mac, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
Create a new static DHCP lease {mac} in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: macaddress
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A MAC address for the lease
|
|
|
|
- in: query
|
|
|
|
name: ipaddress
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: An IPv4 address for the lease
|
|
|
|
- in: query
|
|
|
|
name: hostname
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: An optional hostname for the lease
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_dhcp_add(
|
2021-11-06 03:02:43 -04:00
|
|
|
vni, reqargs.get("ipaddress", None), mac, reqargs.get("hostname", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, vni, mac):
|
|
|
|
"""
|
|
|
|
Delete static DHCP lease {mac}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.net_dhcp_remove(vni, mac)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Network_Lease_Element, "/network/<vni>/lease/<mac>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /network/<vni>/acl
|
|
|
|
class API_Network_ACL_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
{
|
|
|
|
"name": "direction",
|
|
|
|
"choices": ("in", "out"),
|
|
|
|
"helptext": "A valid direction must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, vni, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of ACLs in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: acl
|
|
|
|
properties:
|
|
|
|
description:
|
|
|
|
type: string
|
|
|
|
description: The description of the rule
|
|
|
|
direction:
|
|
|
|
type: string
|
|
|
|
description: The direction the rule applies in
|
|
|
|
order:
|
|
|
|
type: integer
|
|
|
|
description: The order of the rule in the chain
|
|
|
|
rule:
|
|
|
|
type: string
|
|
|
|
description: The NFT-format rule string
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A description search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
- in: query
|
|
|
|
name: direction
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The direction of rules to display; both directions shown if unspecified
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/acl'
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_acl_list(
|
2021-11-06 03:02:43 -04:00
|
|
|
vni, reqargs.get("limit", None), reqargs.get("direction", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "description",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A whitespace-free description must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "rule", "required": True, "helptext": "A rule must be specified."},
|
|
|
|
{
|
|
|
|
"name": "direction",
|
|
|
|
"choices": ("in", "out"),
|
|
|
|
"helptext": "A valid direction must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "order"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vni, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new ACL in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: description
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A whitespace-free description/name for the ACL
|
|
|
|
- in: query
|
|
|
|
name: direction
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The direction of the ACL; defaults to "in" if unspecified
|
|
|
|
enum:
|
|
|
|
- in
|
|
|
|
- out
|
|
|
|
- in: query
|
|
|
|
name: order
|
|
|
|
type: integer
|
|
|
|
description: The order of the ACL in the chain; defaults to the end
|
|
|
|
- in: query
|
|
|
|
name: rule
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw NFT firewall rule string
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_acl_add(
|
|
|
|
vni,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("direction", "in"),
|
|
|
|
reqargs.get("description", None),
|
|
|
|
reqargs.get("rule", None),
|
|
|
|
reqargs.get("order", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Network_ACL_Root, "/network/<vni>/acl")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /network/<vni>/acl/<description>
|
|
|
|
class API_Network_ACL_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, vni, description):
|
|
|
|
"""
|
|
|
|
Return information about ACL {description} in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/acl'
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.net_acl_list(vni, description, None, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "rule", "required": True, "helptext": "A rule must be specified."},
|
|
|
|
{
|
|
|
|
"name": "direction",
|
|
|
|
"choices": ("in", "out"),
|
|
|
|
"helptext": "A valid direction must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "order"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, vni, description, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new ACL {description} in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: direction
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The direction of the ACL; defaults to "in" if unspecified
|
|
|
|
enum:
|
|
|
|
- in
|
|
|
|
- out
|
|
|
|
- in: query
|
|
|
|
name: order
|
|
|
|
type: integer
|
|
|
|
description: The order of the ACL in the chain; defaults to the end
|
|
|
|
- in: query
|
|
|
|
name: rule
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The raw NFT firewall rule string
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.net_acl_add(
|
|
|
|
vni,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("direction", "in"),
|
2020-02-08 20:36:53 -05:00
|
|
|
description,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("rule", None),
|
|
|
|
reqargs.get("order", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, vni, description):
|
|
|
|
"""
|
|
|
|
Delete ACL {description} in network {vni}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.net_acl_remove(vni, description)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Network_ACL_Element, "/network/<vni>/acl/<description>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
|
2021-06-21 01:42:55 -04:00
|
|
|
##########################################################
|
|
|
|
# Client API - SR-IOV
|
|
|
|
##########################################################
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2021-06-21 01:42:55 -04:00
|
|
|
# /sriov
|
|
|
|
class API_SRIOV_Root(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_SRIOV_Root, "/sriov")
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
# /sriov/pf
|
|
|
|
class API_SRIOV_PF_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "node",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid node must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2021-06-21 01:42:55 -04:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of SR-IOV PFs on a given node
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network / sriov
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: sriov_pf
|
|
|
|
properties:
|
|
|
|
phy:
|
|
|
|
type: string
|
|
|
|
description: The name of the SR-IOV PF device
|
|
|
|
mtu:
|
|
|
|
type: string
|
|
|
|
description: The MTU of the SR-IOV PF device
|
|
|
|
vfs:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: The PHY name of a VF of this PF
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.sriov_pf_list(reqargs.get("node"))
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_SRIOV_PF_Root, "/sriov/pf")
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
|
2021-06-21 17:12:14 -04:00
|
|
|
# /sriov/pf/<node>
|
|
|
|
class API_SRIOV_PF_Node(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, node):
|
|
|
|
"""
|
|
|
|
Return a list of SR-IOV PFs on node {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network / sriov
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/sriov_pf'
|
|
|
|
"""
|
|
|
|
return api_helper.sriov_pf_list(node)
|
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_SRIOV_PF_Node, "/sriov/pf/<node>")
|
2021-06-21 17:12:14 -04:00
|
|
|
|
|
|
|
|
2021-06-21 01:42:55 -04:00
|
|
|
# /sriov/vf
|
|
|
|
class API_SRIOV_VF_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "node",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid node must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "pf",
|
|
|
|
"required": False,
|
|
|
|
"helptext": "A PF parent may be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2021-06-21 01:42:55 -04:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of SR-IOV VFs on a given node, optionally limited to those in the specified PF
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network / sriov
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: sriov_vf
|
|
|
|
properties:
|
|
|
|
phy:
|
|
|
|
type: string
|
|
|
|
description: The name of the SR-IOV VF device
|
|
|
|
pf:
|
|
|
|
type: string
|
|
|
|
description: The name of the SR-IOV PF parent of this VF device
|
|
|
|
mtu:
|
|
|
|
type: integer
|
|
|
|
description: The current MTU of the VF device
|
|
|
|
mac:
|
|
|
|
type: string
|
|
|
|
description: The current MAC address of the VF device
|
|
|
|
config:
|
|
|
|
type: object
|
|
|
|
id: sriov_vf_config
|
|
|
|
properties:
|
|
|
|
vlan_id:
|
|
|
|
type: string
|
|
|
|
description: The tagged vLAN ID of the SR-IOV VF device
|
|
|
|
vlan_qos:
|
|
|
|
type: string
|
|
|
|
description: The QOS group of the tagged vLAN
|
|
|
|
tx_rate_min:
|
|
|
|
type: string
|
|
|
|
description: The minimum TX rate of the SR-IOV VF device
|
|
|
|
tx_rate_max:
|
|
|
|
type: string
|
|
|
|
description: The maximum TX rate of the SR-IOV VF device
|
|
|
|
spoof_check:
|
|
|
|
type: boolean
|
|
|
|
description: Whether device spoof checking is enabled or disabled
|
|
|
|
link_state:
|
|
|
|
type: string
|
|
|
|
description: The current SR-IOV VF link state (either enabled, disabled, or auto)
|
|
|
|
trust:
|
|
|
|
type: boolean
|
|
|
|
description: Whether guest device trust is enabled or disabled
|
|
|
|
query_rss:
|
|
|
|
type: boolean
|
|
|
|
description: Whether VF RSS querying is enabled or disabled
|
|
|
|
usage:
|
|
|
|
type: object
|
|
|
|
id: sriov_vf_usage
|
|
|
|
properties:
|
|
|
|
used:
|
|
|
|
type: boolean
|
|
|
|
description: Whether the SR-IOV VF is currently used by a VM or not
|
|
|
|
domain:
|
|
|
|
type: boolean
|
|
|
|
description: The UUID of the domain the SR-IOV VF is currently used by
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.sriov_vf_list(reqargs.get("node"), reqargs.get("pf", None))
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_SRIOV_VF_Root, "/sriov/vf")
|
2021-06-21 01:42:55 -04:00
|
|
|
|
|
|
|
|
2021-06-21 17:12:14 -04:00
|
|
|
# /sriov/vf/<node>
|
|
|
|
class API_SRIOV_VF_Node(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pf",
|
|
|
|
"required": False,
|
|
|
|
"helptext": "A PF parent may be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2021-06-21 17:12:14 -04:00
|
|
|
@Authenticator
|
|
|
|
def get(self, node, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of SR-IOV VFs on node {node}, optionally limited to those in the specified PF
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network / sriov
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/sriov_vf'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.sriov_vf_list(node, reqargs.get("pf", None))
|
2021-06-21 17:12:14 -04:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_SRIOV_VF_Node, "/sriov/vf/<node>")
|
2021-06-21 17:12:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
# /sriov/vf/<node>/<vf>
|
|
|
|
class API_SRIOV_VF_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, node, vf):
|
|
|
|
"""
|
|
|
|
Return information about {vf} on {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network / sriov
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/sriov_vf'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
vf_list = list()
|
|
|
|
full_vf_list, _ = api_helper.sriov_vf_list(node)
|
|
|
|
for vf_element in full_vf_list:
|
2021-11-06 03:02:43 -04:00
|
|
|
if vf_element["phy"] == vf:
|
2021-06-21 17:12:14 -04:00
|
|
|
vf_list.append(vf_element)
|
|
|
|
|
|
|
|
if len(vf_list) == 1:
|
|
|
|
return vf_list, 200
|
|
|
|
else:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "No VF '{}' found on node '{}'".format(vf, node)}, 404
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "vlan_id"},
|
|
|
|
{"name": "vlan_qos"},
|
|
|
|
{"name": "tx_rate_min"},
|
|
|
|
{"name": "tx_rate_max"},
|
|
|
|
{
|
|
|
|
"name": "link_state",
|
|
|
|
"choices": ("auto", "enable", "disable"),
|
|
|
|
"helptext": "A valid state must be specified",
|
|
|
|
},
|
|
|
|
{"name": "spoof_check"},
|
|
|
|
{"name": "trust"},
|
|
|
|
{"name": "query_rss"},
|
|
|
|
]
|
|
|
|
)
|
2021-06-21 18:40:11 -04:00
|
|
|
@Authenticator
|
|
|
|
def put(self, node, vf, reqargs):
|
|
|
|
"""
|
|
|
|
Set the configuration of {vf} on {node}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- network / sriov
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: vlan_id
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The vLAN ID for vLAN tagging (0 is disabled)
|
|
|
|
- in: query
|
|
|
|
name: vlan_qos
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The vLAN QOS priority (0 is disabled)
|
|
|
|
- in: query
|
|
|
|
name: tx_rate_min
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The minimum TX rate (0 is disabled)
|
|
|
|
- in: query
|
|
|
|
name: tx_rate_max
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The maximum TX rate (0 is disabled)
|
|
|
|
- in: query
|
|
|
|
name: link_state
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The administrative link state
|
|
|
|
enum:
|
|
|
|
- auto
|
|
|
|
- enable
|
|
|
|
- disable
|
|
|
|
- in: query
|
|
|
|
name: spoof_check
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Enable or disable spoof checking
|
|
|
|
- in: query
|
|
|
|
name: trust
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Enable or disable VF user trust
|
|
|
|
- in: query
|
|
|
|
name: query_rss
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Enable or disable query RSS support
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.update_sriov_vf_config(
|
|
|
|
node,
|
|
|
|
vf,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("vlan_id", None),
|
|
|
|
reqargs.get("vlan_qos", None),
|
|
|
|
reqargs.get("tx_rate_min", None),
|
|
|
|
reqargs.get("tx_rate_max", None),
|
|
|
|
reqargs.get("link_state", None),
|
|
|
|
reqargs.get("spoof_check", None),
|
|
|
|
reqargs.get("trust", None),
|
|
|
|
reqargs.get("query_rss", None),
|
2021-06-21 18:40:11 -04:00
|
|
|
)
|
|
|
|
|
2021-06-21 17:12:14 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_SRIOV_VF_Element, "/sriov/vf/<node>/<vf>")
|
2021-06-21 17:12:14 -04:00
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
##########################################################
|
|
|
|
# Client API - Storage
|
|
|
|
##########################################################
|
|
|
|
# Note: The prefix `/storage` allows future potential storage subsystems.
|
|
|
|
# Since Ceph is the only section not abstracted by PVC directly
|
|
|
|
# (i.e. it references Ceph-specific concepts), this makes more
|
|
|
|
# sense in the long-term.#
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage
|
|
|
|
class API_Storage_Root(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
pass
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Root, "/storage")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph
|
|
|
|
class API_Storage_Ceph_Root(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
pass
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Root, "/storage/ceph")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/status
|
|
|
|
class API_Storage_Ceph_Status(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return status data for the PVC Ceph cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of Ceph data returned
|
|
|
|
primary_node:
|
|
|
|
type: string
|
|
|
|
description: The curent primary node in the cluster
|
|
|
|
ceph_data:
|
|
|
|
type: string
|
|
|
|
description: The raw output data
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_status()
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Status, "/storage/ceph/status")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/utilization
|
|
|
|
class API_Storage_Ceph_Utilization(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Return utilization data for the PVC Ceph cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
type:
|
|
|
|
type: string
|
|
|
|
description: The type of Ceph data returned
|
|
|
|
primary_node:
|
|
|
|
type: string
|
|
|
|
description: The curent primary node in the cluster
|
|
|
|
ceph_data:
|
|
|
|
type: string
|
|
|
|
description: The raw output data
|
|
|
|
"""
|
2020-06-06 22:49:47 -04:00
|
|
|
return api_helper.ceph_util()
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Utilization, "/storage/ceph/utilization")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-08-24 14:57:52 -04:00
|
|
|
# /storage/ceph/benchmark
|
|
|
|
class API_Storage_Ceph_Benchmark(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "job"}])
|
2020-08-24 14:57:52 -04:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
List results from benchmark jobs
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
2020-08-25 12:43:16 -04:00
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: job
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A single job name to limit results to
|
2020-08-24 14:57:52 -04:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
2020-08-25 12:43:16 -04:00
|
|
|
id: storagebenchmark
|
2020-08-24 14:57:52 -04:00
|
|
|
properties:
|
2020-08-25 12:43:16 -04:00
|
|
|
id:
|
|
|
|
type: string (containing integer)
|
|
|
|
description: The database ID of the test result
|
|
|
|
job:
|
|
|
|
type: string
|
|
|
|
description: The job name (an ISO date) of the test result
|
2021-10-02 00:53:27 -04:00
|
|
|
test_format:
|
|
|
|
type: integer
|
|
|
|
description: The PVC benchmark format of the results
|
2020-08-25 12:43:16 -04:00
|
|
|
benchmark_result:
|
2020-08-24 14:57:52 -04:00
|
|
|
type: object
|
2021-10-02 00:53:27 -04:00
|
|
|
description: A format 0 test result
|
2020-08-25 12:43:16 -04:00
|
|
|
properties:
|
|
|
|
test_name:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
overall:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
iosize:
|
|
|
|
type: string (integer)
|
|
|
|
description: The total size of the benchmark data
|
|
|
|
bandwidth:
|
|
|
|
type: string (integer)
|
|
|
|
description: The average bandwidth (KiB/s)
|
|
|
|
iops:
|
|
|
|
type: string (integer)
|
|
|
|
description: The average IOPS
|
|
|
|
runtime:
|
|
|
|
type: string (integer)
|
|
|
|
description: The total test time in milliseconds
|
|
|
|
latency:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
min:
|
|
|
|
type: string (integer)
|
|
|
|
description: The minimum latency measurement
|
|
|
|
max:
|
|
|
|
type: string (integer)
|
|
|
|
description: The maximum latency measurement
|
|
|
|
mean:
|
|
|
|
type: string (float)
|
|
|
|
description: The mean latency measurement
|
|
|
|
stdev:
|
|
|
|
type: string (float)
|
|
|
|
description: The standard deviation of latency
|
|
|
|
bandwidth:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
min:
|
|
|
|
type: string (integer)
|
|
|
|
description: The minimum bandwidth (KiB/s) measurement
|
|
|
|
max:
|
|
|
|
type: string (integer)
|
|
|
|
description: The maximum bandwidth (KiB/s) measurement
|
|
|
|
mean:
|
|
|
|
type: string (float)
|
|
|
|
description: The mean bandwidth (KiB/s) measurement
|
|
|
|
stdev:
|
|
|
|
type: string (float)
|
|
|
|
description: The standard deviation of bandwidth
|
|
|
|
numsamples:
|
|
|
|
type: string (integer)
|
|
|
|
description: The number of samples taken during the test
|
|
|
|
iops:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
min:
|
|
|
|
type: string (integer)
|
|
|
|
description: The minimum IOPS measurement
|
|
|
|
max:
|
|
|
|
type: string (integer)
|
|
|
|
description: The maximum IOPS measurement
|
|
|
|
mean:
|
|
|
|
type: string (float)
|
|
|
|
description: The mean IOPS measurement
|
|
|
|
stdev:
|
|
|
|
type: string (float)
|
|
|
|
description: The standard deviation of IOPS
|
|
|
|
numsamples:
|
|
|
|
type: string (integer)
|
|
|
|
description: The number of samples taken during the test
|
|
|
|
cpu:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
user:
|
|
|
|
type: string (float percentage)
|
|
|
|
description: The percentage of test time spent in user space
|
|
|
|
system:
|
|
|
|
type: string (float percentage)
|
|
|
|
description: The percentage of test time spent in system (kernel) space
|
|
|
|
ctxsw:
|
|
|
|
type: string (integer)
|
|
|
|
description: The number of context switches during the test
|
|
|
|
majfault:
|
|
|
|
type: string (integer)
|
|
|
|
description: The number of major page faults during the test
|
|
|
|
minfault:
|
|
|
|
type: string (integer)
|
|
|
|
description: The number of minor page faults during the test
|
2020-08-24 14:57:52 -04:00
|
|
|
"""
|
2023-11-30 02:01:22 -05:00
|
|
|
return list_benchmarks(config, reqargs.get("job", None))
|
2020-08-24 14:57:52 -04:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid pool must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-08-24 14:57:52 -04:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Execute a storage benchmark against a storage pool
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The PVC storage pool to benchmark
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: string
|
2020-08-25 12:43:16 -04:00
|
|
|
description: The Celery job ID of the benchmark (unused elsewhere)
|
2020-08-24 14:57:52 -04:00
|
|
|
"""
|
|
|
|
# Verify that the pool is valid
|
2021-11-06 03:02:43 -04:00
|
|
|
_list, code = api_helper.ceph_pool_list(
|
|
|
|
reqargs.get("pool", None), is_fuzzy=False
|
|
|
|
)
|
2020-08-24 14:57:52 -04:00
|
|
|
if code != 200:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {
|
|
|
|
"message": 'Pool "{}" is not valid.'.format(reqargs.get("pool"))
|
|
|
|
}, 400
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"storage.benchmark", pool=reqargs.get("pool", None), run_on="primary"
|
2023-11-16 13:22:14 -05:00
|
|
|
)
|
2021-11-06 03:02:43 -04:00
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{
|
|
|
|
"task_id": task.id,
|
|
|
|
"task_name": "storage.benchmark",
|
|
|
|
"run_on": get_primary_node(),
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
202,
|
2023-11-16 01:57:56 -05:00
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
2020-08-24 14:57:52 -04:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Benchmark, "/storage/ceph/benchmark")
|
2020-08-24 14:57:52 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/option
|
|
|
|
class API_Storage_Ceph_Option(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "option",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid option must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "action",
|
|
|
|
"required": True,
|
|
|
|
"choices": ("set", "unset"),
|
|
|
|
"helptext": "A valid action must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Set or unset OSD options on the Ceph cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: option
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The Ceph OSD option to act on; must be valid to "ceph osd set/unset"
|
|
|
|
- in: query
|
|
|
|
name: action
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The action to take
|
|
|
|
enum:
|
|
|
|
- set
|
|
|
|
- unset
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("action") == "set":
|
|
|
|
return api_helper.ceph_osd_set(reqargs.get("option"))
|
|
|
|
if reqargs.get("action") == "unset":
|
|
|
|
return api_helper.ceph_osd_unset(reqargs.get("option"))
|
2020-02-08 20:36:53 -05:00
|
|
|
abort(400)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Option, "/storage/ceph/option")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2021-09-23 13:59:49 -04:00
|
|
|
# /storage/ceph/osddb
|
|
|
|
class API_Storage_Ceph_OSDDB_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "node",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid node must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "device",
|
|
|
|
"required": True,
|
2021-12-24 15:18:38 -05:00
|
|
|
"helptext": "A valid device or detect string must be specified.",
|
2021-11-06 03:02:43 -04:00
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2021-09-23 13:59:49 -04:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Add a Ceph OSD database volume group to the cluster
|
|
|
|
Note: This task may take up to 30s to complete and return
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: node
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The PVC node to create the OSD DB volume group on
|
|
|
|
- in: query
|
|
|
|
name: device
|
|
|
|
type: string
|
|
|
|
required: true
|
2021-12-24 15:18:38 -05:00
|
|
|
description: The block device (e.g. "/dev/sdb", "/dev/disk/by-path/...", etc.) or detect string ("detect:NAME:SIZE:ID") to create the OSD DB volume group on
|
2021-09-23 13:59:49 -04:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-09 14:05:15 -05:00
|
|
|
node = reqargs.get("node", None)
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"osd.add_db_vg", device=reqargs.get("device", None), run_on=node
|
2023-11-16 13:22:14 -05:00
|
|
|
)
|
2023-11-09 14:05:15 -05:00
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "osd.add_db_vg", "run_on": node},
|
2023-11-09 14:05:15 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
2021-09-23 13:59:49 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_OSDDB_Root, "/storage/ceph/osddb")
|
2021-09-23 13:59:49 -04:00
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/osd
|
|
|
|
class API_Storage_Ceph_OSD_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "limit"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of Ceph OSDs in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: osd
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: string (containing integer)
|
|
|
|
description: The Ceph ID of the OSD
|
2021-09-23 13:59:49 -04:00
|
|
|
device:
|
|
|
|
type: string
|
|
|
|
description: The OSD data block device
|
|
|
|
db_device:
|
|
|
|
type: string
|
|
|
|
description: The OSD database/WAL block device (logical volume); empty if not applicable
|
2020-02-08 20:36:53 -05:00
|
|
|
stats:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
uuid:
|
|
|
|
type: string
|
|
|
|
description: The Ceph OSD UUID
|
|
|
|
up:
|
|
|
|
type: boolean integer
|
|
|
|
description: Whether OSD is in "up" state
|
|
|
|
in:
|
|
|
|
type: boolean integer
|
|
|
|
description: Whether OSD is in "in" state
|
|
|
|
primary_affinity:
|
|
|
|
type: integer
|
|
|
|
description: The Ceph primary affinity of the OSD
|
|
|
|
utilization:
|
|
|
|
type: number
|
|
|
|
description: The utilization percentage of the OSD
|
|
|
|
var:
|
|
|
|
type: number
|
|
|
|
description: The usage variability among OSDs
|
|
|
|
pgs:
|
|
|
|
type: integer
|
|
|
|
description: The number of placement groups on this OSD
|
|
|
|
kb:
|
|
|
|
type: integer
|
|
|
|
description: Size of the OSD in KB
|
|
|
|
weight:
|
|
|
|
type: number
|
|
|
|
description: The weight of the OSD in the CRUSH map
|
|
|
|
reweight:
|
|
|
|
type: number
|
|
|
|
description: The active cluster weight of the OSD
|
|
|
|
node:
|
|
|
|
type: string
|
|
|
|
description: The PVC node the OSD resides on
|
|
|
|
used:
|
|
|
|
type: string
|
|
|
|
description: The used space on the OSD in human-readable format
|
|
|
|
avail:
|
|
|
|
type: string
|
|
|
|
description: The free space on the OSD in human-readable format
|
|
|
|
wr_ops:
|
|
|
|
type: integer
|
|
|
|
description: Cluster-lifetime write operations to OSD
|
|
|
|
rd_ops:
|
|
|
|
type: integer
|
|
|
|
description: Cluster-lifetime read operations from OSD
|
|
|
|
wr_data:
|
|
|
|
type: integer
|
|
|
|
description: Cluster-lifetime write size to OSD
|
|
|
|
rd_data:
|
|
|
|
type: integer
|
|
|
|
description: Cluster-lifetime read size from OSD
|
|
|
|
state:
|
|
|
|
type: string
|
|
|
|
description: CSV of the current state of the OSD
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A OSD ID search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/osd'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_osd_list(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "node",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid node must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "device",
|
|
|
|
"required": True,
|
2021-12-24 15:18:38 -05:00
|
|
|
"helptext": "A valid device or detect string must be specified.",
|
2021-11-06 03:02:43 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "weight",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "An OSD weight must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "ext_db_ratio",
|
|
|
|
"required": False,
|
2023-11-01 21:17:38 -04:00
|
|
|
},
|
|
|
|
{
|
2023-11-02 13:29:47 -04:00
|
|
|
"name": "ext_db_size",
|
2023-11-01 21:17:38 -04:00
|
|
|
"required": False,
|
|
|
|
},
|
|
|
|
{
|
2023-11-02 13:29:47 -04:00
|
|
|
"name": "osd_count",
|
2023-11-01 21:17:38 -04:00
|
|
|
"required": False,
|
2021-11-06 03:02:43 -04:00
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Add a Ceph OSD to the cluster
|
2023-11-02 13:29:47 -04:00
|
|
|
Note: This task may take up to 60s to complete and return
|
2020-02-08 20:36:53 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: node
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The PVC node to create the OSD on
|
|
|
|
- in: query
|
|
|
|
name: device
|
|
|
|
type: string
|
|
|
|
required: true
|
2021-12-24 15:18:38 -05:00
|
|
|
description: The block device (e.g. "/dev/sdb", "/dev/disk/by-path/...", etc.) or detect string ("detect:NAME:SIZE:ID") to create the OSD on
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: weight
|
|
|
|
type: number
|
|
|
|
required: true
|
|
|
|
description: The Ceph CRUSH weight for the OSD
|
2021-09-23 23:31:58 -04:00
|
|
|
- in: query
|
|
|
|
name: ext_db_ratio
|
|
|
|
type: float
|
|
|
|
required: false
|
2023-11-02 13:29:47 -04:00
|
|
|
description: If set, creates an OSD DB LV with this decimal ratio of DB to total OSD size (usually 0.05 i.e. 5%); mutually exclusive with ext_db_size
|
2023-11-01 21:17:38 -04:00
|
|
|
- in: query
|
2023-11-02 13:29:47 -04:00
|
|
|
name: ext_db_size
|
|
|
|
type: float
|
2023-11-01 21:17:38 -04:00
|
|
|
required: false
|
2023-11-02 13:29:47 -04:00
|
|
|
description: If set, creates an OSD DB LV with this explicit size in human units (e.g. 1024M, 20G); mutually exclusive with ext_db_ratio
|
2023-11-01 21:17:38 -04:00
|
|
|
- in: query
|
2023-11-02 13:29:47 -04:00
|
|
|
name: osd_count
|
2023-11-01 21:17:38 -04:00
|
|
|
type: integer
|
|
|
|
required: false
|
2023-11-02 13:29:47 -04:00
|
|
|
description: If set, create this many OSDs on the block device instead of 1; usually 2 or 4 depending on size
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-09 14:05:15 -05:00
|
|
|
node = reqargs.get("node", None)
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"osd.add",
|
2023-11-16 11:55:15 -05:00
|
|
|
device=reqargs.get("device", None),
|
|
|
|
weight=reqargs.get("weight", None),
|
|
|
|
ext_db_ratio=reqargs.get("ext_db_ratio", None),
|
|
|
|
ext_db_size=reqargs.get("ext_db_size", None),
|
|
|
|
split_count=reqargs.get("osd_count", None),
|
2023-11-09 14:05:15 -05:00
|
|
|
run_on=node,
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "osd.add", "run_on": node},
|
2023-11-09 14:05:15 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_OSD_Root, "/storage/ceph/osd")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/osd/<osdid>
|
|
|
|
class API_Storage_Ceph_OSD_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, osdid):
|
|
|
|
"""
|
|
|
|
Return information about Ceph OSD {osdid}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/osd'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_osd_list(osdid)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2022-05-06 15:31:58 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
2023-11-03 01:45:49 -04:00
|
|
|
"name": "new_device",
|
2022-05-06 15:31:58 -04:00
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid device or detect string must be specified.",
|
|
|
|
},
|
2023-11-03 01:45:49 -04:00
|
|
|
{
|
|
|
|
"name": "old_device",
|
|
|
|
"required": False,
|
|
|
|
},
|
2022-05-06 15:31:58 -04:00
|
|
|
{
|
|
|
|
"name": "weight",
|
2023-11-03 01:45:49 -04:00
|
|
|
"required": False,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "ext_db_ratio",
|
|
|
|
"required": False,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "ext_db_size",
|
|
|
|
"required": False,
|
2022-05-06 15:31:58 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "yes-i-really-mean-it",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "Please confirm that 'yes-i-really-mean-it'.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def post(self, osdid, reqargs):
|
|
|
|
"""
|
|
|
|
Replace a Ceph OSD in the cluster
|
|
|
|
Note: This task may take up to 30s to complete and return
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
2023-11-03 01:45:49 -04:00
|
|
|
name: new_device
|
2022-05-06 15:31:58 -04:00
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The block device (e.g. "/dev/sdb", "/dev/disk/by-path/...", etc.) or detect string ("detect:NAME:SIZE:ID") to replace the OSD onto
|
2023-11-03 01:45:49 -04:00
|
|
|
- in: query
|
|
|
|
name: old_device
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The block device (e.g. "/dev/sdb", "/dev/disk/by-path/...", etc.) or detect string ("detect:NAME:SIZE:ID") of the original OSD
|
2022-05-06 15:31:58 -04:00
|
|
|
- in: query
|
|
|
|
name: weight
|
|
|
|
type: number
|
2023-11-03 01:45:49 -04:00
|
|
|
required: false
|
|
|
|
description: The Ceph CRUSH weight for the replacement OSD
|
|
|
|
- in: query
|
|
|
|
name: ext_db_ratio
|
|
|
|
type: float
|
|
|
|
required: false
|
|
|
|
description: If set, creates an OSD DB LV for the replcement OSD with this decimal ratio of DB to total OSD size (usually 0.05 i.e. 5%); if unset, use existing ext_db_size
|
|
|
|
- in: query
|
|
|
|
name: ext_db_size
|
|
|
|
type: float
|
|
|
|
required: false
|
|
|
|
description: If set, creates an OSD DB LV for the replacement OSD with this explicit size in human units (e.g. 1024M, 20G); if unset, use existing ext_db_size
|
2022-05-06 15:31:58 -04:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-09 14:05:15 -05:00
|
|
|
osd_node_detail, retcode = api_helper.ceph_osd_node(osdid)
|
|
|
|
if retcode == 200:
|
|
|
|
node = osd_node_detail["node"]
|
|
|
|
else:
|
|
|
|
return osd_node_detail, retcode
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"osd.replace",
|
2023-11-16 11:55:15 -05:00
|
|
|
osd_id=osdid,
|
|
|
|
new_device=reqargs.get("new_device"),
|
|
|
|
old_device=reqargs.get("old_device", None),
|
|
|
|
weight=reqargs.get("weight", None),
|
|
|
|
ext_db_ratio=reqargs.get("ext_db_ratio", None),
|
|
|
|
ext_db_size=reqargs.get("ext_db_size", None),
|
2023-11-09 14:05:15 -05:00
|
|
|
run_on=node,
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "osd.replace", "run_on": node},
|
2023-11-09 14:05:15 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
2022-05-06 15:31:58 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "device",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid device or detect string must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def put(self, osdid, reqargs):
|
|
|
|
"""
|
|
|
|
Refresh (reimport) a Ceph OSD in the cluster
|
|
|
|
Note: This task may take up to 30s to complete and return
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: device
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The block device (e.g. "/dev/sdb", "/dev/disk/by-path/...", etc.) or detect string ("detect:NAME:SIZE:ID") that the OSD should be using
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-09 14:05:15 -05:00
|
|
|
osd_node_detail, retcode = api_helper.ceph_osd_node(osdid)
|
|
|
|
if retcode == 200:
|
|
|
|
node = osd_node_detail["node"]
|
|
|
|
else:
|
|
|
|
return osd_node_detail, retcode
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"osd.refresh",
|
2023-11-16 11:55:15 -05:00
|
|
|
osd_id=osdid,
|
|
|
|
device=reqargs.get("device", None),
|
|
|
|
ext_db_flag=False,
|
2023-11-09 14:05:15 -05:00
|
|
|
run_on=node,
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "osd.refresh", "run_on": node},
|
2023-11-09 14:05:15 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
2022-05-06 15:31:58 -04:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
2022-04-29 11:16:33 -04:00
|
|
|
{
|
|
|
|
"name": "force",
|
|
|
|
"required": False,
|
|
|
|
"helptext": "Force removal even if steps fail.",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{
|
|
|
|
"name": "yes-i-really-mean-it",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "Please confirm that 'yes-i-really-mean-it'.",
|
2022-04-29 11:16:33 -04:00
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def delete(self, osdid, reqargs):
|
|
|
|
"""
|
|
|
|
Remove Ceph OSD {osdid}
|
|
|
|
Note: This task may take up to 30s to complete and return
|
|
|
|
Warning: This operation may have unintended consequences for the storage cluster; ensure the cluster can support removing the OSD before proceeding
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
2022-04-29 11:16:33 -04:00
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
required: flase
|
|
|
|
description: Force removal even if some step(s) fail
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: yes-i-really-mean-it
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A confirmation string to ensure that the API consumer really means it
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2023-11-09 14:05:15 -05:00
|
|
|
osd_node_detail, retcode = api_helper.ceph_osd_node(osdid)
|
|
|
|
if retcode == 200:
|
|
|
|
node = osd_node_detail["node"]
|
|
|
|
else:
|
|
|
|
return osd_node_detail, retcode
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"osd.remove",
|
2023-11-16 11:55:15 -05:00
|
|
|
osd_id=osdid,
|
2023-11-09 14:05:15 -05:00
|
|
|
force_flag=reqargs.get("force", False),
|
|
|
|
run_on=node,
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{"task_id": task.id, "task_name": "osd.remove", "run_on": node},
|
2023-11-09 14:05:15 -05:00
|
|
|
202,
|
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_OSD_Element, "/storage/ceph/osd/<osdid>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/osd/<osdid>/state
|
|
|
|
class API_Storage_Ceph_OSD_State(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, osdid):
|
|
|
|
"""
|
|
|
|
Return the current state of OSD {osdid}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
state:
|
|
|
|
type: string
|
|
|
|
description: The current OSD state
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_osd_state(osdid)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "state",
|
|
|
|
"choices": ("in", "out"),
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid state must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, osdid, reqargs):
|
|
|
|
"""
|
|
|
|
Set the current state of OSD {osdid}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: state
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Set the OSD to this state
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("state", None) == "in":
|
|
|
|
return api_helper.ceph_osd_in(osdid)
|
|
|
|
if reqargs.get("state", None) == "out":
|
|
|
|
return api_helper.ceph_osd_out(osdid)
|
2020-02-08 20:36:53 -05:00
|
|
|
abort(400)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_OSD_State, "/storage/ceph/osd/<osdid>/state")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/pool
|
|
|
|
class API_Storage_Ceph_Pool_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of pools in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: pool
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the pool
|
2020-12-01 03:39:26 -05:00
|
|
|
volume_count:
|
|
|
|
type: integer
|
|
|
|
description: The number of volumes in the pool
|
2021-12-28 20:39:50 -05:00
|
|
|
tier:
|
|
|
|
type: string
|
|
|
|
description: The device class/tier of the pool
|
2021-12-28 21:08:04 -05:00
|
|
|
pgs:
|
|
|
|
type: integer
|
|
|
|
description: The number of PGs (placement groups) for the pool
|
2020-02-08 20:36:53 -05:00
|
|
|
stats:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: The Ceph pool ID
|
2021-02-09 01:49:15 -05:00
|
|
|
stored_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The stored data size (in bytes, post-replicas)
|
2020-02-08 20:36:53 -05:00
|
|
|
free_bytes:
|
|
|
|
type: integer
|
2021-02-09 01:49:15 -05:00
|
|
|
description: The total free space (in bytes. post-replicas)
|
2020-02-08 20:36:53 -05:00
|
|
|
used_bytes:
|
|
|
|
type: integer
|
2021-02-09 01:49:15 -05:00
|
|
|
description: The total used space (in bytes, pre-replicas)
|
2020-02-08 20:36:53 -05:00
|
|
|
used_percent:
|
|
|
|
type: number
|
|
|
|
description: The ratio of used space to free space
|
|
|
|
num_objects:
|
|
|
|
type: integer
|
|
|
|
description: The number of Ceph objects before replication
|
|
|
|
num_object_clones:
|
|
|
|
type: integer
|
|
|
|
description: The total number of cloned Ceph objects
|
|
|
|
num_object_copies:
|
|
|
|
type: integer
|
|
|
|
description: The total number of Ceph objects after replication
|
|
|
|
num_objects_missing_on_primary:
|
|
|
|
type: integer
|
|
|
|
description: The total number of missing-on-primary Ceph objects
|
|
|
|
num_objects_unfound:
|
|
|
|
type: integer
|
|
|
|
description: The total number of unfound Ceph objects
|
|
|
|
num_objects_degraded:
|
|
|
|
type: integer
|
|
|
|
description: The total number of degraded Ceph objects
|
|
|
|
read_ops:
|
|
|
|
type: integer
|
|
|
|
description: The total read operations on the pool (pool-lifetime)
|
|
|
|
read_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The total read bytes on the pool (pool-lifetime)
|
|
|
|
write_ops:
|
|
|
|
type: integer
|
|
|
|
description: The total write operations on the pool (pool-lifetime)
|
|
|
|
write_bytes:
|
|
|
|
type: integer
|
|
|
|
description: The total write bytes on the pool (pool-lifetime)
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A pool name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/pool'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_pool_list(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A pool name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "pgs",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A placement group count must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "replcfg",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid replication configuration must be specified.",
|
|
|
|
},
|
2021-12-28 20:39:50 -05:00
|
|
|
{
|
|
|
|
"name": "tier",
|
|
|
|
"required": False,
|
|
|
|
"choices": ("hdd", "ssd", "nvme", "default"),
|
|
|
|
"helptext": "A valid tier must be specified",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new Ceph pool
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the pool
|
|
|
|
- in: query
|
|
|
|
name: pgs
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The number of placement groups (PGs) for the pool
|
|
|
|
- in: query
|
|
|
|
name: replcfg
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The replication configuration (e.g. "copies=3,mincopies=2") for the pool
|
2021-12-28 20:39:50 -05:00
|
|
|
- in: query
|
|
|
|
name: tier
|
|
|
|
required: false
|
|
|
|
description: The device tier for the pool (hdd, ssd, nvme, or default)
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_pool_add(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("pgs", None),
|
|
|
|
reqargs.get("replcfg", None),
|
2021-12-28 20:39:50 -05:00
|
|
|
reqargs.get("tier", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Pool_Root, "/storage/ceph/pool")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/pool/<pool>
|
|
|
|
class API_Storage_Ceph_Pool_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, pool):
|
|
|
|
"""
|
|
|
|
Return information about {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/pool'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_pool_list(pool, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pgs",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A placement group count must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "replcfg",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid replication configuration must be specified.",
|
|
|
|
},
|
2021-12-28 20:39:50 -05:00
|
|
|
{
|
|
|
|
"name": "tier",
|
|
|
|
"required": False,
|
|
|
|
"choices": ("hdd", "ssd", "nvme", "default"),
|
|
|
|
"helptext": "A valid tier must be specified",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2020-11-07 13:28:59 -05:00
|
|
|
def post(self, pool, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
Create a new Ceph pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pgs
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The number of placement groups (PGs) for the pool
|
|
|
|
- in: query
|
|
|
|
name: replcfg
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The replication configuration (e.g. "copies=3,mincopies=2") for the pool
|
2021-12-28 20:39:50 -05:00
|
|
|
- in: query
|
|
|
|
name: tier
|
|
|
|
required: false
|
|
|
|
description: The device tier for the pool (hdd, ssd, nvme, or default)
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-02-17 11:14:50 -05:00
|
|
|
return api_helper.ceph_pool_add(
|
2021-12-28 20:39:50 -05:00
|
|
|
pool,
|
|
|
|
reqargs.get("pgs", None),
|
|
|
|
reqargs.get("replcfg", None),
|
|
|
|
reqargs.get("tier", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-12-28 21:41:41 -05:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pgs",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A placement group count must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Authenticator
|
|
|
|
def put(self, pool, reqargs):
|
|
|
|
"""
|
|
|
|
Adjust Ceph pool {pool}'s placement group count
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pgs
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The new number of placement groups (PGs) for the pool
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_pool_set_pgs(
|
|
|
|
pool,
|
|
|
|
reqargs.get("pgs", 0),
|
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "yes-i-really-mean-it",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "Please confirm that 'yes-i-really-mean-it'.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def delete(self, pool, reqargs):
|
|
|
|
"""
|
|
|
|
Remove Ceph pool {pool}
|
|
|
|
Note: This task may take up to 30s to complete and return
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: yes-i-really-mean-it
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: A confirmation string to ensure that the API consumer really means it
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_pool_remove(pool)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Pool_Element, "/storage/ceph/pool/<pool>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/volume
|
|
|
|
class API_Storage_Ceph_Volume_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}, {"name": "pool"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of volumes in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: volume
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the volume
|
|
|
|
pool:
|
|
|
|
type: string
|
|
|
|
description: The name of the pool containing the volume
|
|
|
|
stats:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: The name of the volume
|
|
|
|
id:
|
|
|
|
type: string
|
|
|
|
description: The Ceph volume ID
|
|
|
|
size:
|
|
|
|
type: string
|
|
|
|
description: The size of the volume (human-readable values)
|
|
|
|
objects:
|
|
|
|
type: integer
|
|
|
|
description: The number of Ceph objects making up the volume
|
|
|
|
order:
|
|
|
|
type: integer
|
|
|
|
description: The Ceph volume order ID
|
|
|
|
object_size:
|
|
|
|
type: integer
|
|
|
|
description: The size of each object in bytes
|
|
|
|
snapshot_count:
|
|
|
|
type: integer
|
|
|
|
description: The number of snapshots of the volume
|
|
|
|
block_name_prefix:
|
|
|
|
type: string
|
|
|
|
description: The Ceph-internal block name prefix
|
|
|
|
format:
|
|
|
|
type: integer
|
|
|
|
description: The Ceph RBD volume format
|
|
|
|
features:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: The Ceph RBD feature
|
|
|
|
op_features:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: The Ceph RBD operational features
|
|
|
|
flags:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: The Ceph RBD volume flags
|
|
|
|
create_timestamp:
|
|
|
|
type: string
|
|
|
|
description: The volume creation timestamp
|
|
|
|
access_timestamp:
|
|
|
|
type: string
|
|
|
|
description: The volume access timestamp
|
|
|
|
modify_timestamp:
|
|
|
|
type: string
|
|
|
|
description: The volume modification timestamp
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A volume name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A pool to limit the search to
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/volume'
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_list(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None), reqargs.get("limit", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "volume",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A volume name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid pool name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "size",
|
|
|
|
"required": True,
|
2023-10-03 09:42:23 -04:00
|
|
|
"helptext": "A volume size in bytes (B implied or with SI suffix k/M/G/T) must be specified.",
|
2021-11-06 03:02:43 -04:00
|
|
|
},
|
2024-02-02 10:13:46 -05:00
|
|
|
{
|
|
|
|
"name": "force",
|
|
|
|
"required": False,
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new Ceph volume
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: volume
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the volume
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The name of the pool to contain the volume
|
|
|
|
- in: query
|
|
|
|
name: size
|
|
|
|
type: string
|
|
|
|
required: true
|
2023-10-03 09:42:23 -04:00
|
|
|
description: The volume size, in bytes (B implied) or with a single-character SI suffix (k/M/G/T)
|
2024-02-02 10:13:46 -05:00
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: flase
|
|
|
|
description: Force action if volume creation would violate 80% full soft cap on the pool
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_add(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("volume", None),
|
|
|
|
reqargs.get("size", None),
|
2024-08-20 10:10:33 -04:00
|
|
|
bool(strtobool(reqargs.get("force", "False"))),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Volume_Root, "/storage/ceph/volume")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/volume/<pool>/<volume>
|
|
|
|
class API_Storage_Ceph_Volume_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, pool, volume):
|
|
|
|
"""
|
|
|
|
Return information about volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/volume'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_volume_list(pool, volume, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "size",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A volume size in bytes (or with k/M/G/T suffix) must be specified.",
|
2024-02-02 10:13:46 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "force",
|
|
|
|
"required": False,
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, pool, volume, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new Ceph volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: size
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The volume size in bytes (or with a metric suffix, i.e. k/M/G/T)
|
2024-02-02 10:13:46 -05:00
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: flase
|
|
|
|
description: Force action if volume creation would violate 80% full soft cap on the pool
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2024-02-02 10:13:46 -05:00
|
|
|
return api_helper.ceph_volume_add(
|
|
|
|
pool, volume, reqargs.get("size", None), reqargs.get("force", False)
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2024-02-02 10:13:46 -05:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "new_size"},
|
|
|
|
{"name": "new_name"},
|
|
|
|
{"name": "force", "required": False},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, pool, volume, reqargs):
|
|
|
|
"""
|
|
|
|
Update the size or name of Ceph volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: size
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The new volume size in bytes (or with a metric suffix, i.e. k/M/G/T); must be greater than the previous size (shrinking not supported)
|
|
|
|
- in: query
|
|
|
|
name: new_name
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The new volume name
|
2024-02-02 10:13:46 -05:00
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: flase
|
|
|
|
description: Force action if new volume size would violate 80% full soft cap on the pool
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("new_size", None) and reqargs.get("new_name", None):
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "Can only perform one modification at once"}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("new_size", None):
|
2024-02-02 10:13:46 -05:00
|
|
|
return api_helper.ceph_volume_resize(
|
|
|
|
pool, volume, reqargs.get("new_size"), reqargs.get("force", False)
|
|
|
|
)
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("new_name", None):
|
|
|
|
return api_helper.ceph_volume_rename(pool, volume, reqargs.get("new_name"))
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "At least one modification must be specified"}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, pool, volume):
|
|
|
|
"""
|
|
|
|
Remove Ceph volume {volume} from pool {pool}
|
|
|
|
Note: This task may take up to 30s to complete and return depending on the size of the volume
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_volume_remove(pool, volume)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Storage_Ceph_Volume_Element, "/storage/ceph/volume/<pool>/<volume>"
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/volume/<pool>/<volume>/clone
|
|
|
|
class API_Storage_Ceph_Volume_Element_Clone(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "new_volume",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A new volume name must be specified.",
|
2024-02-02 10:29:34 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "force",
|
|
|
|
"required": False,
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, pool, volume, reqargs):
|
|
|
|
"""
|
|
|
|
Clone Ceph volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: new_volume
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the new cloned volume
|
2024-02-02 10:29:34 -05:00
|
|
|
- in: query
|
|
|
|
name: force
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
default: flase
|
|
|
|
description: Force action if clone volume size would violate 80% full soft cap on the pool
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_clone(
|
2024-02-02 10:29:34 -05:00
|
|
|
pool, reqargs.get("new_volume", None), volume, reqargs.get("force", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Storage_Ceph_Volume_Element_Clone, "/storage/ceph/volume/<pool>/<volume>/clone"
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-09 13:43:48 -05:00
|
|
|
# /storage/ceph/volume/<pool>/<volume>/upload
|
|
|
|
class API_Storage_Ceph_Volume_Element_Upload(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "image_format",
|
|
|
|
"required": True,
|
|
|
|
"location": ["args"],
|
|
|
|
"helptext": "A source image format must be specified.",
|
2023-09-29 16:13:08 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "file_size",
|
|
|
|
"required": False,
|
|
|
|
"location": ["args"],
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-09 13:43:48 -05:00
|
|
|
@Authenticator
|
2020-02-09 19:43:07 -05:00
|
|
|
def post(self, pool, volume, reqargs):
|
2020-02-09 13:43:48 -05:00
|
|
|
"""
|
|
|
|
Upload a disk image to Ceph volume {volume} in pool {pool}
|
2020-02-09 21:08:27 -05:00
|
|
|
|
|
|
|
The body must be a form body containing a file that is the binary contents of the image.
|
2020-02-09 13:43:48 -05:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
2020-02-09 19:43:07 -05:00
|
|
|
name: image_format
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The type of source image file
|
|
|
|
enum:
|
|
|
|
- raw
|
|
|
|
- vmdk
|
|
|
|
- qcow2
|
|
|
|
- qed
|
|
|
|
- vdi
|
|
|
|
- vpc
|
2023-09-29 16:13:08 -04:00
|
|
|
- in: query
|
|
|
|
name: file_size
|
|
|
|
type: integer
|
|
|
|
required: false
|
2023-10-03 09:39:19 -04:00
|
|
|
description: The size of the image file, in bytes, if {image_format} is not "raw"
|
2020-02-09 13:43:48 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_upload(
|
2023-09-29 16:13:08 -04:00
|
|
|
pool,
|
|
|
|
volume,
|
|
|
|
reqargs.get("image_format", None),
|
|
|
|
reqargs.get("file_size", None),
|
2020-02-09 13:43:48 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Storage_Ceph_Volume_Element_Upload,
|
|
|
|
"/storage/ceph/volume/<pool>/<volume>/upload",
|
|
|
|
)
|
2020-02-09 13:43:48 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/snapshot
|
|
|
|
class API_Storage_Ceph_Snapshot_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "pool"},
|
|
|
|
{"name": "volume"},
|
|
|
|
{"name": "limit"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of snapshots in the cluster
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: snapshot
|
|
|
|
properties:
|
|
|
|
snapshot:
|
|
|
|
type: string
|
|
|
|
description: The name of the snapshot
|
|
|
|
volume:
|
|
|
|
type: string
|
|
|
|
description: The name of the volume
|
|
|
|
pool:
|
|
|
|
type: string
|
|
|
|
description: The name of the pool
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A volume name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A pool to limit the search to
|
|
|
|
- in: query
|
|
|
|
name: volume
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A volume to limit the search to
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/snapshot'
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_snapshot_list(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("volume", None),
|
|
|
|
reqargs.get("limit", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "snapshot",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A snapshot name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "volume",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A volume name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A pool name must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new Ceph snapshot
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the snapshot
|
|
|
|
- in: query
|
|
|
|
name: volume
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the volume
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The name of the pool
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_snapshot_add(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("volume", None),
|
|
|
|
reqargs.get("snapshot", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Storage_Ceph_Snapshot_Root, "/storage/ceph/snapshot")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /storage/ceph/snapshot/<pool>/<volume>/<snapshot>
|
|
|
|
class API_Storage_Ceph_Snapshot_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, pool, volume, snapshot):
|
|
|
|
"""
|
|
|
|
Return information about snapshot {snapshot} of volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/snapshot'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_snapshot_list(
|
2021-11-06 03:02:43 -04:00
|
|
|
pool, volume, snapshot, is_fuzzy=False
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def post(self, pool, volume, snapshot):
|
|
|
|
"""
|
|
|
|
Create a new Ceph snapshot {snapshot} of volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the snapshot
|
|
|
|
- in: query
|
|
|
|
name: volume
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the volume
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The name of the pool
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_volume_snapshot_add(pool, volume, snapshot)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "new_name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A new name must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, pool, volume, snapshot, reqargs):
|
|
|
|
"""
|
|
|
|
Update the name of Ceph snapshot {snapshot} of volume {volume} in pool {pool}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: new_name
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The new snaoshot name
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_snapshot_rename(
|
2021-11-06 03:02:43 -04:00
|
|
|
pool, volume, snapshot, reqargs.get("new_name", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, pool, volume, snapshot):
|
|
|
|
"""
|
|
|
|
Remove Ceph snapshot {snapshot} of volume {volume} from pool {pool}
|
|
|
|
Note: This task may take up to 30s to complete and return depending on the size of the snapshot
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_helper.ceph_volume_snapshot_remove(pool, volume, snapshot)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Storage_Ceph_Snapshot_Element,
|
|
|
|
"/storage/ceph/snapshot/<pool>/<volume>/<snapshot>",
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
|
2024-05-13 15:22:03 -04:00
|
|
|
# /storage/ceph/snapshot/<pool>/<volume>/<snapshot>/rollback
|
|
|
|
class API_Storage_Ceph_Snapshot_Rollback_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def post(self, pool, volume, snapshot):
|
|
|
|
"""
|
|
|
|
Roll back an RBD volume {volume} in pool {pool} to snapshot {snapshot}
|
|
|
|
|
|
|
|
WARNING: This action cannot be done on an active RBD volume. All IO MUST be stopped first.
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- storage / ceph
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: snapshot
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the snapshot
|
|
|
|
- in: query
|
|
|
|
name: volume
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: The name of the volume
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: The name of the pool
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_helper.ceph_volume_snapshot_rollback(pool, volume, snapshot)
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(
|
|
|
|
API_Storage_Ceph_Snapshot_Rollback_Element,
|
|
|
|
"/storage/ceph/snapshot/<pool>/<volume>/<snapshot>/rollback",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
##########################################################
|
|
|
|
# Provisioner API
|
|
|
|
##########################################################
|
|
|
|
|
2023-09-12 16:41:02 -04:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner
|
|
|
|
class API_Provisioner_Root(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
Unused endpoint
|
|
|
|
"""
|
|
|
|
abort(404)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Root, "/provisioner")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template
|
|
|
|
class API_Provisioner_Template_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of all templates
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: all-templates
|
|
|
|
properties:
|
|
|
|
system-templates:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/system-template'
|
|
|
|
network-templates:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/network-template'
|
|
|
|
storage-templates:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/storage-template'
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A template name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/all-templates'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.template_list(reqargs.get("limit", None))
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Template_Root, "/provisioner/template")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/system
|
|
|
|
class API_Provisioner_Template_System_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of system templates
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: system-template
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner template ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: Template name
|
|
|
|
vcpu_count:
|
|
|
|
type: integer
|
|
|
|
description: vCPU count for VM
|
|
|
|
vram_mb:
|
|
|
|
type: integer
|
|
|
|
description: vRAM size in MB for VM
|
|
|
|
serial:
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable serial console for VM
|
|
|
|
vnc:
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable VNC console for VM
|
|
|
|
vnc_bind:
|
|
|
|
type: string
|
|
|
|
description: VNC bind address when VNC console is enabled
|
|
|
|
node_limit:
|
|
|
|
type: string
|
|
|
|
description: CSV list of node(s) to limit VM assignment to
|
|
|
|
node_selector:
|
|
|
|
type: string
|
|
|
|
description: Selector to use for VM node assignment on migration/move
|
|
|
|
node_autostart:
|
|
|
|
type: boolean
|
|
|
|
description: Whether to start VM with node ready state (one-time)
|
2020-10-29 11:31:32 -04:00
|
|
|
migration_method:
|
|
|
|
type: string
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime:
|
|
|
|
type: integer
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
2020-02-08 20:36:53 -05:00
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A template name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/system-template'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_template_system(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "name", "required": True, "helptext": "A name must be specified."},
|
|
|
|
{
|
|
|
|
"name": "vcpus",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A vcpus value must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "vram",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A vram value in MB must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "serial",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A serial value must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "vnc",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A vnc value must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "vnc_bind"},
|
|
|
|
{"name": "node_limit"},
|
|
|
|
{"name": "node_selector"},
|
|
|
|
{"name": "node_autostart"},
|
|
|
|
{"name": "migration_method"},
|
2024-01-10 16:13:31 -05:00
|
|
|
{"name": "migration_max_downtime"},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new system template
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Template name
|
|
|
|
- in: query
|
|
|
|
name: vcpus
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: vCPU count for VM
|
|
|
|
- in: query
|
|
|
|
name: vram
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: vRAM size in MB for VM
|
|
|
|
- in: query
|
|
|
|
name: serial
|
|
|
|
type: boolean
|
|
|
|
required: true
|
|
|
|
description: Whether to enable serial console for VM
|
|
|
|
- in: query
|
|
|
|
name: vnc
|
|
|
|
type: boolean
|
|
|
|
required: true
|
|
|
|
description: Whether to enable VNC console for VM
|
|
|
|
- in: query
|
|
|
|
name: vnc_bind
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: VNC bind address when VNC console is enabled
|
|
|
|
- in: query
|
|
|
|
name: node_limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: CSV list of node(s) to limit VM assignment to
|
|
|
|
- in: query
|
|
|
|
name: node_selector
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Selector to use for VM node assignment on migration/move
|
|
|
|
- in: query
|
|
|
|
name: node_autostart
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to start VM with node ready state (one-time)
|
2020-10-29 11:31:32 -04:00
|
|
|
- in: query
|
|
|
|
name: migration_method
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
2024-01-10 16:13:31 -05:00
|
|
|
- in: query
|
|
|
|
name: migration_max_downtime
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
# Validate arguments
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
vcpus = int(reqargs.get("vcpus"))
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "A vcpus value must be an integer"}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
vram = int(reqargs.get("vram"))
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "A vram value must be an integer"}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
# Cast boolean arguments
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("serial", "false"))):
|
2020-02-08 20:36:53 -05:00
|
|
|
serial = True
|
|
|
|
else:
|
|
|
|
serial = False
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("vnc", "false"))):
|
2020-02-08 20:36:53 -05:00
|
|
|
vnc = True
|
2021-11-06 03:02:43 -04:00
|
|
|
vnc_bind = reqargs.get("vnc_bind", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
|
|
|
vnc = False
|
|
|
|
vnc_bind = None
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("node_autostart", None) and bool(
|
|
|
|
strtobool(reqargs.get("node_autostart", "false"))
|
|
|
|
):
|
2020-02-08 20:36:53 -05:00
|
|
|
node_autostart = True
|
|
|
|
else:
|
|
|
|
node_autostart = False
|
|
|
|
|
|
|
|
return api_provisioner.create_template_system(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("name"),
|
2020-02-08 20:36:53 -05:00
|
|
|
vcpus,
|
|
|
|
vram,
|
|
|
|
serial,
|
|
|
|
vnc,
|
|
|
|
vnc_bind,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("node_limit", None),
|
|
|
|
reqargs.get("node_selector", None),
|
2020-10-29 11:31:32 -04:00
|
|
|
node_autostart,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("migration_method", None),
|
2024-01-10 16:13:31 -05:00
|
|
|
reqargs.get("migration_max_downtime", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Template_System_Root, "/provisioner/template/system")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/system/<template>
|
|
|
|
class API_Provisioner_Template_System_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, template):
|
|
|
|
"""
|
|
|
|
Return information about system template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/system-template'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_template_system(template, is_fuzzy=False)
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "vcpus",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A vcpus value must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "vram",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A vram value in MB must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "serial",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A serial value must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "vnc",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A vnc value must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "vnc_bind"},
|
|
|
|
{"name": "node_limit"},
|
|
|
|
{"name": "node_selector"},
|
|
|
|
{"name": "node_autostart"},
|
|
|
|
{"name": "migration_method"},
|
2024-01-10 16:13:31 -05:00
|
|
|
{"name": "migration_max_downtime"},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, template, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new system template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: vcpus
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: vCPU count for VM
|
|
|
|
- in: query
|
|
|
|
name: vram
|
|
|
|
type: integer
|
|
|
|
required: true
|
|
|
|
description: vRAM size in MB for VM
|
|
|
|
- in: query
|
|
|
|
name: serial
|
|
|
|
type: boolean
|
|
|
|
required: true
|
|
|
|
description: Whether to enable serial console for VM
|
|
|
|
- in: query
|
|
|
|
name: vnc
|
|
|
|
type: boolean
|
|
|
|
required: true
|
|
|
|
description: Whether to enable VNC console for VM
|
|
|
|
- in: query
|
|
|
|
name: vnc_bind
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: VNC bind address when VNC console is enabled
|
|
|
|
- in: query
|
|
|
|
name: node_limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: CSV list of node(s) to limit VM assignment to
|
|
|
|
- in: query
|
|
|
|
name: node_selector
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Selector to use for VM node assignment on migration/move
|
|
|
|
- in: query
|
|
|
|
name: node_autostart
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to start VM with node ready state (one-time)
|
2020-10-29 11:31:32 -04:00
|
|
|
- in: query
|
|
|
|
name: migration_method
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
2024-01-10 16:13:31 -05:00
|
|
|
- in: query
|
|
|
|
name: migration_max_downtime
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
# Validate arguments
|
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
vcpus = int(reqargs.get("vcpus"))
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "A vcpus value must be an integer"}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
try:
|
2021-11-06 03:02:43 -04:00
|
|
|
vram = int(reqargs.get("vram"))
|
2020-11-06 18:55:10 -05:00
|
|
|
except Exception:
|
2020-11-07 12:57:42 -05:00
|
|
|
return {"message": "A vram value must be an integer"}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
# Cast boolean arguments
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("serial", False))):
|
2020-02-08 20:36:53 -05:00
|
|
|
serial = True
|
|
|
|
else:
|
|
|
|
serial = False
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("vnc", False))):
|
2020-02-08 20:36:53 -05:00
|
|
|
vnc = True
|
2021-11-06 03:02:43 -04:00
|
|
|
vnc_bind = reqargs.get("vnc_bind", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
|
|
|
vnc = False
|
|
|
|
vnc_bind = None
|
2021-11-06 03:02:43 -04:00
|
|
|
if reqargs.get("node_autostart", None) and bool(
|
|
|
|
strtobool(reqargs.get("node_autostart", False))
|
|
|
|
):
|
2020-02-08 20:36:53 -05:00
|
|
|
node_autostart = True
|
|
|
|
else:
|
|
|
|
node_autostart = False
|
|
|
|
|
|
|
|
return api_provisioner.create_template_system(
|
|
|
|
template,
|
|
|
|
vcpus,
|
|
|
|
vram,
|
|
|
|
serial,
|
|
|
|
vnc,
|
|
|
|
vnc_bind,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("node_limit", None),
|
|
|
|
reqargs.get("node_selector", None),
|
2020-10-29 11:31:32 -04:00
|
|
|
node_autostart,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("migration_method", None),
|
2024-01-10 16:13:31 -05:00
|
|
|
reqargs.get("migration_max_downtime", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "vcpus"},
|
|
|
|
{"name": "vram"},
|
|
|
|
{"name": "serial"},
|
|
|
|
{"name": "vnc"},
|
|
|
|
{"name": "vnc_bind"},
|
|
|
|
{"name": "node_limit"},
|
|
|
|
{"name": "node_selector"},
|
|
|
|
{"name": "node_autostart"},
|
|
|
|
{"name": "migration_method"},
|
2024-01-10 16:13:31 -05:00
|
|
|
{"name": "migration_max_downtime"},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2020-02-18 16:18:27 -05:00
|
|
|
def put(self, template, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
2020-02-18 16:18:27 -05:00
|
|
|
Modify an existing system template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: vcpus
|
|
|
|
type: integer
|
|
|
|
description: vCPU count for VM
|
|
|
|
- in: query
|
|
|
|
name: vram
|
|
|
|
type: integer
|
|
|
|
description: vRAM size in MB for VM
|
|
|
|
- in: query
|
|
|
|
name: serial
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable serial console for VM
|
|
|
|
- in: query
|
|
|
|
name: vnc
|
|
|
|
type: boolean
|
|
|
|
description: Whether to enable VNC console for VM
|
|
|
|
- in: query
|
|
|
|
name: vnc_bind
|
|
|
|
type: string
|
|
|
|
description: VNC bind address when VNC console is enabled
|
|
|
|
- in: query
|
|
|
|
name: node_limit
|
|
|
|
type: string
|
|
|
|
description: CSV list of node(s) to limit VM assignment to
|
|
|
|
- in: query
|
|
|
|
name: node_selector
|
|
|
|
type: string
|
|
|
|
description: Selector to use for VM node assignment on migration/move
|
|
|
|
- in: query
|
|
|
|
name: node_autostart
|
|
|
|
type: boolean
|
|
|
|
description: Whether to start VM with node ready state (one-time)
|
2020-10-29 11:31:32 -04:00
|
|
|
- in: query
|
|
|
|
name: migration_method
|
|
|
|
type: string
|
|
|
|
description: The preferred migration method (live, shutdown, none)
|
2024-01-10 16:13:31 -05:00
|
|
|
- in: query
|
|
|
|
name: migration_max_downtime
|
|
|
|
type: integer
|
|
|
|
description: The maximum time in milliseconds that a VM can be down for during a live migration; busy VMs may require a larger max_downtime
|
2020-02-18 16:18:27 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
2020-02-18 16:18:27 -05:00
|
|
|
return api_provisioner.modify_template_system(
|
|
|
|
template,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("vcpus", None),
|
|
|
|
reqargs.get("vram", None),
|
|
|
|
reqargs.get("serial", None),
|
|
|
|
reqargs.get("vnc", None),
|
|
|
|
reqargs.get("vnc_bind"),
|
|
|
|
reqargs.get("node_limit", None),
|
|
|
|
reqargs.get("node_selector", None),
|
|
|
|
reqargs.get("node_autostart", None),
|
|
|
|
reqargs.get("migration_method", None),
|
2024-01-10 16:13:31 -05:00
|
|
|
reqargs.get("migration_max_downtime", None),
|
2020-02-18 16:18:27 -05:00
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, template):
|
|
|
|
"""
|
|
|
|
Remove system template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_template_system(template)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_System_Element, "/provisioner/template/system/<template>"
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/network
|
|
|
|
class API_Provisioner_Template_Network_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of network templates
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: network-template-net
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner template ID
|
|
|
|
network_template:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner network template ID
|
|
|
|
vni:
|
|
|
|
type: integer
|
|
|
|
description: PVC network VNI
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: network-template
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner template ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: Template name
|
|
|
|
mac_template:
|
|
|
|
type: string
|
|
|
|
description: MAC address template for VM
|
|
|
|
networks:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/network-template-net'
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A template name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/network-template'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_template_network(reqargs.get("limit", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A template name must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "mac_template"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new network template
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Template name
|
|
|
|
- in: query
|
|
|
|
name: mac_template
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: MAC address template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_template_network(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("name", None), reqargs.get("mac_template", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Template_Network_Root, "/provisioner/template/network")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/network/<template>
|
|
|
|
class API_Provisioner_Template_Network_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, template):
|
|
|
|
"""
|
|
|
|
Return information about network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/network-template'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_template_network(template, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "mac_template"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, template, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: mac_template
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: MAC address template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_template_network(
|
2021-11-06 03:02:43 -04:00
|
|
|
template, reqargs.get("mac_template", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, template):
|
|
|
|
"""
|
|
|
|
Remove network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_template_network(template)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_Network_Element, "/provisioner/template/network/<template>"
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/network/<template>/net
|
|
|
|
class API_Provisioner_Template_Network_Net_Root(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, template):
|
|
|
|
"""
|
|
|
|
Return a list of networks in network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/network-template-net'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
templates = api_provisioner.list_template_network(template, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
if templates:
|
2021-11-06 03:02:43 -04:00
|
|
|
return templates["networks"]
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "Template not found."}, 404
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "vni",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A valid VNI must be specified.",
|
2024-02-09 12:12:04 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "permit_duplicate",
|
|
|
|
"required": False,
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2020-11-07 13:30:32 -05:00
|
|
|
def post(self, template, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
Create a new network in network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: vni
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: PVC network VNI
|
2024-02-09 12:12:04 -05:00
|
|
|
- in: query
|
|
|
|
name: permit_duplicate
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Bypass checks to permit duplicate VNIs for niche usecases
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_template_network_element(
|
2024-02-09 12:12:04 -05:00
|
|
|
template, reqargs.get("vni", None), reqargs.get("permit_duplicate", False)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_Network_Net_Root,
|
|
|
|
"/provisioner/template/network/<template>/net",
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/network/<template>/net/<vni>
|
|
|
|
class API_Provisioner_Template_Network_Net_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, template, vni):
|
|
|
|
"""
|
|
|
|
Return information about network {vni} in network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/network-template-net'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
vni_list = api_provisioner.list_template_network(template, is_fuzzy=False)[
|
|
|
|
"networks"
|
|
|
|
]
|
2020-02-08 20:36:53 -05:00
|
|
|
for _vni in vni_list:
|
2021-11-06 03:02:43 -04:00
|
|
|
if int(_vni["vni"]) == int(vni):
|
2020-02-08 20:36:53 -05:00
|
|
|
return _vni, 200
|
|
|
|
abort(404)
|
|
|
|
|
2024-02-09 12:12:04 -05:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "permit_duplicate",
|
|
|
|
"required": False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2024-02-09 12:12:04 -05:00
|
|
|
def post(self, template, vni, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
Create a new network {vni} in network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
2024-02-09 12:12:04 -05:00
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: permit_duplicate
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Bypass checks to permit duplicate VNIs for niche usecases
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2024-02-09 12:12:04 -05:00
|
|
|
return api_provisioner.create_template_network_element(
|
|
|
|
template, vni, reqargs.get("permit_duplicate", False)
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, template, vni):
|
|
|
|
"""
|
|
|
|
Remove network {vni} from network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_template_network_element(template, vni)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_Network_Net_Element,
|
|
|
|
"/provisioner/template/network/<template>/net/<vni>",
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/storage
|
|
|
|
class API_Provisioner_Template_Storage_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of storage templates
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: storage-template-disk
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner disk ID
|
|
|
|
storage_template:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner storage template ID
|
|
|
|
pool:
|
|
|
|
type: string
|
|
|
|
description: Ceph storage pool for disk
|
|
|
|
disk_id:
|
|
|
|
type: string
|
|
|
|
description: Disk identifier
|
|
|
|
disk_size_gb:
|
|
|
|
type: string
|
|
|
|
description: Disk size in GB
|
|
|
|
mountpoint:
|
|
|
|
type: string
|
|
|
|
description: In-VM mountpoint for disk
|
|
|
|
filesystem:
|
|
|
|
type: string
|
|
|
|
description: Filesystem for disk
|
|
|
|
filesystem_args:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: Filesystem mkfs arguments
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: storage-template
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner template ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: Template name
|
|
|
|
disks:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/storage-template-disk'
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A template name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/storage-template'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_template_storage(reqargs.get("limit", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A template name must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new storage template
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Template name
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.create_template_storage(reqargs.get("name", None))
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Template_Storage_Root, "/provisioner/template/storage")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/storage/<template>
|
|
|
|
class API_Provisioner_Template_Storage_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, template):
|
|
|
|
"""
|
|
|
|
Return information about storage template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/storage-template'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_template_storage(template, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def post(self, template):
|
|
|
|
"""
|
|
|
|
Create a new storage template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.create_template_storage(template)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, template):
|
|
|
|
"""
|
|
|
|
Remove storage template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_template_storage(template)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_Storage_Element, "/provisioner/template/storage/<template>"
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/storage/<template>/disk
|
|
|
|
class API_Provisioner_Template_Storage_Disk_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, template, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of disks in network template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/storage-template-disk'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
templates = api_provisioner.list_template_storage(template, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
if templates:
|
2021-11-06 03:02:43 -04:00
|
|
|
return templates["disks"]
|
2020-02-08 20:36:53 -05:00
|
|
|
else:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {"message": "Template not found."}, 404
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "disk_id",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A disk identifier in sdX or vdX format must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A storage pool must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "source_volume"},
|
|
|
|
{"name": "disk_size"},
|
|
|
|
{"name": "filesystem"},
|
|
|
|
{"name": "filesystem_arg", "action": "append"},
|
|
|
|
{"name": "mountpoint"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, template, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new disk in storage template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: disk_id
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Disk identifier in "sdX"/"vdX" format (e.g. "sda", "vdb", etc.)
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: ceph storage pool for disk
|
|
|
|
- in: query
|
|
|
|
name: source_volume
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Source storage volume; not compatible with other options
|
|
|
|
- in: query
|
|
|
|
name: disk_size
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: Disk size in GB; not compatible with source_volume
|
|
|
|
- in: query
|
|
|
|
name: filesystem
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Filesystem for disk; not compatible with source_volume
|
|
|
|
- in: query
|
|
|
|
name: filesystem_arg
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Filesystem mkfs argument in "-X=foo" format; may be specified multiple times to add multiple arguments
|
|
|
|
- in: query
|
|
|
|
name: mountpoint
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: In-VM mountpoint for disk; not compatible with source_volume
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_template_storage_element(
|
|
|
|
template,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("disk_id", None),
|
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("source_volume", None),
|
|
|
|
reqargs.get("disk_size", None),
|
|
|
|
reqargs.get("filesystem", None),
|
|
|
|
reqargs.get("filesystem_arg", []),
|
|
|
|
reqargs.get("mountpoint", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_Storage_Disk_Root,
|
|
|
|
"/provisioner/template/storage/<template>/disk",
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/template/storage/<template>/disk/<disk_id>
|
|
|
|
class API_Provisioner_Template_Storage_Disk_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, template, disk_id):
|
|
|
|
"""
|
|
|
|
Return information about disk {disk_id} in storage template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/storage-template-disk'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
disk_list = api_provisioner.list_template_storage(template, is_fuzzy=False)[
|
|
|
|
"disks"
|
|
|
|
]
|
2020-02-08 20:36:53 -05:00
|
|
|
for _disk in disk_list:
|
2021-11-06 03:02:43 -04:00
|
|
|
if _disk["disk_id"] == disk_id:
|
2020-02-08 20:36:53 -05:00
|
|
|
return _disk, 200
|
|
|
|
abort(404)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A storage pool must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "source_volume"},
|
|
|
|
{"name": "disk_size"},
|
|
|
|
{"name": "filesystem"},
|
|
|
|
{"name": "filesystem_arg", "action": "append"},
|
|
|
|
{"name": "mountpoint"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, template, disk_id, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new disk {disk_id} in storage template {template}
|
|
|
|
Alternative to "POST /provisioner/template/storage/<template>/disk?disk_id=<disk_id>"
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: ceph storage pool for disk
|
|
|
|
- in: query
|
|
|
|
name: source_volume
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Source storage volume; not compatible with other options
|
|
|
|
- in: query
|
|
|
|
name: disk_size
|
|
|
|
type: integer
|
|
|
|
required: false
|
|
|
|
description: Disk size in GB; not compatible with source_volume
|
|
|
|
- in: query
|
|
|
|
name: filesystem
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Filesystem for disk; not compatible with source_volume
|
|
|
|
- in: query
|
|
|
|
name: filesystem_arg
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Filesystem mkfs argument in "-X=foo" format; may be specified multiple times to add multiple arguments
|
|
|
|
- in: query
|
|
|
|
name: mountpoint
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: In-VM mountpoint for disk; not compatible with source_volume
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_template_storage_element(
|
|
|
|
template,
|
|
|
|
disk_id,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("source_volume", None),
|
|
|
|
reqargs.get("disk_size", None),
|
|
|
|
reqargs.get("filesystem", None),
|
|
|
|
reqargs.get("filesystem_arg", []),
|
|
|
|
reqargs.get("mountpoint", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, template, disk_id):
|
|
|
|
"""
|
|
|
|
Remove disk {disk_id} from storage template {template}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner / template
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_template_storage_element(template, disk_id)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(
|
|
|
|
API_Provisioner_Template_Storage_Disk_Element,
|
|
|
|
"/provisioner/template/storage/<template>/disk/<disk_id>",
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/userdata
|
|
|
|
class API_Provisioner_Userdata_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of userdata documents
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: userdata
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: Userdata name
|
|
|
|
userdata:
|
|
|
|
type: string
|
|
|
|
description: Raw userdata configuration document
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A userdata name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/userdata'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_userdata(reqargs.get("limit", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "name", "required": True, "helptext": "A name must be specified."},
|
|
|
|
{
|
|
|
|
"name": "data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A userdata document must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new userdata document
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Userdata name
|
|
|
|
- in: query
|
|
|
|
name: data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Raw userdata configuration document
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_userdata(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("name", None), reqargs.get("data", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Userdata_Root, "/provisioner/userdata")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/userdata/<userdata>
|
|
|
|
class API_Provisioner_Userdata_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, userdata):
|
|
|
|
"""
|
|
|
|
Return information about userdata document {userdata}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/userdata'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_userdata(userdata, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A userdata document must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, userdata, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new userdata document {userdata}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Raw userdata configuration document
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.create_userdata(userdata, reqargs.get("data", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A userdata document must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, userdata, reqargs):
|
|
|
|
"""
|
|
|
|
Update userdata document {userdata}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Raw userdata configuration document
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.update_userdata(userdata, reqargs.get("data", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, userdata):
|
|
|
|
"""
|
|
|
|
Remove userdata document {userdata}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_userdata(userdata)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Userdata_Element, "/provisioner/userdata/<userdata>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/script
|
|
|
|
class API_Provisioner_Script_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of scripts
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: script
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner script ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: Script name
|
|
|
|
script:
|
|
|
|
type: string
|
|
|
|
description: Raw Python script document
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A script name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/script'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_script(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A script name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A script document must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new script
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Script name
|
|
|
|
- in: query
|
|
|
|
name: data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Raw Python script document
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_script(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("name", None), reqargs.get("data", None)
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Script_Root, "/provisioner/script")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/script/<script>
|
|
|
|
class API_Provisioner_Script_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, script):
|
|
|
|
"""
|
|
|
|
Return information about script {script}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/script'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_script(script, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A script document must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
2020-11-07 13:28:59 -05:00
|
|
|
def post(self, script, reqargs):
|
2020-02-08 20:36:53 -05:00
|
|
|
"""
|
|
|
|
Create a new script {script}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Raw Python script document
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.create_script(script, reqargs.get("data", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "data",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A script document must be specified.",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, script, reqargs):
|
|
|
|
"""
|
|
|
|
Update script {script}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: data
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Raw Python script document
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.update_script(script, reqargs.get("data", None))
|
2020-02-08 20:36:53 -05:00
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, script):
|
|
|
|
"""
|
|
|
|
Remove script {script}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_script(script)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Script_Element, "/provisioner/script/<script>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-17 22:52:49 -05:00
|
|
|
# /provisioner/profile
|
|
|
|
class API_Provisioner_OVA_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-17 22:52:49 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of OVA sources
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: ova
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner OVA ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: OVA name
|
|
|
|
volumes:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
type: object
|
|
|
|
id: ova_volume
|
|
|
|
properties:
|
|
|
|
disk_id:
|
|
|
|
type: string
|
|
|
|
description: Disk identifier
|
|
|
|
disk_size_gb:
|
|
|
|
type: string
|
|
|
|
description: Disk size in GB
|
|
|
|
pool:
|
|
|
|
type: string
|
|
|
|
description: Pool containing the OVA volume
|
|
|
|
volume_name:
|
|
|
|
type: string
|
|
|
|
description: Storage volume containing the OVA image
|
|
|
|
volume_format:
|
|
|
|
type: string
|
|
|
|
description: OVA image format
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: An OVA name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/ova'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_ova.list_ova(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"location": ["args"],
|
|
|
|
"helptext": "A storage pool must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"required": True,
|
|
|
|
"location": ["args"],
|
|
|
|
"helptext": "A VM name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "ova_size",
|
|
|
|
"required": True,
|
|
|
|
"location": ["args"],
|
|
|
|
"helptext": "An OVA size must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-17 22:52:49 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Upload an OVA image to the cluster
|
|
|
|
|
|
|
|
The API client is responsible for determining and setting the ova_size value, as this value cannot be determined dynamically before the upload proceeds.
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Storage pool name
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: OVA name on the cluster (usually identical to the OVA file name)
|
|
|
|
- in: query
|
|
|
|
name: ova_size
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Size of the OVA file in bytes
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_ova.upload_ova(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
|
|
|
reqargs.get("name", None),
|
|
|
|
reqargs.get("ova_size", None),
|
2020-02-17 22:52:49 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_OVA_Root, "/provisioner/ova")
|
2020-02-17 22:52:49 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-17 22:52:49 -05:00
|
|
|
# /provisioner/ova/<ova>
|
|
|
|
class API_Provisioner_OVA_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, ova):
|
|
|
|
"""
|
|
|
|
Return information about OVA image {ova}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/ova'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_ova.list_ova(ova, is_fuzzy=False)
|
2020-02-17 22:52:49 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "pool",
|
|
|
|
"required": True,
|
|
|
|
"location": ["args"],
|
|
|
|
"helptext": "A storage pool must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "ova_size",
|
|
|
|
"required": True,
|
|
|
|
"location": ["args"],
|
|
|
|
"helptext": "An OVA size must be specified.",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2020-02-17 22:52:49 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, ova, reqargs):
|
|
|
|
"""
|
|
|
|
Upload an OVA image to the cluster
|
|
|
|
|
|
|
|
The API client is responsible for determining and setting the ova_size value, as this value cannot be determined dynamically before the upload proceeds.
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: pool
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Storage pool name
|
|
|
|
- in: query
|
|
|
|
name: ova_size
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Size of the OVA file in bytes
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_ova.upload_ova(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("pool", None),
|
2020-02-17 22:52:49 -05:00
|
|
|
ova,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("ova_size", None),
|
2020-02-17 22:52:49 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, ova):
|
|
|
|
"""
|
|
|
|
Remove ova {ova}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_ova.delete_ova(ova)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_OVA_Element, "/provisioner/ova/<ova>")
|
2020-02-17 22:52:49 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/profile
|
|
|
|
class API_Provisioner_Profile_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser([{"name": "limit"}])
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def get(self, reqargs):
|
|
|
|
"""
|
|
|
|
Return a list of profiles
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
definitions:
|
|
|
|
- schema:
|
|
|
|
type: object
|
|
|
|
id: profile
|
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
type: integer
|
|
|
|
description: Internal provisioner profile ID
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
description: Profile name
|
|
|
|
script:
|
|
|
|
type: string
|
|
|
|
description: Script name
|
|
|
|
system_template:
|
|
|
|
type: string
|
|
|
|
description: System template name
|
|
|
|
network_template:
|
|
|
|
type: string
|
|
|
|
description: Network template name
|
|
|
|
storage_template:
|
|
|
|
type: string
|
|
|
|
description: Storage template name
|
|
|
|
userdata:
|
|
|
|
type: string
|
|
|
|
description: Userdata template name
|
|
|
|
arguments:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
type: string
|
|
|
|
description: Script install() function keyword arguments in "arg=data" format
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: limit
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: A profile name search limit; fuzzy by default, use ^/$ to force exact matches
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: list
|
|
|
|
items:
|
|
|
|
$ref: '#/definitions/profile'
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_profile(reqargs.get("limit", None))
|
|
|
|
|
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A profile name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "profile_type",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A profile type must be specified.",
|
|
|
|
},
|
2022-10-06 10:27:08 -04:00
|
|
|
{
|
|
|
|
"name": "system_template",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A system_template must be specified.",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "network_template"},
|
|
|
|
{"name": "storage_template"},
|
|
|
|
{"name": "userdata"},
|
2022-10-06 10:27:08 -04:00
|
|
|
{
|
|
|
|
"name": "script",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A script must be specified.",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "ova"},
|
|
|
|
{"name": "arg", "action": "append"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new profile
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Profile name
|
|
|
|
- in: query
|
2020-02-17 22:52:49 -05:00
|
|
|
name: profile_type
|
2020-02-08 20:36:53 -05:00
|
|
|
type: string
|
|
|
|
required: true
|
2020-02-17 22:52:49 -05:00
|
|
|
description: Profile type
|
|
|
|
enum:
|
|
|
|
- provisioner
|
|
|
|
- ova
|
|
|
|
- in: query
|
|
|
|
name: script
|
|
|
|
type: string
|
2022-10-06 10:27:08 -04:00
|
|
|
required: true
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Script name
|
|
|
|
- in: query
|
|
|
|
name: system_template
|
|
|
|
type: string
|
2022-10-06 10:27:08 -04:00
|
|
|
required: true
|
2020-02-08 20:36:53 -05:00
|
|
|
description: System template name
|
|
|
|
- in: query
|
|
|
|
name: network_template
|
|
|
|
type: string
|
2020-02-17 22:52:49 -05:00
|
|
|
required: false
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Network template name
|
|
|
|
- in: query
|
|
|
|
name: storage_template
|
|
|
|
type: string
|
2020-02-17 22:52:49 -05:00
|
|
|
required: false
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Storage template name
|
|
|
|
- in: query
|
|
|
|
name: userdata
|
|
|
|
type: string
|
2020-02-17 22:52:49 -05:00
|
|
|
required: false
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Userdata template name
|
2020-02-17 22:52:49 -05:00
|
|
|
- in: query
|
|
|
|
name: ova
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: OVA image source
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: arg
|
|
|
|
type: string
|
|
|
|
description: Script install() function keywork argument in "arg=data" format; may be specified multiple times to add multiple arguments
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_profile(
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("name", None),
|
|
|
|
reqargs.get("profile_type", None),
|
|
|
|
reqargs.get("system_template", None),
|
|
|
|
reqargs.get("network_template", None),
|
|
|
|
reqargs.get("storage_template", None),
|
|
|
|
reqargs.get("userdata", None),
|
|
|
|
reqargs.get("script", None),
|
|
|
|
reqargs.get("ova", None),
|
|
|
|
reqargs.get("arg", []),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Profile_Root, "/provisioner/profile")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/profile/<profile>
|
|
|
|
class API_Provisioner_Profile_Element(Resource):
|
|
|
|
@Authenticator
|
|
|
|
def get(self, profile):
|
|
|
|
"""
|
|
|
|
Return information about profile {profile}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
$ref: '#/definitions/profile'
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.list_profile(profile, is_fuzzy=False)
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "profile_type",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A profile type must be specified.",
|
|
|
|
},
|
2022-10-06 10:27:08 -04:00
|
|
|
{
|
|
|
|
"name": "system_template",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A system_template must be specified.",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "network_template"},
|
|
|
|
{"name": "storage_template"},
|
|
|
|
{"name": "userdata"},
|
2022-10-06 10:27:08 -04:00
|
|
|
{
|
|
|
|
"name": "script",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A script must be specified.",
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
{"name": "ova"},
|
|
|
|
{"name": "arg", "action": "append"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, profile, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new profile {profile}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
2020-02-17 22:52:49 -05:00
|
|
|
- in: query
|
|
|
|
name: profile_type
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Profile type
|
|
|
|
enum:
|
|
|
|
- provisioner
|
|
|
|
- ova
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: script
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Script name
|
|
|
|
- in: query
|
|
|
|
name: system_template
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: System template name
|
|
|
|
- in: query
|
|
|
|
name: network_template
|
|
|
|
type: string
|
2022-10-06 10:27:08 -04:00
|
|
|
required: false
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Network template name
|
|
|
|
- in: query
|
|
|
|
name: storage_template
|
|
|
|
type: string
|
2022-10-06 10:27:08 -04:00
|
|
|
required: false
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Storage template name
|
|
|
|
- in: query
|
|
|
|
name: userdata
|
|
|
|
type: string
|
2022-10-06 10:27:08 -04:00
|
|
|
required: false
|
2020-02-08 20:36:53 -05:00
|
|
|
description: Userdata template name
|
2020-02-17 22:52:49 -05:00
|
|
|
- in: query
|
|
|
|
name: ova
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: OVA image source
|
2020-02-08 20:36:53 -05:00
|
|
|
- in: query
|
|
|
|
name: arg
|
|
|
|
type: string
|
|
|
|
description: Script install() function keywork argument in "arg=data" format; may be specified multiple times to add multiple arguments
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.create_profile(
|
|
|
|
profile,
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("profile_type", None),
|
|
|
|
reqargs.get("system_template", None),
|
|
|
|
reqargs.get("network_template", None),
|
|
|
|
reqargs.get("storage_template", None),
|
|
|
|
reqargs.get("userdata", None),
|
|
|
|
reqargs.get("script", None),
|
|
|
|
reqargs.get("ova", None),
|
|
|
|
reqargs.get("arg", []),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{"name": "system_template"},
|
|
|
|
{"name": "network_template"},
|
|
|
|
{"name": "storage_template"},
|
|
|
|
{"name": "userdata"},
|
|
|
|
{"name": "script"},
|
|
|
|
{"name": "arg", "action": "append"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def put(self, profile, reqargs):
|
|
|
|
"""
|
|
|
|
Modify profile {profile}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: script
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Script name
|
|
|
|
- in: query
|
|
|
|
name: system_template
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: System template name
|
|
|
|
- in: query
|
|
|
|
name: network_template
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Network template name
|
|
|
|
- in: query
|
|
|
|
name: storage_template
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Storage template name
|
|
|
|
- in: query
|
|
|
|
name: userdata
|
|
|
|
type: string
|
|
|
|
required: false
|
|
|
|
description: Userdata template name
|
|
|
|
- in: query
|
|
|
|
name: arg
|
|
|
|
type: string
|
|
|
|
description: Script install() function keywork argument in "arg=data" format; may be specified multiple times to add multiple arguments
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
return api_provisioner.modify_profile(
|
|
|
|
profile,
|
2020-11-07 13:11:03 -05:00
|
|
|
None, # Can't modify the profile type
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("system_template", None),
|
|
|
|
reqargs.get("network_template", None),
|
|
|
|
reqargs.get("storage_template", None),
|
|
|
|
reqargs.get("userdata", None),
|
|
|
|
reqargs.get("script", None),
|
2020-11-07 13:11:03 -05:00
|
|
|
None, # Can't modify the OVA
|
2021-11-06 03:02:43 -04:00
|
|
|
reqargs.get("arg", []),
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
@Authenticator
|
|
|
|
def delete(self, profile):
|
|
|
|
"""
|
|
|
|
Remove profile {profile}
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
404:
|
|
|
|
description: Not found
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
2021-11-06 03:02:43 -04:00
|
|
|
return api_provisioner.delete_profile(profile)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Profile_Element, "/provisioner/profile/<profile>")
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-08 20:36:53 -05:00
|
|
|
# /provisioner/create
|
|
|
|
class API_Provisioner_Create_Root(Resource):
|
2021-11-06 03:02:43 -04:00
|
|
|
@RequestParser(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A VM name must be specified.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "profile",
|
|
|
|
"required": True,
|
|
|
|
"helptext": "A profile name must be specified.",
|
|
|
|
},
|
|
|
|
{"name": "define_vm"},
|
|
|
|
{"name": "start_vm"},
|
|
|
|
{"name": "arg", "action": "append"},
|
|
|
|
]
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
@Authenticator
|
|
|
|
def post(self, reqargs):
|
|
|
|
"""
|
|
|
|
Create a new virtual machine
|
|
|
|
Note: Starts a background job in the pvc-provisioner-worker Celery worker while returning a task ID; the task ID can be used to query the "GET /provisioner/status/<task_id>" endpoint for the job status
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- provisioner
|
|
|
|
parameters:
|
|
|
|
- in: query
|
|
|
|
name: name
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Virtual machine name
|
|
|
|
- in: query
|
|
|
|
name: profile
|
|
|
|
type: string
|
|
|
|
required: true
|
|
|
|
description: Profile name
|
|
|
|
- in: query
|
|
|
|
name: define_vm
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to define the VM on the cluster during provisioning
|
|
|
|
- in: query
|
|
|
|
name: start_vm
|
|
|
|
type: boolean
|
|
|
|
required: false
|
|
|
|
description: Whether to start the VM after provisioning
|
2020-07-08 13:18:12 -04:00
|
|
|
- in: query
|
|
|
|
name: arg
|
|
|
|
type: string
|
|
|
|
description: Script install() function keywork argument in "arg=data" format; may be specified multiple times to add multiple arguments
|
2020-02-08 20:36:53 -05:00
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: OK
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
properties:
|
|
|
|
task_id:
|
|
|
|
type: string
|
|
|
|
description: Task ID for the provisioner Celery worker
|
|
|
|
400:
|
|
|
|
description: Bad request
|
|
|
|
schema:
|
|
|
|
type: object
|
|
|
|
id: Message
|
|
|
|
"""
|
|
|
|
# Verify that the profile is valid
|
2021-11-06 03:02:43 -04:00
|
|
|
_list, code = api_provisioner.list_profile(
|
|
|
|
reqargs.get("profile", None), is_fuzzy=False
|
|
|
|
)
|
2020-02-08 20:36:53 -05:00
|
|
|
if code != 200:
|
2021-11-06 03:02:43 -04:00
|
|
|
return {
|
|
|
|
"message": 'Profile "{}" is not valid.'.format(reqargs.get("profile"))
|
|
|
|
}, 400
|
2020-02-08 20:36:53 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("define_vm", "true"))):
|
2020-02-08 20:36:53 -05:00
|
|
|
define_vm = True
|
|
|
|
else:
|
|
|
|
define_vm = False
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
if bool(strtobool(reqargs.get("start_vm", "true"))):
|
2020-02-08 20:36:53 -05:00
|
|
|
start_vm = True
|
|
|
|
else:
|
|
|
|
start_vm = False
|
|
|
|
|
2023-11-16 13:22:14 -05:00
|
|
|
task = run_celery_task(
|
2023-11-30 00:40:09 -05:00
|
|
|
"provisioner.create",
|
2023-11-16 11:55:15 -05:00
|
|
|
vm_name=reqargs.get("name", None),
|
|
|
|
profile_name=reqargs.get("profile", None),
|
2020-02-08 20:36:53 -05:00
|
|
|
define_vm=define_vm,
|
2020-07-08 13:18:12 -04:00
|
|
|
start_vm=start_vm,
|
2021-11-06 03:02:43 -04:00
|
|
|
script_run_args=reqargs.get("arg", []),
|
2023-11-16 01:57:56 -05:00
|
|
|
run_on="primary",
|
2021-11-06 03:02:43 -04:00
|
|
|
)
|
|
|
|
return (
|
2023-11-16 14:50:02 -05:00
|
|
|
{
|
|
|
|
"task_id": task.id,
|
|
|
|
"task_name": "provisioner.create",
|
|
|
|
"run_on": get_primary_node(),
|
|
|
|
},
|
2021-11-06 03:02:43 -04:00
|
|
|
202,
|
2023-11-16 01:57:56 -05:00
|
|
|
{"Location": Api.url_for(api, API_Tasks_Element, task_id=task.id)},
|
2020-02-08 20:36:53 -05:00
|
|
|
)
|
2020-11-07 13:17:49 -05:00
|
|
|
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
api.add_resource(API_Provisioner_Create_Root, "/provisioner/create")
|