summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/tenant_networks.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/tenant_networks.py')
-rw-r--r--novaclient/v2/contrib/tenant_networks.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/tenant_networks.py b/novaclient/v2/contrib/tenant_networks.py
new file mode 100644
index 0000000..06edeb1
--- /dev/null
+++ b/novaclient/v2/contrib/tenant_networks.py
@@ -0,0 +1,82 @@
1# Copyright 2013 OpenStack Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from novaclient import base
16from novaclient.i18n import _
17from novaclient.openstack.common import cliutils
18from novaclient import utils
19
20
21class TenantNetwork(base.Resource):
22 def delete(self):
23 self.manager.delete(network=self)
24
25
26class TenantNetworkManager(base.ManagerWithFind):
27 resource_class = base.Resource
28
29 def list(self):
30 return self._list('/os-tenant-networks', 'networks')
31
32 def get(self, network):
33 return self._get('/os-tenant-networks/%s' % base.getid(network),
34 'network')
35
36 def delete(self, network):
37 self._delete('/os-tenant-networks/%s' % base.getid(network))
38
39 def create(self, label, cidr):
40 body = {'network': {'label': label, 'cidr': cidr}}
41 return self._create('/os-tenant-networks', body, 'network')
42
43
44@cliutils.arg('network_id', metavar='<network_id>', help='ID of network')
45def do_net(cs, args):
46 """
47 Show a network
48 """
49 network = cs.tenant_networks.get(args.network_id)
50 utils.print_dict(network._info)
51
52
53def do_net_list(cs, args):
54 """
55 List networks
56 """
57 networks = cs.tenant_networks.list()
58 utils.print_list(networks, ['ID', 'Label', 'CIDR'])
59
60
61@cliutils.arg(
62 'label',
63 metavar='<network_label>',
64 help=_('Network label (ex. my_new_network)'))
65@cliutils.arg(
66 'cidr',
67 metavar='<cidr>',
68 help=_('IP block to allocate from (ex. 172.16.0.0/24 or 2001:DB8::/64)'))
69def do_net_create(cs, args):
70 """
71 Create a network
72 """
73 network = cs.tenant_networks.create(args.label, args.cidr)
74 utils.print_dict(network._info)
75
76
77@cliutils.arg('network_id', metavar='<network_id>', help='ID of network')
78def do_net_delete(cs, args):
79 """
80 Delete a network
81 """
82 cs.tenant_networks.delete(args.network_id)