Support source_volume options to storage volumes
This commit is contained in:
parent
2ed6949373
commit
e433181e34
|
@ -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
|
||||
|
|
|
@ -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', []),
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue