Skip to content

Commit 39681f4

Browse files
committed
Simple network resource
Network resource. Seems to work for create, delete and list. Change-Id: I4b50bb2304a13f6b92433baacd02ff6e68dc4b65
1 parent 3408433 commit 39681f4

8 files changed

Lines changed: 127 additions & 0 deletions

File tree

openstack/network/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.auth import service_filter
14+
15+
16+
class NetworkService(service_filter.ServiceFilter):
17+
"""The network service."""
18+
19+
def __init__(self):
20+
"""Create an network service."""
21+
super(NetworkService, self).__init__(service_type='network')

openstack/network/v2/__init__.py

Whitespace-only changes.

openstack/network/v2/network.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.network import network_service
14+
from openstack import resource
15+
16+
17+
class Network(resource.Resource):
18+
resource_key = 'network'
19+
resources_key = 'networks'
20+
base_path = '/v2.0/networks'
21+
service = network_service.NetworkService()
22+
23+
# capabilities
24+
allow_create = True
25+
allow_retrieve = True
26+
allow_update = True
27+
allow_delete = True
28+
allow_list = True
29+
30+
# Properties
31+
admin_state_up = resource.prop('admin_state_up')
32+
name = resource.prop('name')
33+
shared = resource.prop('shared')
34+
project_id = resource.prop('tenant_id')

openstack/tests/network/__init__.py

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.network import network_service
16+
17+
18+
class TestNetworkService(testtools.TestCase):
19+
20+
def test_service(self):
21+
sot = network_service.NetworkService()
22+
self.assertEqual('network', sot.service_type)
23+
self.assertEqual('public', sot.visibility)
24+
self.assertIsNone(sot.region)
25+
self.assertIsNone(sot.service_name)

openstack/tests/network/v2/__init__.py

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.network.v2 import network
16+
17+
IDENTIFIER = 'IDENTIFIER'
18+
EXAMPLE = {
19+
'admin_state_up': '1',
20+
'id': IDENTIFIER,
21+
'name': '2',
22+
'shared': True,
23+
'tenant_id': '4',
24+
}
25+
26+
27+
class TestNetwork(testtools.TestCase):
28+
29+
def test_basic(self):
30+
sot = network.Network()
31+
self.assertEqual('network', sot.resource_key)
32+
self.assertEqual('networks', sot.resources_key)
33+
self.assertEqual('/v2.0/networks', sot.base_path)
34+
self.assertEqual('network', sot.service.service_type)
35+
self.assertTrue(sot.allow_create)
36+
self.assertTrue(sot.allow_retrieve)
37+
self.assertTrue(sot.allow_update)
38+
self.assertTrue(sot.allow_delete)
39+
self.assertTrue(sot.allow_list)
40+
41+
def test_make_it(self):
42+
sot = network.Network(EXAMPLE)
43+
self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up)
44+
self.assertEqual(IDENTIFIER, sot.id)
45+
self.assertEqual(EXAMPLE['name'], sot.name)
46+
self.assertEqual(EXAMPLE['shared'], sot.shared)
47+
self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)

0 commit comments

Comments
 (0)