From fa1253eb9292c51be8874934cf40ec01574d68ea Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Thu, 19 Sep 2013 00:25:20 +0100 Subject: [PATCH] Implement chassis-show Added chassis-show command for v1. Partially implements: bp simple-crud Change-Id: If04b5a76bd385da3c01682ef6137d710b2143641 --- ironicclient/v1/chassis.py | 39 ++++++++++++++++++++++++++++++++++++++ ironicclient/v1/client.py | 2 ++ ironicclient/v1/shell.py | 16 ++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 ironicclient/v1/chassis.py diff --git a/ironicclient/v1/chassis.py b/ironicclient/v1/chassis.py new file mode 100644 index 000000000..4883d2a23 --- /dev/null +++ b/ironicclient/v1/chassis.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2013 Red Hat, Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from ironicclient.common import base + + +class Chassis(base.Resource): + def __repr__(self): + return "" % self._info + + +class ChassisManager(base.Manager): + resource_class = Chassis + + @staticmethod + def _path(id=None): + return '/v1/chassis/%s' % id if id else '/v1/chassis' + + def list(self): + return self._list(self._path()) + + def get(self, chassis_id): + try: + return self._list(self._path(chassis_id))[0] + except IndexError: + return None diff --git a/ironicclient/v1/client.py b/ironicclient/v1/client.py index bb82bcce2..813722451 100644 --- a/ironicclient/v1/client.py +++ b/ironicclient/v1/client.py @@ -14,6 +14,7 @@ # under the License. from ironicclient.common import http +from ironicclient.v1 import chassis class Client(http.HTTPClient): @@ -29,3 +30,4 @@ class Client(http.HTTPClient): def __init__(self, *args, **kwargs): """Initialize a new client for the Ironic v1 API.""" super(Client, self).__init__(*args, **kwargs) + self.chassis = chassis.ChassisManager(self) diff --git a/ironicclient/v1/shell.py b/ironicclient/v1/shell.py index 94e731d20..1d194952b 100644 --- a/ironicclient/v1/shell.py +++ b/ironicclient/v1/shell.py @@ -9,3 +9,19 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from ironicclient.common import utils +from ironicclient import exc + + +@utils.arg('chassis', metavar='', help="ID of chassis") +def do_chassis_show(self, args): + """Show a chassis.""" + try: + chassis = self.chassis.get(args.chassis) + except exc.HTTPNotFound: + raise exc.CommandError('Chassis not found: %s' % args.chassis) + else: + fields = ['uuid', 'description', 'extra'] + data = dict([(f, getattr(chassis, f, '')) for f in fields]) + utils.print_dict(data, wrap=72)