Skip to content

Commit 861e1a8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Finish switching server migration to sdk"
2 parents 8786767 + d1c1c36 commit 861e1a8

File tree

4 files changed

+196
-166
lines changed

4 files changed

+196
-166
lines changed

openstackclient/compute/v2/server_migration.py

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import uuid
1616

17-
from novaclient import api_versions
1817
from openstack import utils as sdk_utils
1918
from osc_lib.command import command
2019
from osc_lib import exceptions
@@ -256,7 +255,7 @@ def take_action(self, parsed_args):
256255

257256

258257
def _get_migration_by_uuid(compute_client, server_id, migration_uuid):
259-
for migration in compute_client.server_migrations.list(server_id):
258+
for migration in compute_client.server_migrations(server_id):
260259
if migration.uuid == migration_uuid:
261260
return migration
262261
break
@@ -290,9 +289,9 @@ def get_parser(self, prog_name):
290289
return parser
291290

292291
def take_action(self, parsed_args):
293-
compute_client = self.app.client_manager.compute
292+
compute_client = self.app.client_manager.sdk_connection.compute
294293

295-
if compute_client.api_version < api_versions.APIVersion('2.24'):
294+
if not sdk_utils.supports_microversion(compute_client, '2.24'):
296295
msg = _(
297296
'--os-compute-api-version 2.24 or greater is required to '
298297
'support the server migration show command'
@@ -308,16 +307,16 @@ def take_action(self, parsed_args):
308307
)
309308
raise exceptions.CommandError(msg)
310309

311-
if compute_client.api_version < api_versions.APIVersion('2.59'):
310+
if not sdk_utils.supports_microversion(compute_client, '2.59'):
312311
msg = _(
313312
'--os-compute-api-version 2.59 or greater is required to '
314313
'retrieve server migrations by UUID'
315314
)
316315
raise exceptions.CommandError(msg)
317316

