1399
1400
_('createTime'))
1401
for drive in drives:
1402
for name, vol_type in drives.iteritems():
1403
drive = vol_type.get('extra_specs')
1402
1404
print format_str %\
1406
str(drive['size_gb']),
1408
drive['capabilities'],
1409
str(drive['visible']),
1410
str(drive['created_at']))
1405
(str(vol_type['id']),
1406
drive['drive_name'],
1407
drive['drive_type'],
1408
drive['drive_size'],
1410
drive.get('capabilities', ''),
1411
str(drive.get('visible', '')),
1412
str(vol_type['created_at']))
1412
1414
@args('--type', dest='type', metavar="<type>",
1413
1415
help='Drive type (SATA, SAS, SSD, etc.)')
1414
1416
@args('--size', dest='size_gb', metavar="<gb>", help='Drive size in GB')
1415
1417
@args('--rpm', dest='rpm', metavar="<rpm>", help='RPM')
1416
@args('--capabilities', dest='capabilities', metavar="<string>",
1417
help='Different capabilities')
1418
@args('--visible', dest='visible', metavar="<show|hide>",
1418
@args('--capabilities', dest='capabilities', default=None,
1419
metavar="<string>", help='Different capabilities')
1420
@args('--hide', dest='hide', action="store_true", default=False,
1419
1421
help='Show or hide drive')
1420
1422
@args('--name', dest='name', metavar="<name>", help='Drive name')
1421
def create(self, type, size_gb, rpm, capabilities='',
1422
visible=None, name=None):
1423
def create(self, type, size_gb, rpm, capabilities=None,
1424
hide=False, name=None):
1423
1425
"""Create drive type."""
1425
if visible in [None, "--show", "show"]:
1427
elif visible in ["--hide", "hide"]:
1427
hide = True if hide in [True, "True", "--hide", "hide"] else False
1430
name = self._drive_type_template % (type, size_gb, rpm)
1432
extra_specs = {'type': 'vsa_drive',
1435
'drive_size': size_gb,
1440
extra_specs['visible'] = False
1442
if capabilities is not None and capabilities != '':
1443
extra_specs['capabilities'] = capabilities
1445
volume_types.create(self.context, name, extra_specs)
1446
result = volume_types.get_volume_type_by_name(self.context, name)
1447
self._list({name: result})
1449
@args('--name', dest='name', metavar="<name>", help='Drive name')
1450
@args('--purge', action="store_true", dest='purge', default=False,
1451
help='purge record from database')
1452
def delete(self, name, purge):
1453
"""Marks instance types / flavors as deleted"""
1456
volume_types.purge(self.context, name)
1459
volume_types.destroy(self.context, name)
1461
except exception.ApiError:
1462
print "Valid volume type name is required"
1464
except exception.DBError, e:
1465
print "DB Error: %s" % e
1430
raise ValueError(_('Visible parameter should be set to --show '\
1433
result = drive_types.create(self.context,
1434
type, int(size_gb), rpm,
1435
capabilities, visible, name)
1436
self._list([result])
1438
@args('--name', dest='name', metavar="<name>", help='Drive name')
1439
def delete(self, name):
1440
"""Delete drive type."""
1442
dtype = drive_types.get_by_name(self.context, name)
1443
drive_types.delete(self.context, dtype['id'])
1445
@args('--name', dest='name', metavar="<name>", help='Drive name')
1446
@args('--new_name', dest='new_name', metavar="<name>",
1447
help='New Drive name (optional)')
1448
def rename(self, name, new_name=None):
1449
"""Rename drive type."""
1451
dtype = drive_types.rename(self.context,
1455
@args('--all', dest='visible', action="store_false",
1456
help='Show all drives')
1470
print "%s %s" % (name, verb)
1472
@args('--all', dest='all', action="store_true", default=False,
1473
help='Show all drives (including invisible)')
1457
1474
@args('--name', dest='name', metavar="<name>",
1458
1475
help='Show only specified drive')
1459
def list(self, visible=None, name=None):
1476
def list(self, all=False, name=None):
1460
1477
"""Describe all available VSA drive types (or particular one)."""
1462
visible = False if visible in ["--all", False] else True
1479
all = False if all in ["--all", False, "False"] else True
1481
search_opts = {'extra_specs': {'type': 'vsa_drive'}}
1464
1482
if name is not None:
1465
drive = drive_types.get_by_name(self.context, name)
1468
drives = drive_types.get_all(self.context, visible)
1483
search_opts['extra_specs']['name'] = name
1486
search_opts['extra_specs']['visible'] = '1'
1488
drives = volume_types.get_all_types(self.context,
1489
search_opts=search_opts)
1470
1490
self._list(drives)
1472
1492
@args('--name', dest='name', metavar="<name>", help='Drive name')
1474
1494
help='Drive type (SATA, SAS, SSD, etc.)')
1475
1495
@args('--size', dest='size_gb', metavar="<gb>", help='Drive size in GB')
1476
1496
@args('--rpm', dest='rpm', metavar="<rpm>", help='RPM')
1477
@args('--capabilities', dest='capabilities', metavar="<string>",
1478
help='Different capabilities')
1479
@args('--visible', dest='visible', metavar="<show|hide>",
1480
help='Show or hide drive')
1497
@args('--capabilities', dest='capabilities', default=None,
1498
metavar="<string>", help='Different capabilities')
1499
@args('--visible', dest='visible',
1500
metavar="<show|hide>", help='Show or hide drive')
1481
1501
def update(self, name, type=None, size_gb=None, rpm=None,
1482
capabilities='', visible=None):
1502
capabilities=None, visible=None):
1483
1503
"""Update drive type."""
1489
'capabilities': capabilities,
1492
if visible in ["--show", "show"]:
1493
values['visible'] = True
1494
elif visible in ["--hide", "hide"]:
1495
values['visible'] = False
1505
volume_type = volume_types.get_volume_type_by_name(self.context, name)
1507
extra_specs = {'type': 'vsa_drive'}
1510
extra_specs['drive_type'] = type
1513
extra_specs['drive_size'] = size_gb
1516
extra_specs['drive_rpm'] = rpm
1519
extra_specs['capabilities'] = capabilities
1521
if visible is not None:
1522
if visible in ["show", True, "True"]:
1523
extra_specs['visible'] = True
1524
elif visible in ["hide", False, "False"]:
1525
extra_specs['visible'] = False
1497
raise ValueError(_("Visible parameter should be set to "\
1498
"--show or --hide"))
1527
raise ValueError(_('visible parameter should be set to '\
1500
dtype = drive_types.get_by_name(self.context, name)
1501
dtype = drive_types.update(self.context, dtype['id'], **values)
1530
db.api.volume_type_extra_specs_update_or_create(self.context,
1533
result = volume_types.get_volume_type_by_name(self.context, name)
1534
self._list({name: result})
1505
1537
class VolumeCommands(object):