Lint: E302 expected 2 blank lines, found X
This commit is contained in:
@ -30,6 +30,7 @@ import daemon_lib.ceph as pvc_ceph
|
||||
|
||||
config = None # Set in this namespace by flaskapi
|
||||
|
||||
|
||||
def strtobool(stringv):
|
||||
if stringv is None:
|
||||
return False
|
||||
@ -40,6 +41,7 @@ def strtobool(stringv):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Exceptions (used by Celery tasks)
|
||||
#
|
||||
@ -66,6 +68,7 @@ class BenchmarkError(Exception):
|
||||
# Common functions
|
||||
#
|
||||
|
||||
|
||||
# Database connections
|
||||
def open_database(config):
|
||||
conn = psycopg2.connect(
|
||||
@ -78,12 +81,14 @@ def open_database(config):
|
||||
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||
return conn, cur
|
||||
|
||||
|
||||
def close_database(conn, cur, failed=False):
|
||||
if not failed:
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
def list_benchmarks(job=None):
|
||||
if job is not None:
|
||||
query = "SELECT * FROM {} WHERE job = %s;".format('storage_benchmarks')
|
||||
@ -109,6 +114,7 @@ def list_benchmarks(job=None):
|
||||
else:
|
||||
return {'message': 'No benchmark found.'}, 404
|
||||
|
||||
|
||||
def run_benchmark(self, pool):
|
||||
# Runtime imports
|
||||
import time
|
||||
|
@ -38,6 +38,7 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
API_VERSION = 1.0
|
||||
|
||||
|
||||
def strtobool(stringv):
|
||||
if stringv is None:
|
||||
return False
|
||||
@ -137,6 +138,7 @@ app.register_blueprint(blueprint)
|
||||
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
|
||||
celery.conf.update(app.config)
|
||||
|
||||
|
||||
#
|
||||
# Custom decorators
|
||||
#
|
||||
@ -168,6 +170,7 @@ class RequestParser(object):
|
||||
return function(*args, **kwargs)
|
||||
return wrapped_function
|
||||
|
||||
|
||||
# Authentication decorator function
|
||||
def Authenticator(function):
|
||||
@wraps(function)
|
||||
@ -196,6 +199,7 @@ def Authenticator(function):
|
||||
def create_vm(self, vm_name, profile_name, define_vm=True, start_vm=True, script_run_args=[]):
|
||||
return api_provisioner.create_vm(self, vm_name, profile_name, define_vm=define_vm, start_vm=start_vm, script_run_args=script_run_args)
|
||||
|
||||
|
||||
@celery.task(bind=True)
|
||||
def run_benchmark(self, pool):
|
||||
return api_benchmark.run_benchmark(self, pool)
|
||||
@ -230,6 +234,7 @@ class API_Root(Resource):
|
||||
|
||||
api.add_resource(API_Root, '/')
|
||||
|
||||
|
||||
# /doc - NOTE: Until flask_swagger is packaged for Debian this must be disabled
|
||||
# class API_Doc(Resource):
|
||||
# def get(self):
|
||||
@ -251,6 +256,7 @@ api.add_resource(API_Root, '/')
|
||||
#
|
||||
# api.add_resource(API_Doc, '/doc')
|
||||
|
||||
|
||||
# /login
|
||||
class API_Login(Resource):
|
||||
def post(self):
|
||||
@ -294,6 +300,7 @@ class API_Login(Resource):
|
||||
|
||||
api.add_resource(API_Login, '/login')
|
||||
|
||||
|
||||
# /logout
|
||||
class API_Logout(Resource):
|
||||
def post(self):
|
||||
@ -320,6 +327,7 @@ class API_Logout(Resource):
|
||||
|
||||
api.add_resource(API_Logout, '/logout')
|
||||
|
||||
|
||||
# /initialize
|
||||
class API_Initialize(Resource):
|
||||
@Authenticator
|
||||
@ -351,6 +359,7 @@ class API_Initialize(Resource):
|
||||
|
||||
api.add_resource(API_Initialize, '/initialize')
|
||||
|
||||
|
||||
# /status
|
||||
class API_Status(Resource):
|
||||
@Authenticator
|
||||
@ -588,6 +597,7 @@ class API_Node_Root(Resource):
|
||||
|
||||
api.add_resource(API_Node_Root, '/node')
|
||||
|
||||
|
||||
# /node/<node>
|
||||
class API_Node_Element(Resource):
|
||||
@Authenticator
|
||||
@ -613,6 +623,7 @@ class API_Node_Element(Resource):
|
||||
|
||||
api.add_resource(API_Node_Element, '/node/<node>')
|
||||
|
||||
|
||||
# /node/<node>/daemon-state
|
||||
class API_Node_DaemonState(Resource):
|
||||
@Authenticator
|
||||
@ -646,6 +657,7 @@ class API_Node_DaemonState(Resource):
|
||||
|
||||
api.add_resource(API_Node_DaemonState, '/node/<node>/daemon-state')
|
||||
|
||||
|
||||
# /node/<node>/coordinator-state
|
||||
class API_Node_CoordinatorState(Resource):
|
||||
@Authenticator
|
||||
@ -716,6 +728,7 @@ class API_Node_CoordinatorState(Resource):
|
||||
|
||||
api.add_resource(API_Node_CoordinatorState, '/node/<node>/coordinator-state')
|
||||
|
||||
|
||||
# /node/<node>/domain-state
|
||||
class API_Node_DomainState(Resource):
|
||||
@Authenticator
|
||||
@ -1128,6 +1141,7 @@ class API_VM_Root(Resource):
|
||||
|
||||
api.add_resource(API_VM_Root, '/vm')
|
||||
|
||||
|
||||
# /vm/<vm>
|
||||
class API_VM_Element(Resource):
|
||||
@Authenticator
|
||||
@ -1310,6 +1324,7 @@ class API_VM_Element(Resource):
|
||||
|
||||
api.add_resource(API_VM_Element, '/vm/<vm>')
|
||||
|
||||
|
||||
# /vm/<vm>/meta
|
||||
class API_VM_Metadata(Resource):
|
||||
@Authenticator
|
||||
@ -1425,6 +1440,7 @@ class API_VM_Metadata(Resource):
|
||||
|
||||
api.add_resource(API_VM_Metadata, '/vm/<vm>/meta')
|
||||
|
||||
|
||||
# /vm/<vm</state
|
||||
class API_VM_State(Resource):
|
||||
@Authenticator
|
||||
@ -1512,6 +1528,7 @@ class API_VM_State(Resource):
|
||||
|
||||
api.add_resource(API_VM_State, '/vm/<vm>/state')
|
||||
|
||||
|
||||
# /vm/<vm>/node
|
||||
class API_VM_Node(Resource):
|
||||
@Authenticator
|
||||
@ -1614,6 +1631,7 @@ class API_VM_Node(Resource):
|
||||
|
||||
api.add_resource(API_VM_Node, '/vm/<vm>/node')
|
||||
|
||||
|
||||
# /vm/<vm>/locks
|
||||
class API_VM_Locks(Resource):
|
||||
@Authenticator
|
||||
@ -1640,6 +1658,7 @@ class API_VM_Locks(Resource):
|
||||
|
||||
api.add_resource(API_VM_Locks, '/vm/<vm>/locks')
|
||||
|
||||
|
||||
# /vm/<vm</console
|
||||
class API_VM_Console(Resource):
|
||||
@RequestParser([
|
||||
@ -1885,6 +1904,7 @@ class API_Network_Root(Resource):
|
||||
|
||||
api.add_resource(API_Network_Root, '/network')
|
||||
|
||||
|
||||
# /network/<vni>
|
||||
class API_Network_Element(Resource):
|
||||
@Authenticator
|
||||
@ -2133,6 +2153,7 @@ class API_Network_Element(Resource):
|
||||
|
||||
api.add_resource(API_Network_Element, '/network/<vni>')
|
||||
|
||||
|
||||
# /network/<vni>/lease
|
||||
class API_Network_Lease_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -2254,6 +2275,7 @@ class API_Network_Lease_Root(Resource):
|
||||
|
||||
api.add_resource(API_Network_Lease_Root, '/network/<vni>/lease')
|
||||
|
||||
|
||||
# /network/<vni>/lease/{mac}
|
||||
class API_Network_Lease_Element(Resource):
|
||||
@Authenticator
|
||||
@ -2382,6 +2404,7 @@ class API_Network_Lease_Element(Resource):
|
||||
|
||||
api.add_resource(API_Network_Lease_Element, '/network/<vni>/lease/<mac>')
|
||||
|
||||
|
||||
# /network/<vni>/acl
|
||||
class API_Network_ACL_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -2506,6 +2529,7 @@ class API_Network_ACL_Root(Resource):
|
||||
|
||||
api.add_resource(API_Network_ACL_Root, '/network/<vni>/acl')
|
||||
|
||||
|
||||
# /network/<vni>/acl/<description>
|
||||
class API_Network_ACL_Element(Resource):
|
||||
@Authenticator
|
||||
@ -2633,6 +2657,7 @@ class API_Storage_Root(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Root, '/storage')
|
||||
|
||||
|
||||
# /storage/ceph
|
||||
class API_Storage_Ceph_Root(Resource):
|
||||
@Authenticator
|
||||
@ -2642,6 +2667,7 @@ class API_Storage_Ceph_Root(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Root, '/storage/ceph')
|
||||
|
||||
|
||||
# /storage/ceph/status
|
||||
class API_Storage_Ceph_Status(Resource):
|
||||
@Authenticator
|
||||
@ -2672,6 +2698,7 @@ class API_Storage_Ceph_Status(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Status, '/storage/ceph/status')
|
||||
|
||||
|
||||
# /storage/ceph/utilization
|
||||
class API_Storage_Ceph_Utilization(Resource):
|
||||
@Authenticator
|
||||
@ -2702,6 +2729,7 @@ class API_Storage_Ceph_Utilization(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Utilization, '/storage/ceph/utilization')
|
||||
|
||||
|
||||
# /storage/ceph/benchmark
|
||||
class API_Storage_Ceph_Benchmark(Resource):
|
||||
@RequestParser([
|
||||
@ -2862,6 +2890,7 @@ class API_Storage_Ceph_Benchmark(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Benchmark, '/storage/ceph/benchmark')
|
||||
|
||||
|
||||
# /storage/ceph/option
|
||||
class API_Storage_Ceph_Option(Resource):
|
||||
@RequestParser([
|
||||
@ -2910,6 +2939,7 @@ class API_Storage_Ceph_Option(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Option, '/storage/ceph/option')
|
||||
|
||||
|
||||
# /storage/ceph/osd
|
||||
class API_Storage_Ceph_OSD_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -3055,6 +3085,7 @@ class API_Storage_Ceph_OSD_Root(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_OSD_Root, '/storage/ceph/osd')
|
||||
|
||||
|
||||
# /storage/ceph/osd/<osdid>
|
||||
class API_Storage_Ceph_OSD_Element(Resource):
|
||||
@Authenticator
|
||||
@ -3116,6 +3147,7 @@ class API_Storage_Ceph_OSD_Element(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_OSD_Element, '/storage/ceph/osd/<osdid>')
|
||||
|
||||
|
||||
# /storage/ceph/osd/<osdid>/state
|
||||
class API_Storage_Ceph_OSD_State(Resource):
|
||||
@Authenticator
|
||||
@ -3175,6 +3207,7 @@ class API_Storage_Ceph_OSD_State(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_OSD_State, '/storage/ceph/osd/<osdid>/state')
|
||||
|
||||
|
||||
# /storage/ceph/pool
|
||||
class API_Storage_Ceph_Pool_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -3307,6 +3340,7 @@ class API_Storage_Ceph_Pool_Root(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Pool_Root, '/storage/ceph/pool')
|
||||
|
||||
|
||||
# /storage/ceph/pool/<pool>
|
||||
class API_Storage_Ceph_Pool_Element(Resource):
|
||||
@Authenticator
|
||||
@ -3418,6 +3452,7 @@ class API_Storage_Ceph_Pool_Element(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Pool_Element, '/storage/ceph/pool/<pool>')
|
||||
|
||||
|
||||
# /storage/ceph/volume
|
||||
class API_Storage_Ceph_Volume_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -3569,6 +3604,7 @@ class API_Storage_Ceph_Volume_Root(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Volume_Root, '/storage/ceph/volume')
|
||||
|
||||
|
||||
# /storage/ceph/volume/<pool>/<volume>
|
||||
class API_Storage_Ceph_Volume_Element(Resource):
|
||||
@Authenticator
|
||||
@ -3718,6 +3754,7 @@ class API_Storage_Ceph_Volume_Element(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Volume_Element, '/storage/ceph/volume/<pool>/<volume>')
|
||||
|
||||
|
||||
# /storage/ceph/volume/<pool>/<volume>/clone
|
||||
class API_Storage_Ceph_Volume_Element_Clone(Resource):
|
||||
@RequestParser([
|
||||
@ -3762,6 +3799,7 @@ class API_Storage_Ceph_Volume_Element_Clone(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Volume_Element_Clone, '/storage/ceph/volume/<pool>/<volume>/clone')
|
||||
|
||||
|
||||
# /storage/ceph/volume/<pool>/<volume>/upload
|
||||
class API_Storage_Ceph_Volume_Element_Upload(Resource):
|
||||
@RequestParser([
|
||||
@ -3815,6 +3853,7 @@ class API_Storage_Ceph_Volume_Element_Upload(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Volume_Element_Upload, '/storage/ceph/volume/<pool>/<volume>/upload')
|
||||
|
||||
|
||||
# /storage/ceph/snapshot
|
||||
class API_Storage_Ceph_Snapshot_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -3922,6 +3961,7 @@ class API_Storage_Ceph_Snapshot_Root(Resource):
|
||||
|
||||
api.add_resource(API_Storage_Ceph_Snapshot_Root, '/storage/ceph/snapshot')
|
||||
|
||||
|
||||
# /storage/ceph/snapshot/<pool>/<volume>/<snapshot>
|
||||
class API_Storage_Ceph_Snapshot_Element(Resource):
|
||||
@Authenticator
|
||||
@ -4081,6 +4121,7 @@ class API_Provisioner_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Root, '/provisioner')
|
||||
|
||||
|
||||
# /provisioner/template
|
||||
class API_Provisioner_Template_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -4129,6 +4170,7 @@ class API_Provisioner_Template_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Root, '/provisioner/template')
|
||||
|
||||
|
||||
# /provisioner/template/system
|
||||
class API_Provisioner_Template_System_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -4320,6 +4362,7 @@ class API_Provisioner_Template_System_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_System_Root, '/provisioner/template/system')
|
||||
|
||||
|
||||
# /provisioner/template/system/<template>
|
||||
class API_Provisioner_Template_System_Element(Resource):
|
||||
@Authenticator
|
||||
@ -4565,6 +4608,7 @@ class API_Provisioner_Template_System_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_System_Element, '/provisioner/template/system/<template>')
|
||||
|
||||
|
||||
# /provisioner/template/network
|
||||
class API_Provisioner_Template_Network_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -4668,6 +4712,7 @@ class API_Provisioner_Template_Network_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Network_Root, '/provisioner/template/network')
|
||||
|
||||
|
||||
# /provisioner/template/network/<template>
|
||||
class API_Provisioner_Template_Network_Element(Resource):
|
||||
@Authenticator
|
||||
@ -4752,6 +4797,7 @@ class API_Provisioner_Template_Network_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Network_Element, '/provisioner/template/network/<template>')
|
||||
|
||||
|
||||
# /provisioner/template/network/<template>/net
|
||||
class API_Provisioner_Template_Network_Net_Root(Resource):
|
||||
@Authenticator
|
||||
@ -4819,6 +4865,7 @@ class API_Provisioner_Template_Network_Net_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Network_Net_Root, '/provisioner/template/network/<template>/net')
|
||||
|
||||
|
||||
# /provisioner/template/network/<template>/net/<vni>
|
||||
class API_Provisioner_Template_Network_Net_Element(Resource):
|
||||
@Authenticator
|
||||
@ -4899,6 +4946,7 @@ class API_Provisioner_Template_Network_Net_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Network_Net_Element, '/provisioner/template/network/<template>/net/<vni>')
|
||||
|
||||
|
||||
# /provisioner/template/storage
|
||||
class API_Provisioner_Template_Storage_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -5009,6 +5057,7 @@ class API_Provisioner_Template_Storage_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Storage_Root, '/provisioner/template/storage')
|
||||
|
||||
|
||||
# /provisioner/template/storage/<template>
|
||||
class API_Provisioner_Template_Storage_Element(Resource):
|
||||
@Authenticator
|
||||
@ -5083,6 +5132,7 @@ class API_Provisioner_Template_Storage_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Storage_Element, '/provisioner/template/storage/<template>')
|
||||
|
||||
|
||||
# /provisioner/template/storage/<template>/disk
|
||||
class API_Provisioner_Template_Storage_Disk_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -5195,6 +5245,7 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Storage_Disk_Root, '/provisioner/template/storage/<template>/disk')
|
||||
|
||||
|
||||
# /provisioner/template/storage/<template>/disk/<disk_id>
|
||||
class API_Provisioner_Template_Storage_Disk_Element(Resource):
|
||||
@Authenticator
|
||||
@ -5321,6 +5372,7 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Template_Storage_Disk_Element, '/provisioner/template/storage/<template>/disk/<disk_id>')
|
||||
|
||||
|
||||
# /provisioner/userdata
|
||||
class API_Provisioner_Userdata_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -5407,6 +5459,7 @@ class API_Provisioner_Userdata_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Userdata_Root, '/provisioner/userdata')
|
||||
|
||||
|
||||
# /provisioner/userdata/<userdata>
|
||||
class API_Provisioner_Userdata_Element(Resource):
|
||||
@Authenticator
|
||||
@ -5524,6 +5577,7 @@ class API_Provisioner_Userdata_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Userdata_Element, '/provisioner/userdata/<userdata>')
|
||||
|
||||
|
||||
# /provisioner/script
|
||||
class API_Provisioner_Script_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -5610,6 +5664,7 @@ class API_Provisioner_Script_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Script_Root, '/provisioner/script')
|
||||
|
||||
|
||||
# /provisioner/script/<script>
|
||||
class API_Provisioner_Script_Element(Resource):
|
||||
@Authenticator
|
||||
@ -5727,6 +5782,7 @@ class API_Provisioner_Script_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Script_Element, '/provisioner/script/<script>')
|
||||
|
||||
|
||||
# /provisioner/profile
|
||||
class API_Provisioner_OVA_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -5840,6 +5896,7 @@ class API_Provisioner_OVA_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_OVA_Root, '/provisioner/ova')
|
||||
|
||||
|
||||
# /provisioner/ova/<ova>
|
||||
class API_Provisioner_OVA_Element(Resource):
|
||||
@Authenticator
|
||||
@ -5933,6 +5990,7 @@ class API_Provisioner_OVA_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_OVA_Element, '/provisioner/ova/<ova>')
|
||||
|
||||
|
||||
# /provisioner/profile
|
||||
class API_Provisioner_Profile_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -6087,6 +6145,7 @@ class API_Provisioner_Profile_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Profile_Root, '/provisioner/profile')
|
||||
|
||||
|
||||
# /provisioner/profile/<profile>
|
||||
class API_Provisioner_Profile_Element(Resource):
|
||||
@Authenticator
|
||||
@ -6291,6 +6350,7 @@ class API_Provisioner_Profile_Element(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Profile_Element, '/provisioner/profile/<profile>')
|
||||
|
||||
|
||||
# /provisioner/create
|
||||
class API_Provisioner_Create_Root(Resource):
|
||||
@RequestParser([
|
||||
@ -6375,6 +6435,7 @@ class API_Provisioner_Create_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Create_Root, '/provisioner/create')
|
||||
|
||||
|
||||
# /provisioner/status
|
||||
class API_Provisioner_Status_Root(Resource):
|
||||
@Authenticator
|
||||
@ -6411,6 +6472,7 @@ class API_Provisioner_Status_Root(Resource):
|
||||
|
||||
api.add_resource(API_Provisioner_Status_Root, '/provisioner/status')
|
||||
|
||||
|
||||
# /provisioner/status/<task_id>
|
||||
class API_Provisioner_Status_Element(Resource):
|
||||
@Authenticator
|
||||
|
@ -36,6 +36,7 @@ import daemon_lib.ceph as pvc_ceph
|
||||
|
||||
config = None # Set in this namespace by flaskapi
|
||||
|
||||
|
||||
def strtobool(stringv):
|
||||
if stringv is None:
|
||||
return False
|
||||
@ -46,6 +47,7 @@ def strtobool(stringv):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Initialization function
|
||||
#
|
||||
@ -83,6 +85,7 @@ def initialize_cluster():
|
||||
|
||||
return True
|
||||
|
||||
|
||||
#
|
||||
# Cluster functions
|
||||
#
|
||||
@ -96,6 +99,7 @@ def cluster_status():
|
||||
|
||||
return retdata, 200
|
||||
|
||||
|
||||
def cluster_maintenance(maint_state='false'):
|
||||
"""
|
||||
Set the cluster in or out of maintenance state
|
||||
@ -114,6 +118,7 @@ def cluster_maintenance(maint_state='false'):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
#
|
||||
# Node functions
|
||||
#
|
||||
@ -145,6 +150,7 @@ def node_list(limit=None, daemon_state=None, coordinator_state=None, domain_stat
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def node_daemon_state(node):
|
||||
"""
|
||||
Return the daemon state of node NODE.
|
||||
@ -173,6 +179,7 @@ def node_daemon_state(node):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def node_coordinator_state(node):
|
||||
"""
|
||||
Return the coordinator state of node NODE.
|
||||
@ -201,6 +208,7 @@ def node_coordinator_state(node):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def node_domain_state(node):
|
||||
"""
|
||||
Return the domain state of node NODE.
|
||||
@ -226,6 +234,7 @@ def node_domain_state(node):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def node_secondary(node):
|
||||
"""
|
||||
Take NODE out of primary router mode.
|
||||
@ -244,6 +253,7 @@ def node_secondary(node):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def node_primary(node):
|
||||
"""
|
||||
Set NODE to primary router mode.
|
||||
@ -262,6 +272,7 @@ def node_primary(node):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def node_flush(node, wait):
|
||||
"""
|
||||
Flush NODE of running VMs.
|
||||
@ -280,6 +291,7 @@ def node_flush(node, wait):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def node_ready(node, wait):
|
||||
"""
|
||||
Restore NODE to active service.
|
||||
@ -298,6 +310,7 @@ def node_ready(node, wait):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
#
|
||||
# VM functions
|
||||
#
|
||||
@ -311,6 +324,7 @@ def vm_is_migrated(vm):
|
||||
|
||||
return retdata
|
||||
|
||||
|
||||
def vm_state(vm):
|
||||
"""
|
||||
Return the state of virtual machine VM.
|
||||
@ -343,6 +357,7 @@ def vm_state(vm):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def vm_node(vm):
|
||||
"""
|
||||
Return the current node of virtual machine VM.
|
||||
@ -376,6 +391,7 @@ def vm_node(vm):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def vm_console(vm, lines=None):
|
||||
"""
|
||||
Return the current console log for VM.
|
||||
@ -404,6 +420,7 @@ def vm_console(vm, lines=None):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def vm_list(node=None, state=None, limit=None, is_fuzzy=True):
|
||||
"""
|
||||
Return a list of VMs with limit LIMIT.
|
||||
@ -432,6 +449,7 @@ def vm_list(node=None, state=None, limit=None, is_fuzzy=True):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def vm_define(xml, node, limit, selector, autostart, migration_method):
|
||||
"""
|
||||
Define a VM from Libvirt XML in the PVC cluster.
|
||||
@ -457,6 +475,7 @@ def vm_define(xml, node, limit, selector, autostart, migration_method):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def get_vm_meta(vm):
|
||||
"""
|
||||
Get metadata of a VM.
|
||||
@ -492,6 +511,7 @@ def get_vm_meta(vm):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def update_vm_meta(vm, limit, selector, autostart, provisioner_profile, migration_method):
|
||||
"""
|
||||
Update metadata of a VM.
|
||||
@ -515,6 +535,7 @@ def update_vm_meta(vm, limit, selector, autostart, provisioner_profile, migratio
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_modify(name, restart, xml):
|
||||
"""
|
||||
Modify a VM Libvirt XML in the PVC cluster.
|
||||
@ -539,6 +560,7 @@ def vm_modify(name, restart, xml):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_undefine(name):
|
||||
"""
|
||||
Undefine a VM from the PVC cluster.
|
||||
@ -557,6 +579,7 @@ def vm_undefine(name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_remove(name):
|
||||
"""
|
||||
Remove a VM from the PVC cluster.
|
||||
@ -575,6 +598,7 @@ def vm_remove(name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_start(name):
|
||||
"""
|
||||
Start a VM in the PVC cluster.
|
||||
@ -593,6 +617,7 @@ def vm_start(name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_restart(name, wait):
|
||||
"""
|
||||
Restart a VM in the PVC cluster.
|
||||
@ -611,6 +636,7 @@ def vm_restart(name, wait):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_shutdown(name, wait):
|
||||
"""
|
||||
Shutdown a VM in the PVC cluster.
|
||||
@ -629,6 +655,7 @@ def vm_shutdown(name, wait):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_stop(name):
|
||||
"""
|
||||
Forcibly stop a VM in the PVC cluster.
|
||||
@ -647,6 +674,7 @@ def vm_stop(name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_disable(name):
|
||||
"""
|
||||
Disable a (stopped) VM in the PVC cluster.
|
||||
@ -665,6 +693,7 @@ def vm_disable(name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_move(name, node, wait, force_live):
|
||||
"""
|
||||
Move a VM to another node.
|
||||
@ -683,6 +712,7 @@ def vm_move(name, node, wait, force_live):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_migrate(name, node, flag_force, wait, force_live):
|
||||
"""
|
||||
Temporarily migrate a VM to another node.
|
||||
@ -701,6 +731,7 @@ def vm_migrate(name, node, flag_force, wait, force_live):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_unmigrate(name, wait, force_live):
|
||||
"""
|
||||
Unmigrate a migrated VM.
|
||||
@ -719,6 +750,7 @@ def vm_unmigrate(name, wait, force_live):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def vm_flush_locks(vm):
|
||||
"""
|
||||
Flush locks of a (stopped) VM.
|
||||
@ -748,6 +780,7 @@ def vm_flush_locks(vm):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
#
|
||||
# Network functions
|
||||
#
|
||||
@ -779,6 +812,7 @@ def net_list(limit=None, is_fuzzy=True):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def net_add(vni, description, nettype, domain, name_servers,
|
||||
ip4_network, ip4_gateway, ip6_network, ip6_gateway,
|
||||
dhcp4_flag, dhcp4_start, dhcp4_end):
|
||||
@ -803,6 +837,7 @@ def net_add(vni, description, nettype, domain, name_servers,
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def net_modify(vni, description, domain, name_servers,
|
||||
ip4_network, ip4_gateway,
|
||||
ip6_network, ip6_gateway,
|
||||
@ -828,6 +863,7 @@ def net_modify(vni, description, domain, name_servers,
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def net_remove(network):
|
||||
"""
|
||||
Remove a virtual client network from the PVC cluster.
|
||||
@ -846,6 +882,7 @@ def net_remove(network):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def net_dhcp_list(network, limit=None, static=False):
|
||||
"""
|
||||
Return a list of DHCP leases in network NETWORK with limit LIMIT.
|
||||
@ -870,6 +907,7 @@ def net_dhcp_list(network, limit=None, static=False):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def net_dhcp_add(network, ipaddress, macaddress, hostname):
|
||||
"""
|
||||
Add a static DHCP lease to a virtual client network.
|
||||
@ -888,6 +926,7 @@ def net_dhcp_add(network, ipaddress, macaddress, hostname):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def net_dhcp_remove(network, macaddress):
|
||||
"""
|
||||
Remove a static DHCP lease from a virtual client network.
|
||||
@ -906,6 +945,7 @@ def net_dhcp_remove(network, macaddress):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def net_acl_list(network, limit=None, direction=None, is_fuzzy=True):
|
||||
"""
|
||||
Return a list of network ACLs in network NETWORK with limit LIMIT.
|
||||
@ -934,6 +974,7 @@ def net_acl_list(network, limit=None, direction=None, is_fuzzy=True):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def net_acl_add(network, direction, description, rule, order):
|
||||
"""
|
||||
Add an ACL to a virtual client network.
|
||||
@ -952,6 +993,7 @@ def net_acl_add(network, direction, description, rule, order):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def net_acl_remove(network, description):
|
||||
"""
|
||||
Remove an ACL from a virtual client network.
|
||||
@ -970,6 +1012,7 @@ def net_acl_remove(network, description):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
#
|
||||
# Ceph functions
|
||||
#
|
||||
@ -988,6 +1031,7 @@ def ceph_status():
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def ceph_util():
|
||||
"""
|
||||
Get the current Ceph cluster utilization.
|
||||
@ -1003,6 +1047,7 @@ def ceph_util():
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def ceph_osd_list(limit=None):
|
||||
"""
|
||||
Get the list of OSDs in the Ceph storage cluster.
|
||||
@ -1027,6 +1072,7 @@ def ceph_osd_list(limit=None):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def ceph_osd_state(osd):
|
||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
||||
retflag, retdata = pvc_ceph.get_list_osd(zk_conn, osd)
|
||||
@ -1051,6 +1097,7 @@ def ceph_osd_state(osd):
|
||||
|
||||
return {"id": osd, "in": in_state, "up": up_state}, retcode
|
||||
|
||||
|
||||
def ceph_osd_add(node, device, weight):
|
||||
"""
|
||||
Add a Ceph OSD to the PVC Ceph storage cluster.
|
||||
@ -1069,6 +1116,7 @@ def ceph_osd_add(node, device, weight):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_osd_remove(osd_id):
|
||||
"""
|
||||
Remove a Ceph OSD from the PVC Ceph storage cluster.
|
||||
@ -1087,6 +1135,7 @@ def ceph_osd_remove(osd_id):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_osd_in(osd_id):
|
||||
"""
|
||||
Set in a Ceph OSD in the PVC Ceph storage cluster.
|
||||
@ -1105,6 +1154,7 @@ def ceph_osd_in(osd_id):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_osd_out(osd_id):
|
||||
"""
|
||||
Set out a Ceph OSD in the PVC Ceph storage cluster.
|
||||
@ -1123,6 +1173,7 @@ def ceph_osd_out(osd_id):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_osd_set(option):
|
||||
"""
|
||||
Set options on a Ceph OSD in the PVC Ceph storage cluster.
|
||||
@ -1141,6 +1192,7 @@ def ceph_osd_set(option):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_osd_unset(option):
|
||||
"""
|
||||
Unset options on a Ceph OSD in the PVC Ceph storage cluster.
|
||||
@ -1159,6 +1211,7 @@ def ceph_osd_unset(option):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_pool_list(limit=None, is_fuzzy=True):
|
||||
"""
|
||||
Get the list of RBD pools in the Ceph storage cluster.
|
||||
@ -1187,6 +1240,7 @@ def ceph_pool_list(limit=None, is_fuzzy=True):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def ceph_pool_add(name, pgs, replcfg):
|
||||
"""
|
||||
Add a Ceph RBD pool to the PVC Ceph storage cluster.
|
||||
@ -1205,6 +1259,7 @@ def ceph_pool_add(name, pgs, replcfg):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_pool_remove(name):
|
||||
"""
|
||||
Remove a Ceph RBD pool to the PVC Ceph storage cluster.
|
||||
@ -1223,6 +1278,7 @@ def ceph_pool_remove(name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_list(pool=None, limit=None, is_fuzzy=True):
|
||||
"""
|
||||
Get the list of RBD volumes in the Ceph storage cluster.
|
||||
@ -1251,6 +1307,7 @@ def ceph_volume_list(pool=None, limit=None, is_fuzzy=True):
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def ceph_volume_add(pool, name, size):
|
||||
"""
|
||||
Add a Ceph RBD volume to the PVC Ceph storage cluster.
|
||||
@ -1269,6 +1326,7 @@ def ceph_volume_add(pool, name, size):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_clone(pool, name, source_volume):
|
||||
"""
|
||||
Clone a Ceph RBD volume to a new volume on the PVC Ceph storage cluster.
|
||||
@ -1287,6 +1345,7 @@ def ceph_volume_clone(pool, name, source_volume):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_resize(pool, name, size):
|
||||
"""
|
||||
Resize an existing Ceph RBD volume in the PVC Ceph storage cluster.
|
||||
@ -1305,6 +1364,7 @@ def ceph_volume_resize(pool, name, size):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_rename(pool, name, new_name):
|
||||
"""
|
||||
Rename a Ceph RBD volume in the PVC Ceph storage cluster.
|
||||
@ -1323,6 +1383,7 @@ def ceph_volume_rename(pool, name, new_name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_remove(pool, name):
|
||||
"""
|
||||
Remove a Ceph RBD volume to the PVC Ceph storage cluster.
|
||||
@ -1341,6 +1402,7 @@ def ceph_volume_remove(pool, name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_upload(pool, volume, img_type):
|
||||
"""
|
||||
Upload a raw file via HTTP post to a PVC Ceph volume
|
||||
@ -1491,6 +1553,7 @@ def ceph_volume_upload(pool, volume, img_type):
|
||||
cleanup_maps_and_volumes()
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_snapshot_list(pool=None, volume=None, limit=None, is_fuzzy=True):
|
||||
"""
|
||||
Get the list of RBD volume snapshots in the Ceph storage cluster.
|
||||
@ -1519,6 +1582,7 @@ def ceph_volume_snapshot_list(pool=None, volume=None, limit=None, is_fuzzy=True)
|
||||
|
||||
return retdata, retcode
|
||||
|
||||
|
||||
def ceph_volume_snapshot_add(pool, volume, name):
|
||||
"""
|
||||
Add a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
||||
@ -1537,6 +1601,7 @@ def ceph_volume_snapshot_add(pool, volume, name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_snapshot_rename(pool, volume, name, new_name):
|
||||
"""
|
||||
Rename a Ceph RBD volume snapshot in the PVC Ceph storage cluster.
|
||||
@ -1555,6 +1620,7 @@ def ceph_volume_snapshot_rename(pool, volume, name, new_name):
|
||||
}
|
||||
return output, retcode
|
||||
|
||||
|
||||
def ceph_volume_snapshot_remove(pool, volume, name):
|
||||
"""
|
||||
Remove a Ceph RBD volume snapshot from the PVC Ceph storage cluster.
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
from pvcapid.flaskapi import db
|
||||
|
||||
|
||||
class DBSystemTemplate(db.Model):
|
||||
__tablename__ = 'system_template'
|
||||
|
||||
@ -54,6 +55,7 @@ class DBSystemTemplate(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBNetworkTemplate(db.Model):
|
||||
__tablename__ = 'network_template'
|
||||
|
||||
@ -70,6 +72,7 @@ class DBNetworkTemplate(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBNetworkElement(db.Model):
|
||||
__tablename__ = 'network'
|
||||
|
||||
@ -84,6 +87,7 @@ class DBNetworkElement(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBStorageTemplate(db.Model):
|
||||
__tablename__ = 'storage_template'
|
||||
|
||||
@ -98,6 +102,7 @@ class DBStorageTemplate(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBStorageElement(db.Model):
|
||||
__tablename__ = 'storage'
|
||||
|
||||
@ -124,6 +129,7 @@ class DBStorageElement(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBUserdata(db.Model):
|
||||
__tablename__ = 'userdata'
|
||||
|
||||
@ -138,6 +144,7 @@ class DBUserdata(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBScript(db.Model):
|
||||
__tablename__ = 'script'
|
||||
|
||||
@ -152,6 +159,7 @@ class DBScript(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBOva(db.Model):
|
||||
__tablename__ = 'ova'
|
||||
|
||||
@ -166,6 +174,7 @@ class DBOva(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBOvaVolume(db.Model):
|
||||
__tablename__ = 'ova_volume'
|
||||
|
||||
@ -188,6 +197,7 @@ class DBOvaVolume(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBProfile(db.Model):
|
||||
__tablename__ = 'profile'
|
||||
|
||||
@ -216,6 +226,7 @@ class DBProfile(db.Model):
|
||||
def __repr__(self):
|
||||
return '<id {}>'.format(self.id)
|
||||
|
||||
|
||||
class DBStorageBenchmarks(db.Model):
|
||||
__tablename__ = 'storage_benchmarks'
|
||||
|
||||
|
@ -38,6 +38,7 @@ import pvcapid.provisioner as provisioner
|
||||
|
||||
config = None # Set in this namespace by flaskapi
|
||||
|
||||
|
||||
#
|
||||
# Common functions
|
||||
#
|
||||
@ -54,12 +55,14 @@ def open_database(config):
|
||||
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||
return conn, cur
|
||||
|
||||
|
||||
def close_database(conn, cur, failed=False):
|
||||
if not failed:
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
#
|
||||
# OVA functions
|
||||
#
|
||||
@ -107,6 +110,7 @@ def list_ova(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No OVAs found.'}, 404
|
||||
|
||||
|
||||
def delete_ova(name):
|
||||
ova_data, retcode = list_ova(name, is_fuzzy=False)
|
||||
if retcode != 200:
|
||||
@ -156,6 +160,7 @@ def delete_ova(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def upload_ova(pool, name, ova_size):
|
||||
ova_archive = None
|
||||
|
||||
@ -407,6 +412,7 @@ def upload_ova(pool, name, ova_size):
|
||||
retcode = 200
|
||||
return output, retcode
|
||||
|
||||
|
||||
#
|
||||
# OVF parser
|
||||
#
|
||||
|
@ -39,6 +39,7 @@ from pvcapid.ova import list_ova
|
||||
|
||||
config = None # Set in this namespace by flaskapi
|
||||
|
||||
|
||||
def strtobool(stringv):
|
||||
if stringv is None:
|
||||
return False
|
||||
@ -49,6 +50,7 @@ def strtobool(stringv):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
#
|
||||
# Exceptions (used by Celery tasks)
|
||||
#
|
||||
@ -58,18 +60,21 @@ class ValidationError(Exception):
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ClusterError(Exception):
|
||||
"""
|
||||
An exception that results from the PVC cluster being out of alignment with the action.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ProvisioningError(Exception):
|
||||
"""
|
||||
An exception that results from a failure of a provisioning command.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
#
|
||||
# Common functions
|
||||
#
|
||||
@ -86,12 +91,14 @@ def open_database(config):
|
||||
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||
return conn, cur
|
||||
|
||||
|
||||
def close_database(conn, cur, failed=False):
|
||||
if not failed:
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
#
|
||||
# Template List functions
|
||||
#
|
||||
@ -143,6 +150,7 @@ def list_template(limit, table, is_fuzzy=True):
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def list_template_system(limit, is_fuzzy=True):
|
||||
"""
|
||||
Obtain a list of system templates.
|
||||
@ -153,6 +161,7 @@ def list_template_system(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No system templates found.'}, 404
|
||||
|
||||
|
||||
def list_template_network(limit, is_fuzzy=True):
|
||||
"""
|
||||
Obtain a list of network templates.
|
||||
@ -163,6 +172,7 @@ def list_template_network(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No network templates found.'}, 404
|
||||
|
||||
|
||||
def list_template_network_vnis(name):
|
||||
"""
|
||||
Obtain a list of network template VNIs.
|
||||
@ -174,6 +184,7 @@ def list_template_network_vnis(name):
|
||||
else:
|
||||
return {'message': 'No network template networks found.'}, 404
|
||||
|
||||
|
||||
def list_template_storage(limit, is_fuzzy=True):
|
||||
"""
|
||||
Obtain a list of storage templates.
|
||||
@ -184,6 +195,7 @@ def list_template_storage(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No storage templates found.'}, 404
|
||||
|
||||
|
||||
def list_template_storage_disks(name):
|
||||
"""
|
||||
Obtain a list of storage template disks.
|
||||
@ -195,6 +207,7 @@ def list_template_storage_disks(name):
|
||||
else:
|
||||
return {'message': 'No storage template disks found.'}, 404
|
||||
|
||||
|
||||
def template_list(limit):
|
||||
system_templates, code = list_template_system(limit)
|
||||
if code != 200:
|
||||
@ -208,6 +221,7 @@ def template_list(limit):
|
||||
|
||||
return {"system_templates": system_templates, "network_templates": network_templates, "storage_templates": storage_templates}
|
||||
|
||||
|
||||
#
|
||||
# Template Create functions
|
||||
#
|
||||
@ -231,6 +245,7 @@ def create_template_system(name, vcpu_count, vram_mb, serial=False, vnc=False, v
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def create_template_network(name, mac_template=None):
|
||||
if list_template_network(name, is_fuzzy=False)[-1] != 404:
|
||||
retmsg = {'message': 'The network template "{}" already exists.'.format(name)}
|
||||
@ -250,6 +265,7 @@ def create_template_network(name, mac_template=None):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def create_template_network_element(name, vni):
|
||||
if list_template_network(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The network template "{}" does not exist.'.format(name)}
|
||||
@ -285,6 +301,7 @@ def create_template_network_element(name, vni):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def create_template_storage(name):
|
||||
if list_template_storage(name, is_fuzzy=False)[-1] != 404:
|
||||
retmsg = {'message': 'The storage template "{}" already exists.'.format(name)}
|
||||
@ -304,6 +321,7 @@ def create_template_storage(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def create_template_storage_element(name, disk_id, pool, source_volume=None, disk_size_gb=None, filesystem=None, filesystem_args=[], mountpoint=None):
|
||||
if list_template_storage(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name)}
|
||||
@ -353,6 +371,7 @@ def create_template_storage_element(name, disk_id, pool, source_volume=None, dis
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
#
|
||||
# Template Modify functions
|
||||
#
|
||||
@ -434,6 +453,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
#
|
||||
# Template Delete functions
|
||||
#
|
||||
@ -456,6 +476,7 @@ def delete_template_system(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_template_network(name):
|
||||
if list_template_network(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The network template "{}" does not exist.'.format(name)}
|
||||
@ -482,6 +503,7 @@ def delete_template_network(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_template_network_element(name, vni):
|
||||
if list_template_network(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The network template "{}" does not exist.'.format(name)}
|
||||
@ -515,6 +537,7 @@ def delete_template_network_element(name, vni):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_template_storage(name):
|
||||
if list_template_storage(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name)}
|
||||
@ -541,6 +564,7 @@ def delete_template_storage(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_template_storage_element(name, disk_id):
|
||||
if list_template_storage(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The storage template "{}" does not exist.'.format(name)}
|
||||
@ -574,6 +598,7 @@ def delete_template_storage_element(name, disk_id):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
#
|
||||
# Userdata functions
|
||||
#
|
||||
@ -605,6 +630,7 @@ def list_userdata(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No userdata documents found.'}, 404
|
||||
|
||||
|
||||
def create_userdata(name, userdata):
|
||||
if list_userdata(name, is_fuzzy=False)[-1] != 404:
|
||||
retmsg = {'message': 'The userdata document "{}" already exists.'.format(name)}
|
||||
@ -624,6 +650,7 @@ def create_userdata(name, userdata):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def update_userdata(name, userdata):
|
||||
if list_userdata(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The userdata "{}" does not exist.'.format(name)}
|
||||
@ -646,6 +673,7 @@ def update_userdata(name, userdata):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_userdata(name):
|
||||
if list_userdata(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The userdata "{}" does not exist.'.format(name)}
|
||||
@ -665,6 +693,7 @@ def delete_userdata(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
#
|
||||
# Script functions
|
||||
#
|
||||
@ -696,6 +725,7 @@ def list_script(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No scripts found.'}, 404
|
||||
|
||||
|
||||
def create_script(name, script):
|
||||
if list_script(name, is_fuzzy=False)[-1] != 404:
|
||||
retmsg = {'message': 'The script "{}" already exists.'.format(name)}
|
||||
@ -715,6 +745,7 @@ def create_script(name, script):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def update_script(name, script):
|
||||
if list_script(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The script "{}" does not exist.'.format(name)}
|
||||
@ -737,6 +768,7 @@ def update_script(name, script):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_script(name):
|
||||
if list_script(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The script "{}" does not exist.'.format(name)}
|
||||
@ -756,6 +788,7 @@ def delete_script(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
#
|
||||
# Profile functions
|
||||
#
|
||||
@ -807,6 +840,7 @@ def list_profile(limit, is_fuzzy=True):
|
||||
else:
|
||||
return {'message': 'No profiles found.'}, 404
|
||||
|
||||
|
||||
def create_profile(name, profile_type, system_template, network_template, storage_template, userdata=None, script=None, ova=None, arguments=None):
|
||||
if list_profile(name, is_fuzzy=False)[-1] != 404:
|
||||
retmsg = {'message': 'The profile "{}" already exists.'.format(name)}
|
||||
@ -896,6 +930,7 @@ def create_profile(name, profile_type, system_template, network_template, storag
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def modify_profile(name, profile_type, system_template, network_template, storage_template, userdata, script, ova, arguments=None):
|
||||
if list_profile(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The profile "{}" does not exist.'.format(name)}
|
||||
@ -1004,6 +1039,7 @@ def modify_profile(name, profile_type, system_template, network_template, storag
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
def delete_profile(name):
|
||||
if list_profile(name, is_fuzzy=False)[-1] != 200:
|
||||
retmsg = {'message': 'The profile "{}" does not exist.'.format(name)}
|
||||
@ -1023,6 +1059,7 @@ def delete_profile(name):
|
||||
close_database(conn, cur)
|
||||
return retmsg, retcode
|
||||
|
||||
|
||||
#
|
||||
# Main VM provisioning function - executed by the Celery worker
|
||||
#
|
||||
|
Reference in New Issue
Block a user