318-
server = utils.find_resource(
319-
compute_client.servers,
317+
server = compute_client.find_server(
320318
parsed_args.server,
319+
ignore_missing=False,
321320
)
322321

323322
# the nova API doesn't currently allow retrieval by UUID but it's a
@@ -328,11 +327,13 @@ def take_action(self, parsed_args):
328327
compute_client, server.id, parsed_args.migration,
329328
)
330329
else:
331-
server_migration = compute_client.server_migrations.get(
332-
server.id, parsed_args.migration,
330+
server_migration = compute_client.get_server_migration(
331+
server.id,
332+
parsed_args.migration,
333+
ignore_missing=False,
333334
)
334335

335-
columns = (
336+
column_headers = (
336337
'ID',
337338
'Server UUID',
338339
'Status',
@@ -351,14 +352,35 @@ def take_action(self, parsed_args):
351352
'Updated At',
352353
)
353354

354-
if compute_client.api_version >= api_versions.APIVersion('2.59'):
355-
columns += ('UUID',)
355+
columns = (
356+
'id',
357+
'server_id',
358+
'status',
359+
'source_compute',
360+
'source_node',
361+
'dest_compute',
362+
'dest_host',
363+
'dest_node',
364+
'memory_total_bytes',
365+
'memory_processed_bytes',
366+
'memory_remaining_bytes',
367+
'disk_total_bytes',
368+
'disk_processed_bytes',
369+
'disk_remaining_bytes',
370+
'created_at',
371+
'updated_at',
372+
)
356373

357-
if compute_client.api_version >= api_versions.APIVersion('2.80'):
358-
columns += ('User ID', 'Project ID')
374+
if sdk_utils.supports_microversion(compute_client, '2.59'):
375+
column_headers += ('UUID',)
376+
columns += ('uuid',)
377+
378+
if sdk_utils.supports_microversion(compute_client, '2.80'):
379+
column_headers += ('User ID', 'Project ID')
380+
columns += ('user_id', 'project_id')
359381

360382
data = utils.get_item_properties(server_migration, columns)
361-
return columns, data
383+
return column_headers, data
362384

363385

364386
class AbortMigration(command.Command):
@@ -382,9 +404,9 @@ def get_parser(self, prog_name):
382404
return parser
383405

384406
def take_action(self, parsed_args):
385-
compute_client = self.app.client_manager.compute
407+
compute_client = self.app.client_manager.sdk_connection.compute
386408

387-
if compute_client.api_version < api_versions.APIVersion('2.24'):
409+
if not sdk_utils.supports_microversion(compute_client, '2.24'):
388410
msg = _(
389411
'--os-compute-api-version 2.24 or greater is required to '
390412
'support the server migration abort command'
@@ -400,16 +422,16 @@ def take_action(self, parsed_args):
400422
)
401423
raise exceptions.CommandError(msg)
402424

403-
if compute_client.api_version < api_versions.APIVersion('2.59'):
425+
if not sdk_utils.supports_microversion(compute_client, '2.59'):
404426
msg = _(
405427
'--os-compute-api-version 2.59 or greater is required to '
406428
'abort server migrations by UUID'
407429
)
408430
raise exceptions.CommandError(msg)
409431

410-
server = utils.find_resource(
411-
compute_client.servers,
432+
server = compute_client.find_server(
412433
parsed_args.server,
434+
ignore_missing=False,
413435
)
414436

415437
# the nova API doesn't currently allow retrieval by UUID but it's a
@@ -421,8 +443,10 @@ def take_action(self, parsed_args):
421443
compute_client, server.id, parsed_args.migration,
422444
).id
423445

424-
compute_client.server_migrations.live_migration_abort(
425-
server.id, migration_id,
446+
compute_client.abort_server_migration(
447+
migration_id,
448+
server.id,
449+
ignore_missing=False,
426450
)
427451

428452

@@ -447,9 +471,9 @@ def get_parser(self, prog_name):
447471
return parser
448472

449473
def take_action(self, parsed_args):
450-
compute_client = self.app.client_manager.compute
474+
compute_client = self.app.client_manager.sdk_connection.compute
451475

452-
if compute_client.api_version < api_versions.APIVersion('2.22'):
476+
if not sdk_utils.supports_microversion(compute_client, '2.22'):
453477
msg = _(
454478
'--os-compute-api-version 2.22 or greater is required to '
455479
'support the server migration force complete command'
@@ -465,16 +489,16 @@ def take_action(self, parsed_args):
465489
)
466490
raise exceptions.CommandError(msg)
467491

468-
if compute_client.api_version < api_versions.APIVersion('2.59'):
492+
if not sdk_utils.supports_microversion(compute_client, '2.59'):
469493
msg = _(
470494
'--os-compute-api-version 2.59 or greater is required to '
471495
'abort server migrations by UUID'
472496
)
473497
raise exceptions.CommandError(msg)
474498

475-
server = utils.find_resource(
476-
compute_client.servers,
499+
server = compute_client.find_server(
477500
parsed_args.server,
501+
ignore_missing=False,
478502
)
479503

480504
# the nova API doesn't currently allow retrieval by UUID but it's a
@@ -486,6 +510,6 @@ def take_action(self, parsed_args):
486510
compute_client, server.id, parsed_args.migration,
487511
).id
488512

489-
compute_client.server_migrations.live_migrate_force_complete(
490-
server.id, migration_id,
513+
compute_client.force_complete_server_migration(
514+
migration_id, server.id
491515
)

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from openstack.compute.v2 import server as _server
2626
from openstack.compute.v2 import server_group as _server_group
2727
from openstack.compute.v2 import server_interface as _server_interface
28+
from openstack.compute.v2 import server_migration as _server_migration
2829
from openstack.compute.v2 import service
2930
from openstack.compute.v2 import volume_attachment
3031

@@ -1483,57 +1484,61 @@ def create_migrations(attrs=None, count=2):
14831484
return migrations
14841485

14851486

1486-
class FakeServerMigration(object):
1487-
"""Fake one or more server migrations."""
1487+
def create_one_server_migration(attrs=None):
1488+
"""Create a fake server migration.
14881489
1489-
@staticmethod
1490-
def create_one_server_migration(attrs=None, methods=None):
1491-
"""Create a fake server migration.
1490+
:param dict attrs: A dictionary with all attributes
1491+
:return A fake openstack.compute.v2.server_migration.ServerMigration object
1492+
"""
1493+
attrs = attrs or {}
14921494

1493-
:param dict attrs:
1494-
A dictionary with all attributes
1495-
:param dict methods:
1496-
A dictionary with all methods
1497-
:return:
1498-
A FakeResource object, with id, type, and so on
1499-
"""
1500-
attrs = attrs or {}
1501-
methods = methods or {}
1495+
# Set default attributes.
15021496

1503-
# Set default attributes.
1497+
migration_info = {
1498+
"created_at": "2016-01-29T13:42:02.000000",
1499+
"dest_compute": "compute2",
1500+
"dest_host": "1.2.3.4",
1501+
"dest_node": "node2",
1502+
"id": random.randint(1, 999),
1503+
"server_uuid": uuid.uuid4().hex,
1504+
"source_compute": "compute1",
1505+
"source_node": "node1",
1506+
"status": "running",
1507+
"memory_total_bytes": random.randint(1, 99999),
1508+
"memory_processed_bytes": random.randint(1, 99999),
1509+
"memory_remaining_bytes": random.randint(1, 99999),
1510+
"disk_total_bytes": random.randint(1, 99999),
1511+
"disk_processed_bytes": random.randint(1, 99999),
1512+
"disk_remaining_bytes": random.randint(1, 99999),
1513+
"updated_at": "2016-01-29T13:42:02.000000",
1514+
# added in 2.59
1515+
"uuid": uuid.uuid4().hex,
1516+
# added in 2.80
1517+
"user_id": uuid.uuid4().hex,
1518+
"project_id": uuid.uuid4().hex,
1519+
}
15041520

1505-
migration_info = {
1506-
"created_at": "2016-01-29T13:42:02.000000",
1507-
"dest_compute": "compute2",
1508-
"dest_host": "1.2.3.4",
1509-
"dest_node": "node2",
1510-
"id": random.randint(1, 999),
1511-
"server_uuid": uuid.uuid4().hex,
1512-
"source_compute": "compute1",
1513-
"source_node": "node1",
1514-
"status": "running",
1515-
"memory_total_bytes": random.randint(1, 99999),
1516-
"memory_processed_bytes": random.randint(1, 99999),
1517-
"memory_remaining_bytes": random.randint(1, 99999),
1518-
"disk_total_bytes": random.randint(1, 99999),
1519-
"disk_processed_bytes": random.randint(1, 99999),
1520-
"disk_remaining_bytes": random.randint(1, 99999),
1521-
"updated_at": "2016-01-29T13:42:02.000000",
1522-
# added in 2.59
1523-
"uuid": uuid.uuid4().hex,
1524-
# added in 2.80
1525-
"user_id": uuid.uuid4().hex,
1526-
"project_id": uuid.uuid4().hex,
1527-
}
1521+
# Overwrite default attributes.
1522+
migration_info.update(attrs)
15281523

1529-
# Overwrite default attributes.
1530-
migration_info.update(attrs)
1524+
migration = _server_migration.ServerMigration(**migration_info)
1525+
return migration
15311526

1532-
migration = fakes.FakeResource(
1533-
info=copy.deepcopy(migration_info),
1534-
methods=methods,
1535-
loaded=True)
1536-
return migration
1527+
1528+
def create_server_migrations(attrs=None, methods=None, count=2):
1529+
"""Create multiple server migrations.
1530+
1531+
:param dict attrs: A dictionary with all attributes
1532+
:param int count: The number of server migrations to fake
1533+
:return A list of fake
1534+
openstack.compute.v2.server_migration.ServerMigration objects
1535+
"""
1536+
migrations = []
1537+
for i in range(0, count):
1538+
migrations.append(
1539+
create_one_server_migration(attrs, methods))
1540+
1541+
return migrations
15371542

15381543

15391544
def create_one_volume_attachment(attrs=None):

0 commit comments

Comments
 (0)