Add driver-list

The driver-list command returns a list of drivers supported by the
ironic conductors.

Change-Id: I24adbde087396fb5c01226ef7a2b602ff8732227
This commit is contained in:
Lucas Alvares Gomes
2013-10-24 17:26:43 +01:00
parent ce93dd5ce1
commit 29f806698f
5 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# coding: utf-8
#
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
import testtools
from testtools import matchers
from ironicclient.tests import utils
import ironicclient.v1.driver
DRIVER = {'name': 'fake'}
fake_responses = {
'/v1/drivers':
{
'GET': (
{},
{'drivers': [DRIVER]},
),
},
}
class DriverManagerTest(testtools.TestCase):
def setUp(self):
super(DriverManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses)
self.mgr = ironicclient.v1.driver.DriverManager(self.api)
def test_driver_list(self):
drivers = self.mgr.list()
expect = [
('GET', '/v1/drivers', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertThat(drivers, matchers.HasLength(1))

View File

@@ -15,6 +15,7 @@
from ironicclient.common import http
from ironicclient.v1 import chassis
from ironicclient.v1 import driver
from ironicclient.v1 import node
from ironicclient.v1 import port
@@ -35,3 +36,4 @@ class Client(http.HTTPClient):
self.chassis = chassis.ChassisManager(self)
self.node = node.NodeManager(self)
self.port = port.PortManager(self)
self.driver = driver.DriverManager(self)

31
ironicclient/v1/driver.py Normal file
View File

@@ -0,0 +1,31 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# coding: utf-8
#
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
# 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 Driver(base.Resource):
def __repr__(self):
return "<Driver %s>" % self._info
class DriverManager(base.Manager):
resource_class = Driver
def list(self):
return self._list('/v1/drivers', "drivers")

View File

@@ -0,0 +1,27 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# coding: utf-8
#
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
# 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 utils
def do_driver_list(cc, args):
"""List drivers."""
driver = cc.driver.list()
field_labels = ['Supported drivers']
fields = ['name']
utils.print_list(driver, fields, field_labels)

View File

@@ -13,6 +13,7 @@
from ironicclient.common import utils
from ironicclient.v1 import chassis_shell
from ironicclient.v1 import driver_shell
from ironicclient.v1 import node_shell
from ironicclient.v1 import port_shell
@@ -20,6 +21,7 @@ COMMAND_MODULES = [
chassis_shell,
node_shell,
port_shell,
driver_shell,
]