diff --git a/karborclient/osc/v1/checkpoints.py b/karborclient/osc/v1/checkpoints.py index 098f95b..9cbc761 100644 --- a/karborclient/osc/v1/checkpoints.py +++ b/karborclient/osc/v1/checkpoints.py @@ -12,6 +12,7 @@ """Data protection V1 checkpoint action implementations""" +import json from osc_lib.command import command from osc_lib import utils as osc_utils from oslo_log import log as logging @@ -21,6 +22,17 @@ from karborclient.i18n import _ from karborclient import utils +def format_checkpoint(checkpoint_info): + if 'protection_plan' in checkpoint_info: + plan = checkpoint_info['protection_plan'] + checkpoint_info['protection_plan'] = "Name: %s\nId: %s" % ( + plan['name'], plan['id']) + if 'resource_graph' in checkpoint_info: + checkpoint_info['resource_graph'] = json.dumps(json.loads( + checkpoint_info['resource_graph']), indent=2, sort_keys=True) + checkpoint_info.pop("links", None) + + class ListCheckpoints(command.Lister): _description = _("List checkpoints.") @@ -130,7 +142,7 @@ class ShowCheckpoint(command.ShowOne): client = self.app.client_manager.data_protection checkpoint = client.checkpoints.get(parsed_args.provider_id, parsed_args.checkpoint_id) - checkpoint._info.pop("links", None) + format_checkpoint(checkpoint._info) return zip(*sorted(checkpoint._info.items())) @@ -167,7 +179,7 @@ class CreateCheckpoint(command.ShowOne): checkpoint = client.checkpoints.create(parsed_args.provider_id, parsed_args.plan_id, checkpoint_extra_info) - checkpoint._info.pop("links", None) + format_checkpoint(checkpoint._info) return zip(*sorted(checkpoint._info.items())) diff --git a/karborclient/tests/unit/osc/v1/test_checkpoints.py b/karborclient/tests/unit/osc/v1/test_checkpoints.py index ae790d3..d568bcb 100644 --- a/karborclient/tests/unit/osc/v1/test_checkpoints.py +++ b/karborclient/tests/unit/osc/v1/test_checkpoints.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json + from karborclient.osc.v1 import checkpoints as osc_checkpoints from karborclient.tests.unit.osc.v1 import fakes from karborclient.v1 import checkpoints @@ -29,9 +31,11 @@ CHECKPOINT_INFO = { "type": "OS::Glance::Image", "name": "cirros-0.3.4-x86_64-uec"}] }, - "resource_graph": "[{'0x0': ['OS::Glance::Image', " - "'99777fdd-8a5b-45ab-ba2c-52420008103f', " - "'cirros-0.3.4-x86_64-uec']}, [[['0x0']]]]" + "resource_graph": json.dumps( + "[{'0x0': ['OS::Glance::Image', " + "'99777fdd-8a5b-45ab-ba2c-52420008103f', " + "'cirros-0.3.4-x86_64-uec']}, [[['0x0']]]]" + ), }