Implement chassis-show
Added chassis-show command for v1. Partially implements: bp simple-crud Change-Id: If04b5a76bd385da3c01682ef6137d710b2143641
This commit is contained in:
parent
ba073c0707
commit
fa1253eb92
ironicclient/v1
39
ironicclient/v1/chassis.py
Normal file
39
ironicclient/v1/chassis.py
Normal file
@ -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 "<Chassis %s>" % 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
|
@ -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)
|
||||
|
@ -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='<chassis>', 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user