Skip to content

Commit 538f826

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Sample thin interface"
2 parents 10c0074 + a073359 commit 538f826

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

examples/thin.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+
"""
14+
Example Connection Command
15+
16+
Make sure you can authenticate before running this command.
17+
18+
For example:
19+
python -m examples.thin
20+
"""
21+
22+
import sys
23+
24+
from examples import common
25+
from examples import connection
26+
from openstack.network.v2 import thin
27+
28+
29+
def run_thin(opts):
30+
session = connection.make_connection(opts).session
31+
request = thin.Thin()
32+
for objay in request.list_networks(session):
33+
print(objay['id'])
34+
return
35+
36+
37+
if __name__ == "__main__":
38+
opts = common.setup()
39+
sys.exit(common.main(opts, run_thin))

openstack/network/v2/thin.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
"""Thin interface to network objects.
14+
15+
This class provides a meaningful thin interface to network objects. The
16+
interface does not create resource objects, it just returns dictionairies.
17+
Except in special cases, the signatures of the methods are as follows:
18+
19+
create_*(session, attrs, r_id=None, path_args=None)
20+
delete_*(session, r_id, path_args=None)
21+
find_*(session, name_or_id, path_args=None, id_only=True)
22+
get_*(session, r_id, path_args=None, include_headers=False)
23+
head_*(session, r_id, path_args=None)
24+
list_*(session, limit=None, marker=None, path_args=None, **params)
25+
update_*(session, r_id, attrs, path_args=None)
26+
27+
Examples
28+
--------
29+
30+
Find a router and update the administrative state.
31+
32+
from openstack.network.v2 import thin
33+
requests = thin.Thin()
34+
my_router = requests.find_router(session, 'awesome'):
35+
my_router['admin_state_up'] = False
36+
requests.update_router(session, my_router['id], my_router)
37+
38+
"""
39+
40+
from openstack.network.v2 import floatingip
41+
from openstack.network.v2 import network
42+
from openstack.network.v2 import port
43+
from openstack.network.v2 import router
44+
from openstack.network.v2 import security_group as group
45+
from openstack.network.v2 import security_group_rule as rule
46+
from openstack.network.v2 import subnet
47+
48+
49+
class Thin(object):
50+
51+
create_ip = floatingip.FloatingIP.create_by_id
52+
delete_ip = floatingip.FloatingIP.delete_by_id
53+
find_ip = floatingip.FloatingIP.find
54+
get_ip = floatingip.FloatingIP.get_data_by_id
55+
list_ips = floatingip.FloatingIP.list
56+
update_ip = floatingip.FloatingIP.update_by_id
57+
58+
create_network = network.Network.create_by_id
59+
delete_network = network.Network.delete_by_id
60+
find_network = network.Network.find
61+
get_network = network.Network.get_data_by_id
62+
list_networks = network.Network.list
63+
update_network = network.Network.update_by_id
64+
65+
create_port = port.Port.create_by_id
66+
delete_port = port.Port.delete_by_id
67+
find_port = port.Port.find
68+
get_port = port.Port.get_data_by_id
69+
list_ports = port.Port.list
70+
update_port = port.Port.update_by_id
71+
72+
create_router = router.Router.create_by_id
73+
delete_router = router.Router.delete_by_id
74+
find_router = router.Router.find
75+
get_router = router.Router.get_data_by_id
76+
list_routers = router.Router.list
77+
update_router = router.Router.update_by_id
78+
79+
create_security_group = group.SecurityGroup.create_by_id
80+
delete_security_group = group.SecurityGroup.delete_by_id
81+
find_security_group = group.SecurityGroup.find
82+
get_security_group = group.SecurityGroup.get_data_by_id
83+
list_security_groups = group.SecurityGroup.list
84+
update_security_group = group.SecurityGroup.update_by_id
85+
86+
create_security_group_rule = rule.SecurityGroupRule.create_by_id
87+
delete_security_group_rule = rule.SecurityGroupRule.delete_by_id
88+
find_security_group_rule = rule.SecurityGroupRule.find
89+
get_security_group_rule = rule.SecurityGroupRule.get_data_by_id
90+
list_security_group_rules = rule.SecurityGroupRule.list
91+
update_security_group_rule = rule.SecurityGroupRule.update_by_id
92+
93+
create_subnet = subnet.Subnet.create_by_id
94+
delete_subnet = subnet.Subnet.delete_by_id
95+
find_subnet = subnet.Subnet.find
96+
get_subnet = subnet.Subnet.get_data_by_id
97+
list_subnets = subnet.Subnet.list
98+
update_subnet = subnet.Subnet.update_by_id

0 commit comments

Comments
 (0)