Skip to content

Commit 0f83add

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Port resource for bare-metal service"
2 parents 795eb01 + cc5c610 commit 0f83add

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

openstack/bare_metal/v1/port.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 Port(resource.Resource):
18+
19+
resources_key = 'ports'
20+
base_path = '/ports'
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+
'fields'
33+
)
34+
35+
#: The physical hardware address of the network port, typically the
36+
#: hardware MAC address.
37+
address = resource.Body('address')
38+
#: Timestamp at which the port 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')
42+
#: The UUID of the port
43+
id = resource.Body('uuid', alternate_id=True)
44+
#: Internal metadata set and stored by the port. This field is read-only.
45+
#: Added in API microversion 1.18.
46+
internal_info = resource.Body('internal_info')
47+
#: Whether PXE is enabled on the port. Added in API microversion 1.19.
48+
is_pxe_enabled = resource.Body('pxe_enabled', type=bool)
49+
#: A list of relative links, including the self and bookmark links.
50+
links = resource.Body('links', type=list)
51+
#: The port bindig profile. If specified, must contain ``switch_id`` and
52+
#: ``port_id`` fields. ``switch_info`` field is an optional string field
53+
#: to be used to store vendor specific information. Added in API
54+
#: microversion 1.19.
55+
local_link_connection = resource.Body('local_link_connection')
56+
#: The UUID of node this port belongs to
57+
node_id = resource.Body('node_uuid')
58+
#: The UUID of PortGroup this port belongs to. Added in API microversion
59+
#: 1.23.
60+
port_group_id = resource.Body('portgroup_uuid')
61+
#: Timestamp at which the port was last updated.
62+
updated_at = resource.Body('updated_at')
63+
64+
65+
class PortDetail(Port):
66+
67+
base_path = '/ports/detail'
68+
69+
# capabilities
70+
allow_create = False
71+
allow_get = False
72+
allow_update = False
73+
allow_delete = False
74+
allow_list = True
75+
76+
_query_mapping = resource.QueryParameters(
77+
'address', 'fields', 'node', 'portgroup',
78+
node_id='node_uuid',
79+
)
80+
81+
#: The UUID of the port
82+
id = resource.Body('uuid', alternate_id=True)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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
16+
17+
FAKE = {
18+
"address": "11:11:11:11:11:11",
19+
"created_at": "2016-08-18T22:28:49.946416+00:00",
20+
"extra": {},
21+
"internal_info": {},
22+
"links": [
23+
{
24+
"href": "http://127.0.0.1:6385/v1/ports/<PORT_ID>",
25+
"rel": "self"
26+
},
27+
{
28+
"href": "http://127.0.0.1:6385/ports/<PORT_ID>",
29+
"rel": "bookmark"
30+
}
31+
],
32+
"local_link_connection": {
33+
"port_id": "Ethernet3/1",
34+
"switch_id": "0a:1b:2c:3d:4e:5f",
35+
"switch_info": "switch1"
36+
},
37+
"node_uuid": "6d85703a-565d-469a-96ce-30b6de53079d",
38+
"portgroup_uuid": "e43c722c-248e-4c6e-8ce8-0d8ff129387a",
39+
"pxe_enabled": True,
40+
"updated_at": None,
41+
"uuid": "d2b30520-907d-46c8-bfee-c5586e6fb3a1"
42+
}
43+
44+
45+
class TestPort(testtools.TestCase):
46+
47+
def test_basic(self):
48+
sot = port.Port()
49+
self.assertIsNone(sot.resource_key)
50+
self.assertEqual('ports', sot.resources_key)
51+
self.assertEqual('/ports', sot.base_path)
52+
self.assertEqual('baremetal', sot.service.service_type)
53+
self.assertTrue(sot.allow_create)
54+
self.assertTrue(sot.allow_get)
55+
self.assertTrue(sot.allow_update)
56+
self.assertTrue(sot.allow_delete)
57+
self.assertTrue(sot.allow_list)
58+
self.assertTrue(sot.patch_update)
59+
60+
def test_instantiate(self):
61+
sot = port.PortDetail(**FAKE)
62+
self.assertEqual(FAKE['uuid'], sot.id)
63+
self.assertEqual(FAKE['address'], sot.address)
64+
self.assertEqual(FAKE['created_at'], sot.created_at)
65+
self.assertEqual(FAKE['extra'], sot.extra)
66+
self.assertEqual(FAKE['internal_info'], sot.internal_info)
67+
self.assertEqual(FAKE['links'], sot.links)
68+
self.assertEqual(FAKE['local_link_connection'],
69+
sot.local_link_connection)
70+
self.assertEqual(FAKE['node_uuid'], sot.node_id)
71+
self.assertEqual(FAKE['portgroup_uuid'], sot.port_group_id)
72+
self.assertEqual(FAKE['pxe_enabled'], sot.is_pxe_enabled)
73+
self.assertEqual(FAKE['updated_at'], sot.updated_at)
74+
75+
76+
class TestPortDetail(testtools.TestCase):
77+
78+
def test_basic(self):
79+
sot = port.PortDetail()
80+
self.assertIsNone(sot.resource_key)
81+
self.assertEqual('ports', sot.resources_key)
82+
self.assertEqual('/ports/detail', sot.base_path)
83+
self.assertEqual('baremetal', sot.service.service_type)
84+
self.assertFalse(sot.allow_create)
85+
self.assertFalse(sot.allow_get)
86+
self.assertFalse(sot.allow_update)
87+
self.assertFalse(sot.allow_delete)
88+
self.assertTrue(sot.allow_list)
89+
90+
def test_instantiate(self):
91+
sot = port.PortDetail(**FAKE)
92+
self.assertEqual(FAKE['uuid'], sot.id)
93+
self.assertEqual(FAKE['address'], sot.address)
94+
self.assertEqual(FAKE['created_at'], sot.created_at)
95+
self.assertEqual(FAKE['extra'], sot.extra)
96+
self.assertEqual(FAKE['internal_info'], sot.internal_info)
97+
self.assertEqual(FAKE['links'], sot.links)
98+
self.assertEqual(FAKE['local_link_connection'],
99+
sot.local_link_connection)
100+
self.assertEqual(FAKE['node_uuid'], sot.node_id)
101+
self.assertEqual(FAKE['portgroup_uuid'], sot.port_group_id)
102+
self.assertEqual(FAKE['pxe_enabled'], sot.is_pxe_enabled)
103+
self.assertEqual(FAKE['updated_at'], sot.updated_at)

0 commit comments

Comments
 (0)