Skip to content

Commit ca42615

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Driver resource for bare-metal service"
2 parents c27396d + acb94cf commit ca42615

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

openstack/bare_metal/v1/driver.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack.bare_metal import bare_metal_service
14+
from openstack import resource2 as resource
15+
16+
17+
class Driver(resource.Resource):
18+
19+
resources_key = 'drivers'
20+
base_path = '/drivers'
21+
service = bare_metal_service.BareMetalService()
22+
23+
# capabilities
24+
allow_create = False
25+
allow_get = True
26+
allow_update = False
27+
allow_delete = False
28+
allow_list = True
29+
30+
# NOTE: Query mapping?
31+
32+
#: The name of the driver
33+
name = resource.Body('name', alternate_id=True)
34+
#: A list of active hosts that support this driver.
35+
hosts = resource.Body('hosts', type=list)
36+
#: A list of relative links, including the self and bookmark links.
37+
links = resource.Body('links', type=list)
38+
#: A list of links to driver properties.
39+
properties = resource.Body('properties', type=list)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import testtools
14+
15+
from openstack.bare_metal.v1 import driver
16+
17+
FAKE = {
18+
"hosts": [
19+
"897ab1dad809"
20+
],
21+
"links": [
22+
{
23+
"href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool",
24+
"rel": "self"
25+
},
26+
{
27+
"href": "http://127.0.0.1:6385/drivers/agent_ipmitool",
28+
"rel": "bookmark"
29+
}
30+
],
31+
"name": "agent_ipmitool",
32+
"properties": [
33+
{
34+
"href":
35+
"http://127.0.0.1:6385/v1/drivers/agent_ipmitool/properties",
36+
"rel": "self"
37+
},
38+
{
39+
"href": "http://127.0.0.1:6385/drivers/agent_ipmitool/properties",
40+
"rel": "bookmark"
41+
}
42+
]
43+
}
44+
45+
46+
class TestDriver(testtools.TestCase):
47+
48+
def test_basic(self):
49+
sot = driver.Driver()
50+
self.assertIsNone(sot.resource_key)
51+
self.assertEqual('drivers', sot.resources_key)
52+
self.assertEqual('/drivers', sot.base_path)
53+
self.assertEqual('baremetal', sot.service.service_type)
54+
self.assertFalse(sot.allow_create)
55+
self.assertTrue(sot.allow_get)
56+
self.assertFalse(sot.allow_update)
57+
self.assertFalse(sot.allow_delete)
58+
self.assertTrue(sot.allow_list)
59+
60+
def test_instantiate(self):
61+
sot = driver.Driver(**FAKE)
62+
self.assertEqual(FAKE['name'], sot.id)
63+
self.assertEqual(FAKE['name'], sot.name)
64+
self.assertEqual(FAKE['hosts'], sot.hosts)
65+
self.assertEqual(FAKE['links'], sot.links)
66+
self.assertEqual(FAKE['properties'], sot.properties)

0 commit comments

Comments
 (0)