Skip to content

Commit 9a976ad

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "compute: Add missing options for 'server list'"
2 parents bbf7de8 + d0112a8 commit 9a976ad

3 files changed

Lines changed: 361 additions & 12 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 207 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,18 +1346,18 @@ def _show_progress(progress):
13461346
raise SystemExit
13471347

13481348

1349+
def percent_type(x):
1350+
x = int(x)
1351+
if not 0 < x <= 100:
1352+
raise argparse.ArgumentTypeError("Must be between 0 and 100")
1353+
return x
1354+
1355+
13491356
class ListServer(command.Lister):
13501357
_description = _("List servers")
13511358

13521359
def get_parser(self, prog_name):
13531360
parser = super(ListServer, self).get_parser(prog_name)
1354-
parser.add_argument(
1355-
'--availability-zone',
1356-
metavar='<availability-zone>',
1357-
help=_('Only return instances that match the availability zone. '
1358-
'Note that this option will be ignored for non-admin users '
1359-
'when using ``--os-compute-api-version`` prior to 2.83.'),
1360-
)
13611361
parser.add_argument(
13621362
'--reservation-id',
13631363
metavar='<reservation-id>',
@@ -1387,10 +1387,35 @@ def get_parser(self, prog_name):
13871387
metavar='<server-name>',
13881388
help=_('Regular expression to match instance name (admin only)'),
13891389
)
1390+
# taken from 'task_and_vm_state_from_status' function in nova
1391+
# the API sadly reports these in upper case and while it would be
1392+
# wonderful to plaster over this ugliness client-side, there are
1393+
# already users in the wild doing this in upper case that we need to
1394+
# support
13901395
parser.add_argument(
13911396
'--status',
13921397
metavar='<status>',
1393-
# FIXME(dhellmann): Add choices?
1398+
choices=(
1399+
'ACTIVE',
1400+
'BUILD',
1401+
'DELETED',
1402+
'ERROR',
1403+
'HARD_REBOOT',
1404+
'MIGRATING',
1405+
'PASSWORD',
1406+
'PAUSED',
1407+
'REBOOT',
1408+
'REBUILD',
1409+
'RESCUE',
1410+
'RESIZE',
1411+
'REVERT_RESIZE',
1412+
'SHELVED',
1413+
'SHELVED_OFFLOADED',
1414+
'SHUTOFF',
1415+
'SOFT_DELETED',
1416+
'SUSPENDED',
1417+
'VERIFY_RESIZE'
1418+
),
13941419
help=_('Search by server status'),
13951420
)
13961421
parser.add_argument(
@@ -1423,7 +1448,10 @@ def get_parser(self, prog_name):
14231448
parser.add_argument(
14241449
'--user',
14251450
metavar='<user>',
1426-
help=_('Search by user (admin only) (name or ID)'),
1451+
help=_(
1452+
'Search by user (name or ID) '
1453+
'(admin only before microversion 2.83)'
1454+
),
14271455
)
14281456
identity_common.add_user_domain_option_to_parser(parser)
14291457
parser.add_argument(
@@ -1432,6 +1460,146 @@ def get_parser(self, prog_name):
14321460
default=False,
14331461
help=_('Only display deleted servers (admin only)'),
14341462
)
1463+
parser.add_argument(
1464+
'--availability-zone',
1465+
default=None,
1466+
help=_(
1467+
'Search by availability zone '
1468+
'(admin only before microversion 2.83)'
1469+
),
1470+
)
1471+
parser.add_argument(
1472+
'--key-name',
1473+
help=_(
1474+
'Search by keypair name '
1475+
'(admin only before microversion 2.83)'
1476+
),
1477+
)
1478+
config_drive_group = parser.add_mutually_exclusive_group()
1479+
config_drive_group.add_argument(
1480+
'--config-drive',
1481+
action='store_true',
1482+
dest='has_config_drive',
1483+
default=None,
1484+
help=_(
1485+
'Only display servers with a config drive attached '
1486+
'(admin only before microversion 2.83)'
1487+
),
1488+
)
1489+
# NOTE(gibi): this won't actually do anything until bug 1871409 is
1490+
# fixed and the REST API is cleaned up regarding the values of
1491+
# config_drive
1492+
config_drive_group.add_argument(
1493+
'--no-config-drive',
1494+
action='store_false',
1495+
dest='has_config_drive',
1496+
help=_(
1497+
'Only display servers without a config drive attached '
1498+
'(admin only before microversion 2.83)'
1499+
),
1500+
)
1501+
parser.add_argument(
1502+
'--progress',
1503+
type=percent_type,
1504+
default=None,
1505+
help=_(
1506+
'Search by progress value (%%) '
1507+
'(admin only before microversion 2.83)'
1508+
),
1509+
)
1510+
parser.add_argument(
1511+
'--vm-state',
1512+
metavar='<state>',
1513+
# taken from 'InstanceState' object field in nova
1514+
choices=(
1515+
'active',
1516+
'building',
1517+
'deleted',
1518+
'error',
1519+
'paused',
1520+
'stopped',
1521+
'suspended',
1522+
'rescued',
1523+
'resized',
1524+
'shelved',
1525+
'shelved_offloaded',
1526+
'soft-delete',
1527+
),
1528+
help=_(
1529+
'Search by vm_state value '
1530+
'(admin only before microversion 2.83)'
1531+
),
1532+
)
1533+
parser.add_argument(
1534+
'--task-state',
1535+
metavar='<state>',
1536+
# taken from 'InstanceTaskState' object field in nova
1537+
choices=(
1538+
'block_device_mapping',
1539+
'deleting',
1540+
'image_backup',
1541+
'image_pending_upload',
1542+
'image_snapshot',
1543+
'image_snapshot_pending',
1544+
'image_uploading',
1545+
'migrating',
1546+
'networking',
1547+
'pausing',
1548+
'powering-off',
1549+
'powering-on',
1550+
'rebooting',
1551+
'reboot_pending',
1552+
'reboot_started',
1553+
'reboot_pending_hard',
1554+
'reboot_started_hard',
1555+
'rebooting_hard',
1556+
'rebuilding',
1557+
'rebuild_block_device_mapping',
1558+
'rebuild_spawning',
1559+
'rescuing',
1560+
'resize_confirming',
1561+
'resize_finish',
1562+
'resize_migrated',
1563+
'resize_migrating',
1564+
'resize_prep',
1565+
'resize_reverting',
1566+
'restoring',
1567+
'resuming',
1568+
'scheduling',
1569+
'shelving',
1570+
'shelving_image_pending_upload',
1571+
'shelving_image_uploading',
1572+
'shelving_offloading',
1573+
'soft-deleting',
1574+
'spawning',
1575+
'suspending',
1576+
'updating_password',
1577+
'unpausing',
1578+
'unrescuing',
1579+
'unshelving',
1580+
),
1581+
help=_(
1582+
'Search by task_state value '
1583+
'(admin only before microversion 2.83)'
1584+
),
1585+
)
1586+
parser.add_argument(
1587+
'--power-state',
1588+
metavar='<state>',
1589+
# taken from 'InstancePowerState' object field in nova
1590+
choices=(
1591+
'pending',
1592+
'running',
1593+
'paused',
1594+
'shutdown',
1595+
'crashed',
1596+
'suspended',
1597+
),
1598+
help=_(
1599+
'Search by power_state value '
1600+
'(admin only before microversion 2.83)'
1601+
),
1602+
)
14351603
parser.add_argument(
14361604
'--long',
14371605
action='store_true',
@@ -1584,7 +1752,6 @@ def take_action(self, parsed_args):
15841752
ignore_missing=False).id
15851753

15861754
search_opts = {
1587-
'availability_zone': parsed_args.availability_zone,
15881755
'reservation_id': parsed_args.reservation_id,
15891756
'ip': parsed_args.ip,
15901757
'ip6': parsed_args.ip6,
@@ -1602,6 +1769,36 @@ def take_action(self, parsed_args):
16021769
'changes-since': parsed_args.changes_since,
16031770
}
16041771

1772+
if parsed_args.availability_zone:
1773+
search_opts['availability_zone'] = parsed_args.availability_zone
1774+
1775+
if parsed_args.key_name:
1776+
search_opts['key_name'] = parsed_args.key_name
1777+
1778+
if parsed_args.has_config_drive is not None:
1779+
search_opts['config_drive'] = parsed_args.has_config_drive
1780+
1781+
if parsed_args.progress is not None:
1782+
search_opts['progress'] = str(parsed_args.progress)
1783+
1784+
if parsed_args.vm_state:
1785+
search_opts['vm_state'] = parsed_args.vm_state
1786+
1787+
if parsed_args.task_state:
1788+
search_opts['task_state'] = parsed_args.task_state
1789+
1790+
if parsed_args.power_state:
1791+
# taken from 'InstancePowerState' object field in nova
1792+
power_state = {
1793+
'pending': 0,
1794+
'running': 1,
1795+
'paused': 3,
1796+
'shutdown': 4,
1797+
'crashed': 6,
1798+
'suspended': 7,
1799+
}[parsed_args.power_state]
1800+
search_opts['power_state'] = power_state
1801+
16051802
if parsed_args.tags:
16061803
if compute_client.api_version < api_versions.APIVersion('2.26'):
16071804
msg = _(

0 commit comments

Comments
 (0)