Driver resource for bare-metal service

This adds the Driver resource to the bare-metal (ironic) service.

Change-Id: I26da9d910809d2ffd1c541d91284caf5b86e9560
This commit is contained in:
tengqm 2016-12-14 05:05:09 -05:00
parent 28922b3c28
commit acb94cfbf4
2 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,39 @@
# 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 openstack.bare_metal import bare_metal_service
from openstack import resource2 as resource
class Driver(resource.Resource):
resources_key = 'drivers'
base_path = '/drivers'
service = bare_metal_service.BareMetalService()
# capabilities
allow_create = False
allow_get = True
allow_update = False
allow_delete = False
allow_list = True
# NOTE: Query mapping?
#: The name of the driver
name = resource.Body('name', alternate_id=True)
#: A list of active hosts that support this driver.
hosts = resource.Body('hosts', type=list)
#: A list of relative links, including the self and bookmark links.
links = resource.Body('links', type=list)
#: A list of links to driver properties.
properties = resource.Body('properties', type=list)

View File

@ -0,0 +1,66 @@
# 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 openstack.bare_metal.v1 import driver
FAKE = {
"hosts": [
"897ab1dad809"
],
"links": [
{
"href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/drivers/agent_ipmitool",
"rel": "bookmark"
}
],
"name": "agent_ipmitool",
"properties": [
{
"href":
"http://127.0.0.1:6385/v1/drivers/agent_ipmitool/properties",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/drivers/agent_ipmitool/properties",
"rel": "bookmark"
}
]
}
class TestDriver(testtools.TestCase):
def test_basic(self):
sot = driver.Driver()
self.assertIsNone(sot.resource_key)
self.assertEqual('drivers', sot.resources_key)
self.assertEqual('/drivers', sot.base_path)
self.assertEqual('baremetal', sot.service.service_type)
self.assertFalse(sot.allow_create)
self.assertTrue(sot.allow_get)
self.assertFalse(sot.allow_update)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_instantiate(self):
sot = driver.Driver(**FAKE)
self.assertEqual(FAKE['name'], sot.id)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['hosts'], sot.hosts)
self.assertEqual(FAKE['links'], sot.links)
self.assertEqual(FAKE['properties'], sot.properties)