Add a new filesystem for image conversion

Create the new host_fs CLI commands and the APIs
    system host-fs-add
    system host-fs-delete

These commands will be used only for adding/removing 'image-conversion'
filesystem dedicated only for qcow2 image conversion.
'image-conversion' filesystem is optional.
It is not allowed to add/remove any other filesystem.

Change-Id: I87c876371e123ec1ba946170258401d220260e31
Partial-bug: 1819688
Depends-On: https://review.opendev.org/#/c/714936/
Signed-off-by: Elena Taivan <stefan.dinescu@windriver.com>
This commit is contained in:
Elena Taivan
2020-03-25 12:33:42 +00:00
parent d10ddf1369
commit 8099bbbbcf
7 changed files with 246 additions and 8 deletions

View File

@@ -9,6 +9,8 @@
from cgtsclient.common import base
from cgtsclient import exc
CREATION_ATTRIBUTES = ['name', 'ihost_uuid', 'size']
class HostFs(base.Resource):
def __repr__(self):
@@ -41,6 +43,21 @@ class HostFsManager(base.Manager):
if body:
return self.resource_class(self, body)
def delete(self, fs_id):
path = '/v1/host_fs/%s' % fs_id
return self._delete(path)
def create(self, **kwargs):
path = '/v1/host_fs'
valid_list = []
new = {}
for (key, value) in kwargs.items():
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exc.InvalidAttribute('%s' % key)
return self._create(path, new)
def _find_fs(cc, ihost, host_fs):
if host_fs.isdigit():

View File

@@ -96,3 +96,56 @@ def do_host_fs_modify(cc, args):
raise exc.CommandError('Failed to modify filesystems')
_print_fs_list(cc, ihost.uuid)
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of the host [REQUIRED]")
@utils.arg('name',
metavar='<fs name>',
help="Name of the Filesystem [REQUIRED]")
def do_host_fs_delete(cc, args):
"""Delete a host filesystem."""
# Get the ihost object
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
host_fs = fs_utils._find_fs(cc, ihost, args.name)
try:
cc.host_fs.delete(host_fs.uuid)
except exc.HTTPNotFound:
raise exc.CommandError('Filesystem delete failed: host %s: '
'name %s' % (args.hostnameorid,
args.name))
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of the host [REQUIRED]")
@utils.arg('name',
metavar='<fs name=size>',
nargs=1,
action='append',
help="Name of the Filesystem [REQUIRED]")
def do_host_fs_add(cc, args):
"""Add a host filesystem"""
fields = {}
# Get the ihost object
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
for attr in args.name[0]:
try:
fs_name, size = attr.split("=", 1)
fields['name'] = fs_name
fields['size'] = size
except ValueError:
raise exc.CommandError('Filesystem creation attributes must be '
'FS_NAME=SIZE not "%s"' % attr)
try:
fields['ihost_uuid'] = ihost.uuid
fs = cc.host_fs.create(**fields)
except exc.HTTPNotFound:
raise exc.CommandError('Failed to create filesystem: host %s: fields %s' %
(args.hostnameorid, fields))
_print_fs_show(fs)