Skip to content

Commit 36c92d0

Browse files
committed
PortGroup resource for bare-metal service
Change-Id: I60962f4f9f5fbf6d7579b1cb4808cdd84549378c
1 parent 28922b3 commit 36c92d0

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 PortGroup(resource.Resource):
18+
19+
resources_key = 'portgroups'
20+
base_path = '/portgroups'
21+
service = bare_metal_service.BareMetalService()
22+
23+
# capabilities
24+
allow_create = True
25+
allow_get = True
26+
allow_update = True
27+
allow_delete = True
28+
allow_list = True
29+
patch_update = True
30+
31+
_query_mapping = resource.QueryParameters(
32+
'node', 'address', 'fields',
33+
)
34+
35+
#: The physical hardware address of the portgroup, typically the hardware
36+
#: MAC address. Added in API microversion 1.23.
37+
address = resource.Body('address')
38+
#: Timestamp at which the portgroup was created.
39+
created_at = resource.Body('created_at')
40+
#: A set of one or more arbitrary metadata key and value pairs.
41+
extra = resource.Body('extra', type=dict)
42+
#: The name of the portgroup
43+
name = resource.Body('name')
44+
#: The UUID for the portgroup
45+
id = resource.Body('uuid', alternate_id=True)
46+
#: Internal metadaa set and stored by the portgroup.
47+
internal_info = resource.Body('internal_info')
48+
#: Whether ports that are members of this portgroup can be used as
49+
#: standalone ports. Added in API microversion 1.23.
50+
is_standalone_ports_supported = resource.Body('standalone_ports_supported',
51+
type=bool)
52+
#: A list of relative links, including the self and bookmark links.
53+
links = resource.Body('links', type=list)
54+
#: UUID of the node this portgroup belongs to.
55+
node_id = resource.Body('node_uuid')
56+
#: A list of links to the collection of ports belonging to this portgroup.
57+
#: Added in API microversion 1.24.
58+
ports = resource.Body('ports')
59+
#: Timestamp at which the portgroup was last updated.
60+
updated_at = resource.Body('updated_at')
61+
62+
63+
class PortGroupDetail(PortGroup):
64+
65+
base_path = '/portgroups/detail'
66+
67+
allow_create = False
68+
allow_get = False
69+
allow_update = False
70+
allow_delete = False
71+
allow_list = True
72+
73+
_query_mapping = resource.QueryParameters(
74+
'node', 'address',
75+
)
76+
77+
#: The UUID for the portgroup
78+
id = resource.Body('uuid', alternate_id=True)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 port_group
16+
17+
FAKE = {
18+
"address": "11:11:11:11:11:11",
19+
"created_at": "2016-08-18T22:28:48.165105+00:00",
20+
"extra": {},
21+
"internal_info": {},
22+
"links": [
23+
{
24+
"href": "http://127.0.0.1:6385/v1/portgroups/<PG_ID>",
25+
"rel": "self"
26+
},
27+
{
28+
"href": "http://127.0.0.1:6385/portgroups/<PG_ID>",
29+
"rel": "bookmark"
30+
}
31+
],
32+
"name": "test_portgroup",
33+
"node_uuid": "6d85703a-565d-469a-96ce-30b6de53079d",
34+
"ports": [
35+
{
36+
"href": "http://127.0.0.1:6385/v1/portgroups/<PG_ID>/ports",
37+
"rel": "self"
38+
},
39+
{
40+
"href": "http://127.0.0.1:6385/portgroups/<PG_ID>/ports",
41+
"rel": "bookmark"
42+
}
43+
],
44+
"standalone_ports_supported": True,
45+
"updated_at": None,
46+
"uuid": "e43c722c-248e-4c6e-8ce8-0d8ff129387a",
47+
}
48+
49+
50+
class TestPortGroup(testtools.TestCase):
51+
52+
def test_basic(self):
53+
sot = port_group.PortGroup()
54+
self.assertIsNone(sot.resource_key)
55+
self.assertEqual('portgroups', sot.resources_key)
56+
self.assertEqual('/portgroups', sot.base_path)
57+
self.assertEqual('baremetal', sot.service.service_type)
58+
self.assertTrue(sot.allow_create)
59+
self.assertTrue(sot.allow_get)
60+
self.assertTrue(sot.allow_update)
61+
self.assertTrue(sot.allow_delete)
62+
self.assertTrue(sot.allow_list)
63+
self.assertTrue(sot.patch_update)
64+
65+
def test_instantiate(self):
66+
sot = port_group.PortGroup(**FAKE)
67+
self.assertEqual(FAKE['uuid'], sot.id)
68+
self.assertEqual(FAKE['address'], sot.address)
69+
self.assertEqual(FAKE['created_at'], sot.created_at)
70+
self.assertEqual(FAKE['extra'], sot.extra)
71+
self.assertEqual(FAKE['internal_info'], sot.internal_info)
72+
self.assertEqual(FAKE['links'], sot.links)
73+
self.assertEqual(FAKE['name'], sot.name)
74+
self.assertEqual(FAKE['node_uuid'], sot.node_id)
75+
self.assertEqual(FAKE['ports'], sot.ports)
76+
self.assertEqual(FAKE['standalone_ports_supported'],
77+
sot.is_standalone_ports_supported)
78+
self.assertEqual(FAKE['updated_at'], sot.updated_at)
79+
80+
81+
class TestPortGroupDetail(testtools.TestCase):
82+
83+
def test_basic(self):
84+
sot = port_group.PortGroupDetail()
85+
self.assertIsNone(sot.resource_key)
86+
self.assertEqual('portgroups', sot.resources_key)
87+
self.assertEqual('/portgroups/detail', sot.base_path)
88+
self.assertEqual('baremetal', sot.service.service_type)
89+
self.assertFalse(sot.allow_create)
90+
self.assertFalse(sot.allow_get)
91+
self.assertFalse(sot.allow_update)
92+
self.assertFalse(sot.allow_delete)
93+
self.assertTrue(sot.allow_list)
94+
95+
def test_instantiate(self):
96+
sot = port_group.PortGroupDetail(**FAKE)
97+
self.assertEqual(FAKE['uuid'], sot.id)
98+
self.assertEqual(FAKE['address'], sot.address)
99+
self.assertEqual(FAKE['created_at'], sot.created_at)
100+
self.assertEqual(FAKE['extra'], sot.extra)
101+
self.assertEqual(FAKE['internal_info'], sot.internal_info)
102+
self.assertEqual(FAKE['links'], sot.links)
103+
self.assertEqual(FAKE['name'], sot.name)
104+
self.assertEqual(FAKE['node_uuid'], sot.node_id)
105+
self.assertEqual(FAKE['ports'], sot.ports)
106+
self.assertEqual(FAKE['standalone_ports_supported'],
107+
sot.is_standalone_ports_supported)
108+
self.assertEqual(FAKE['updated_at'], sot.updated_at)

0 commit comments

Comments
 (0)