From e433181e34fbf4a8c893e88f10bebe6c6a10f5c4 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 5 Jan 2020 17:25:34 -0500 Subject: [PATCH] Support source_volume options to storage volumes --- client-api/api_lib/pvcapi_provisioner.py | 11 +++++--- client-api/pvc-api.py | 34 +++++++++++++++++------- docs/manuals/swagger.json | 30 +++++++++++++++------ 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/client-api/api_lib/pvcapi_provisioner.py b/client-api/api_lib/pvcapi_provisioner.py index 9f3705d9..76119452 100755 --- a/client-api/api_lib/pvcapi_provisioner.py +++ b/client-api/api_lib/pvcapi_provisioner.py @@ -282,7 +282,7 @@ def create_template_storage(name): close_database(conn, cur) return retmsg, retcode -def create_template_storage_element(name, disk_id, pool, disk_size_gb, filesystem=None, filesystem_args=[], mountpoint=None): +def create_template_storage_element(name, disk_id, pool, source_volume=None, disk_size_gb=None, filesystem=None, filesystem_args=[], mountpoint=None): if not list_template_storage(name, is_fuzzy=False): retmsg = { 'message': 'The storage template "{}" does not exist'.format(name) } retcode = 400 @@ -303,14 +303,19 @@ def create_template_storage_element(name, disk_id, pool, disk_size_gb, filesyste retcode = 400 return retmsg, retcode + if source_volume and (disk_size_gb or filesystem or mountpoint): + retmsg = { "message": "Clone volumes are not compatible with disk size, filesystem, or mountpoint specifications." } + retcode = 400 + return retmsg, retcode + conn, cur = open_database(config) try: query = "SELECT id FROM storage_template WHERE name = %s;" args = (name,) cur.execute(query, args) template_id = cur.fetchone()['id'] - query = "INSERT INTO storage (storage_template, pool, disk_id, disk_size_gb, mountpoint, filesystem, filesystem_args) VALUES (%s, %s, %s, %s, %s, %s, %s);" - args = (template_id, pool, disk_id, disk_size_gb, mountpoint, filesystem, ' '.join(filesystem_args)) + query = "INSERT INTO storage (storage_template, pool, disk_id, source_volume, disk_size_gb, mountpoint, filesystem, filesystem_args) VALUES (%s, %s, %s, %s, %s, %s, %s, %s);" + args = (template_id, pool, disk_id, source_volume, disk_size_gb, mountpoint, filesystem, ' '.join(filesystem_args)) cur.execute(query, args) retmsg = { 'message': 'Added new disk "{}" to storage template "{}"'.format(disk_id, name) } retcode = 200 diff --git a/client-api/pvc-api.py b/client-api/pvc-api.py index 1a306802..2cf1d50b 100755 --- a/client-api/pvc-api.py +++ b/client-api/pvc-api.py @@ -4359,7 +4359,8 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource): @RequestParser([ { 'name': 'disk_id', 'required': True, 'helpmsg': "A disk identifier in sdX or vdX format must be specified" }, { 'name': 'pool', 'required': True, 'helpmsg': "A storage pool must be specified" }, - { 'name': 'disk_size', 'required': True, 'helpmsg': "A disk size in GB must be specified" }, + { 'name': 'source_volume' }, + { 'name': 'disk_size' }, { 'name': 'filesystem' }, { 'name': 'filesystem_arg', 'action': 'append' }, { 'name': 'mountpoint' } @@ -4382,16 +4383,21 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource): 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: true - description: Disk size in GB + required: false + description: Disk size in GB; not compatible with source_volume - in: query name: filesystem type: string required: false - description: Filesystem for disk + description: Filesystem for disk; not compatible with source_volume - in: query name: filesystem_arg type: string @@ -4401,7 +4407,7 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource): name: mountpoint type: string required: false - description: In-VM mountpoint for disk + description: In-VM mountpoint for disk; not compatible with source_volume responses: 200: description: OK @@ -4418,6 +4424,7 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource): template, 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', []), @@ -4456,7 +4463,8 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource): @RequestParser([ { 'name': 'pool', 'required': True, 'helpmsg': "A storage pool must be specified" }, - { 'name': 'disk_size', 'required': True, 'helpmsg': "A disk size in GB must be specified" }, + { 'name': 'source_volume' }, + { 'name': 'disk_size' }, { 'name': 'filesystem' }, { 'name': 'filesystem_arg', 'action': 'append' }, { 'name': 'mountpoint' } @@ -4475,16 +4483,21 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource): 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: true - description: Disk size in GB + required: false + description: Disk size in GB; not compatible with source_volume - in: query name: filesystem type: string required: false - description: Filesystem for disk + description: Filesystem for disk; not compatible with source_volume - in: query name: filesystem_arg type: string @@ -4494,7 +4507,7 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource): name: mountpoint type: string required: false - description: In-VM mountpoint for disk + description: In-VM mountpoint for disk; not compatible with source_volume responses: 200: description: OK @@ -4511,6 +4524,7 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource): template, disk_id, reqargs.get('pool', None), + reqargs.get('source_volume', None), reqargs.get('disk_size', None), reqargs.get('filesystem', None), reqargs.get('filesystem_arg', []), diff --git a/docs/manuals/swagger.json b/docs/manuals/swagger.json index 1610bc56..5f695bc4 100644 --- a/docs/manuals/swagger.json +++ b/docs/manuals/swagger.json @@ -2963,14 +2963,21 @@ "type": "string" }, { - "description": "Disk size in GB", + "description": "Source storage volume; not compatible with other options", + "in": "query", + "name": "source_volume", + "required": false, + "type": "string" + }, + { + "description": "Disk size in GB; not compatible with source_volume", "in": "query", "name": "disk_size", - "required": true, + "required": false, "type": "integer" }, { - "description": "Filesystem for disk", + "description": "Filesystem for disk; not compatible with source_volume", "in": "query", "name": "filesystem", "required": false, @@ -2984,7 +2991,7 @@ "type": "string" }, { - "description": "In-VM mountpoint for disk", + "description": "In-VM mountpoint for disk; not compatible with source_volume", "in": "query", "name": "mountpoint", "required": false, @@ -3065,14 +3072,21 @@ "type": "string" }, { - "description": "Disk size in GB", + "description": "Source storage volume; not compatible with other options", + "in": "query", + "name": "source_volume", + "required": false, + "type": "string" + }, + { + "description": "Disk size in GB; not compatible with source_volume", "in": "query", "name": "disk_size", - "required": true, + "required": false, "type": "integer" }, { - "description": "Filesystem for disk", + "description": "Filesystem for disk; not compatible with source_volume", "in": "query", "name": "filesystem", "required": false, @@ -3086,7 +3100,7 @@ "type": "string" }, { - "description": "In-VM mountpoint for disk", + "description": "In-VM mountpoint for disk; not compatible with source_volume", "in": "query", "name": "mountpoint", "required": false,