Support source_volume options to storage volumes

This commit is contained in:
Joshua Boniface 2020-01-05 17:25:34 -05:00
parent 2ed6949373
commit e433181e34
3 changed files with 54 additions and 21 deletions

View File

@ -282,7 +282,7 @@ def create_template_storage(name):
close_database(conn, cur) close_database(conn, cur)
return retmsg, retcode 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): if not list_template_storage(name, is_fuzzy=False):
retmsg = { 'message': 'The storage template "{}" does not exist'.format(name) } retmsg = { 'message': 'The storage template "{}" does not exist'.format(name) }
retcode = 400 retcode = 400
@ -303,14 +303,19 @@ def create_template_storage_element(name, disk_id, pool, disk_size_gb, filesyste
retcode = 400 retcode = 400
return retmsg, retcode 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) conn, cur = open_database(config)
try: try:
query = "SELECT id FROM storage_template WHERE name = %s;" query = "SELECT id FROM storage_template WHERE name = %s;"
args = (name,) args = (name,)
cur.execute(query, args) cur.execute(query, args)
template_id = cur.fetchone()['id'] 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);" 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, disk_size_gb, mountpoint, filesystem, ' '.join(filesystem_args)) args = (template_id, pool, disk_id, source_volume, disk_size_gb, mountpoint, filesystem, ' '.join(filesystem_args))
cur.execute(query, args) cur.execute(query, args)
retmsg = { 'message': 'Added new disk "{}" to storage template "{}"'.format(disk_id, name) } retmsg = { 'message': 'Added new disk "{}" to storage template "{}"'.format(disk_id, name) }
retcode = 200 retcode = 200

View File

@ -4359,7 +4359,8 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource):
@RequestParser([ @RequestParser([
{ 'name': 'disk_id', 'required': True, 'helpmsg': "A disk identifier in sdX or vdX format must be specified" }, { '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': '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' },
{ 'name': 'filesystem_arg', 'action': 'append' }, { 'name': 'filesystem_arg', 'action': 'append' },
{ 'name': 'mountpoint' } { 'name': 'mountpoint' }
@ -4382,16 +4383,21 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource):
type: string type: string
required: true required: true
description: ceph storage pool for disk 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 - in: query
name: disk_size name: disk_size
type: integer type: integer
required: true required: false
description: Disk size in GB description: Disk size in GB; not compatible with source_volume
- in: query - in: query
name: filesystem name: filesystem
type: string type: string
required: false required: false
description: Filesystem for disk description: Filesystem for disk; not compatible with source_volume
- in: query - in: query
name: filesystem_arg name: filesystem_arg
type: string type: string
@ -4401,7 +4407,7 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource):
name: mountpoint name: mountpoint
type: string type: string
required: false required: false
description: In-VM mountpoint for disk description: In-VM mountpoint for disk; not compatible with source_volume
responses: responses:
200: 200:
description: OK description: OK
@ -4418,6 +4424,7 @@ class API_Provisioner_Template_Storage_Disk_Root(Resource):
template, template,
reqargs.get('disk_id', None), reqargs.get('disk_id', None),
reqargs.get('pool', None), reqargs.get('pool', None),
reqargs.get('source_volume', None),
reqargs.get('disk_size', None), reqargs.get('disk_size', None),
reqargs.get('filesystem', None), reqargs.get('filesystem', None),
reqargs.get('filesystem_arg', []), reqargs.get('filesystem_arg', []),
@ -4456,7 +4463,8 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource):
@RequestParser([ @RequestParser([
{ 'name': 'pool', 'required': True, 'helpmsg': "A storage pool 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' },
{ 'name': 'filesystem_arg', 'action': 'append' }, { 'name': 'filesystem_arg', 'action': 'append' },
{ 'name': 'mountpoint' } { 'name': 'mountpoint' }
@ -4475,16 +4483,21 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource):
type: string type: string
required: true required: true
description: ceph storage pool for disk 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 - in: query
name: disk_size name: disk_size
type: integer type: integer
required: true required: false
description: Disk size in GB description: Disk size in GB; not compatible with source_volume
- in: query - in: query
name: filesystem name: filesystem
type: string type: string
required: false required: false
description: Filesystem for disk description: Filesystem for disk; not compatible with source_volume
- in: query - in: query
name: filesystem_arg name: filesystem_arg
type: string type: string
@ -4494,7 +4507,7 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource):
name: mountpoint name: mountpoint
type: string type: string
required: false required: false
description: In-VM mountpoint for disk description: In-VM mountpoint for disk; not compatible with source_volume
responses: responses:
200: 200:
description: OK description: OK
@ -4511,6 +4524,7 @@ class API_Provisioner_Template_Storage_Disk_Element(Resource):
template, template,
disk_id, disk_id,
reqargs.get('pool', None), reqargs.get('pool', None),
reqargs.get('source_volume', None),
reqargs.get('disk_size', None), reqargs.get('disk_size', None),
reqargs.get('filesystem', None), reqargs.get('filesystem', None),
reqargs.get('filesystem_arg', []), reqargs.get('filesystem_arg', []),

View File

@ -2963,14 +2963,21 @@
"type": "string" "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", "in": "query",
"name": "disk_size", "name": "disk_size",
"required": true, "required": false,
"type": "integer" "type": "integer"
}, },
{ {
"description": "Filesystem for disk", "description": "Filesystem for disk; not compatible with source_volume",
"in": "query", "in": "query",
"name": "filesystem", "name": "filesystem",
"required": false, "required": false,
@ -2984,7 +2991,7 @@
"type": "string" "type": "string"
}, },
{ {
"description": "In-VM mountpoint for disk", "description": "In-VM mountpoint for disk; not compatible with source_volume",
"in": "query", "in": "query",
"name": "mountpoint", "name": "mountpoint",
"required": false, "required": false,
@ -3065,14 +3072,21 @@
"type": "string" "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", "in": "query",
"name": "disk_size", "name": "disk_size",
"required": true, "required": false,
"type": "integer" "type": "integer"
}, },
{ {
"description": "Filesystem for disk", "description": "Filesystem for disk; not compatible with source_volume",
"in": "query", "in": "query",
"name": "filesystem", "name": "filesystem",
"required": false, "required": false,
@ -3086,7 +3100,7 @@
"type": "string" "type": "string"
}, },
{ {
"description": "In-VM mountpoint for disk", "description": "In-VM mountpoint for disk; not compatible with source_volume",
"in": "query", "in": "query",
"name": "mountpoint", "name": "mountpoint",
"required": false, "required": false,