summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server.py226
-rw-r--r--openstackclient/compute/v2/server_backup.py5
-rw-r--r--openstackclient/compute/v2/server_image.py4
3 files changed, 224 insertions, 11 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index e5a7a328..f8d6aad0 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -21,6 +21,7 @@ import io
import logging
import os
+import iso8601
from novaclient import api_versions
from novaclient.v2 import servers
from openstack import exceptions as sdk_exceptions
@@ -29,7 +30,6 @@ from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
-from oslo_utils import timeutils
from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
@@ -292,6 +292,10 @@ class AddFloatingIP(network_common.NetworkAndComputeCommand):
parsed_args.server,
)
ports = list(client.ports(device_id=server.id))
+ if not ports:
+ msg = _('No attached ports found to associate floating IP with')
+ raise exceptions.CommandError(msg)
+
# If the fixed IP address was specified, we need to find the
# corresponding port.
if parsed_args.fixed_ip_address:
@@ -354,6 +358,14 @@ class AddPort(command.Command):
metavar="<port>",
help=_("Port to add to the server (name or ID)"),
)
+ parser.add_argument(
+ '--tag',
+ metavar='<tag>',
+ help=_(
+ "Tag for the attached interface. "
+ "(Supported by API versions '2.49' - '2.latest')"
+ )
+ )
return parser
def take_action(self, parsed_args):
@@ -369,7 +381,22 @@ class AddPort(command.Command):
else:
port_id = parsed_args.port
- server.interface_attach(port_id=port_id, net_id=None, fixed_ip=None)
+ kwargs = {
+ 'port_id': port_id,
+ 'net_id': None,
+ 'fixed_ip': None,
+ }
+
+ if parsed_args.tag:
+ if compute_client.api_version < api_versions.APIVersion("2.49"):
+ msg = _(
+ '--os-compute-api-version 2.49 or greater is required to '
+ 'support the --tag option'
+ )
+ raise exceptions.CommandError(msg)
+ kwargs['tag'] = parsed_args.tag
+
+ server.interface_attach(**kwargs)
class AddNetwork(command.Command):
@@ -387,6 +414,14 @@ class AddNetwork(command.Command):
metavar="<network>",
help=_("Network to add to the server (name or ID)"),
)
+ parser.add_argument(
+ '--tag',
+ metavar='<tag>',
+ help=_(
+ 'Tag for the attached interface. '
+ '(supported by --os-compute-api-version 2.49 or above)'
+ ),
+ )
return parser
def take_action(self, parsed_args):
@@ -402,7 +437,23 @@ class AddNetwork(command.Command):
else:
net_id = parsed_args.network
- server.interface_attach(port_id=None, net_id=net_id, fixed_ip=None)
+ kwargs = {
+ 'port_id': None,
+ 'net_id': net_id,
+ 'fixed_ip': None,
+ }
+
+ if parsed_args.tag:
+ if compute_client.api_version < api_versions.APIVersion('2.49'):
+ msg = _(
+ '--os-compute-api-version 2.49 or greater is required to '
+ 'support the --tag option'
+ )
+ raise exceptions.CommandError(msg)
+
+ kwargs['tag'] = parsed_args.tag
+
+ server.interface_attach(**kwargs)
class AddServerSecurityGroup(command.Command):
@@ -1404,8 +1455,8 @@ class ListServer(command.Lister):
raise exceptions.CommandError(msg)
try:
- timeutils.parse_isotime(search_opts['changes-before'])
- except ValueError:
+ iso8601.parse_date(search_opts['changes-before'])
+ except (TypeError, iso8601.ParseError):
raise exceptions.CommandError(
_('Invalid changes-before value: %s') %
search_opts['changes-before']
@@ -1413,8 +1464,8 @@ class ListServer(command.Lister):
if search_opts['changes-since']:
try:
- timeutils.parse_isotime(search_opts['changes-since'])
- except ValueError:
+ iso8601.parse_date(search_opts['changes-since'])
+ except (TypeError, iso8601.ParseError):
raise exceptions.CommandError(
_('Invalid changes-since value: %s') %
search_opts['changes-since']
@@ -1814,6 +1865,167 @@ revert to release the new server and restart the old one.""")
raise SystemExit
+class ListMigration(command.Command):
+ _description = _("""List server migrations.""")
+
+ def get_parser(self, prog_name):
+ parser = super(ListMigration, self).get_parser(prog_name)
+ parser.add_argument(
+ "--server",
+ metavar="<server>",
+ dest='server',
+ default=None,
+ help=_('Server to show migration details (name or ID).')
+ )
+ parser.add_argument(
+ "--host",
+ metavar="<host>",
+ default=None,
+ help=_('Fetch migrations for the given host.')
+ )
+ parser.add_argument(
+ "--status",
+ metavar="<status>",
+ default=None,
+ help=_('Fetch migrations for the given status.')
+ )
+ parser.add_argument(
+ "--marker",
+ metavar="<marker>",
+ dest='marker',
+ default=None,
+ help=_("The last migration of the previous page; displays list "
+ "of migrations after 'marker'. Note that the marker is "
+ "the migration UUID. (Supported with "
+ "``--os-compute-api-version`` 2.59 or greater.)")
+ )
+ parser.add_argument(
+ "--limit",
+ metavar="<limit>",
+ dest='limit',
+ type=int,
+ default=None,
+ help=_("Maximum number of migrations to display. Note that there "
+ "is a configurable max limit on the server, and the limit "
+ "that is used will be the minimum of what is requested "
+ "here and what is configured in the server. "
+ "(Supported with ``--os-compute-api-version`` 2.59 "
+ "or greater.)")
+ )
+ parser.add_argument(
+ '--changes-since',
+ dest='changes_since',
+ metavar='<changes-since>',
+ default=None,
+ help=_("List only migrations changed later or equal to a certain "
+ "point of time. The provided time should be an ISO 8061 "
+ "formatted time, e.g. ``2016-03-04T06:27:59Z``. "
+ "(Supported with ``--os-compute-api-version`` 2.59 "
+ "or greater.)")
+ )
+ parser.add_argument(
+ '--changes-before',
+ dest='changes_before',
+ metavar='<changes-before>',
+ default=None,
+ help=_("List only migrations changed earlier or equal to a "
+ "certain point of time. The provided time should be an ISO "
+ "8061 formatted time, e.g. ``2016-03-04T06:27:59Z``. "
+ "(Supported with ``--os-compute-api-version`` 2.66 or "
+ "greater.)")
+ )
+ parser.add_argument(
+ '--project',
+ metavar='<project>',
+ dest='project_id',
+ default=None,
+ help=_("Filter the migrations by the given project ID. "
+ "(Supported with ``--os-compute-api-version`` 2.80 "
+ "or greater.)"),
+ )
+ parser.add_argument(
+ '--user',
+ metavar='<user>',
+ dest='user_id',
+ default=None,
+ help=_("Filter the migrations by the given user ID. "
+ "(Supported with ``--os-compute-api-version`` 2.80 "
+ "or greater.)"),
+ )
+ return parser
+
+ def print_migrations(self, parsed_args, compute_client, migrations):
+ columns = ['Source Node', 'Dest Node', 'Source Compute',
+ 'Dest Compute', 'Dest Host', 'Status',
+ 'Server UUID', 'Old Flavor', 'New Flavor',
+ 'Created At', 'Updated At']
+
+ # Insert migrations UUID after ID
+ if compute_client.api_version >= api_versions.APIVersion("2.59"):
+ columns.insert(0, "UUID")
+
+ # TODO(brinzhang): It also suppports filter migrations by type
+ # since 2.1. https://review.opendev.org/#/c/675117 supported
+ # filtering the migrations by 'migration_type' and 'source_compute'
+ # in novaclient, that will be added in OSC by follow-up.
+ if compute_client.api_version >= api_versions.APIVersion("2.23"):
+ columns.insert(0, "Id")
+ columns.insert(len(columns) - 2, "Type")
+
+ if compute_client.api_version >= api_versions.APIVersion("2.80"):
+ if parsed_args.project_id:
+ columns.insert(len(columns) - 2, "Project")
+ if parsed_args.user_id:
+ columns.insert(len(columns) - 2, "User")
+
+ columns_header = columns
+ return (columns_header, (utils.get_item_properties(
+ mig, columns) for mig in migrations))
+
+ def take_action(self, parsed_args):
+ compute_client = self.app.client_manager.compute
+
+ search_opts = {
+ "host": parsed_args.host,
+ "server": parsed_args.server,
+ "status": parsed_args.status,
+ }
+
+ if (parsed_args.marker or parsed_args.limit or
+ parsed_args.changes_since):
+ if compute_client.api_version < api_versions.APIVersion("2.59"):
+ msg = _("marker, limit and/or changes_since is not supported "
+ "for --os-compute-api-version less than 2.59")
+ raise exceptions.CommandError(msg)
+ if parsed_args.marker:
+ search_opts['marker'] = parsed_args.marker
+ if parsed_args.limit:
+ search_opts['limit'] = parsed_args.limit
+ if parsed_args.changes_since:
+ search_opts['changes_since'] = parsed_args.changes_since
+
+ if parsed_args.changes_before:
+ if compute_client.api_version < api_versions.APIVersion("2.66"):
+ msg = _("changes_before is not supported for "
+ "--os-compute-api-version less than 2.66")
+ raise exceptions.CommandError(msg)
+ search_opts['changes_before'] = parsed_args.changes_before
+
+ if parsed_args.project_id or parsed_args.user_id:
+ if compute_client.api_version < api_versions.APIVersion("2.80"):
+ msg = _("Project and/or user is not supported for "
+ "--os-compute-api-version less than 2.80")
+ raise exceptions.CommandError(msg)
+ if parsed_args.project_id:
+ search_opts['project_id'] = parsed_args.project_id
+ if parsed_args.user_id:
+ search_opts['user_id'] = parsed_args.user_id
+
+ migrations = compute_client.migrations.list(**search_opts)
+
+ return self.print_migrations(parsed_args, compute_client, migrations)
+
+
class PauseServer(command.Command):
_description = _("Pause server(s)")
diff --git a/openstackclient/compute/v2/server_backup.py b/openstackclient/compute/v2/server_backup.py
index a5d43fc6..b1b821b2 100644
--- a/openstackclient/compute/v2/server_backup.py
+++ b/openstackclient/compute/v2/server_backup.py
@@ -15,10 +15,11 @@
"""Compute v2 Server action implementations"""
+import importlib
+
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
-from oslo_utils import importutils
from openstackclient.i18n import _
@@ -119,7 +120,7 @@ class CreateServerBackup(command.ShowOne):
info['properties'] = utils.format_dict(info.get('properties', {}))
else:
# Get the right image module to format the output
- image_module = importutils.import_module(
+ image_module = importlib.import_module(
self.IMAGE_API_VERSIONS[
self.app.client_manager._api_version['image']
]
diff --git a/openstackclient/compute/v2/server_image.py b/openstackclient/compute/v2/server_image.py
index fea87af8..c12bc2b3 100644
--- a/openstackclient/compute/v2/server_image.py
+++ b/openstackclient/compute/v2/server_image.py
@@ -15,12 +15,12 @@
"""Compute v2 Server action implementations"""
+import importlib
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
-from oslo_utils import importutils
from openstackclient.i18n import _
@@ -99,7 +99,7 @@ class CreateServerImage(command.ShowOne):
info['properties'] = utils.format_dict(info.get('properties', {}))
else:
# Get the right image module to format the output
- image_module = importutils.import_module(
+ image_module = importlib.import_module(
self.IMAGE_API_VERSIONS[
self.app.client_manager._api_version['image']
]