Debian Codegraph @

neutronclient/neutron/v2_0/fw/firewall.py

raw
1 # Copyright 2013 Big Switch Networks
2 # All Rights Reserved
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15 #
16 from neutronclient._i18n import _
17 from neutronclient.common import utils
18 from neutronclient.neutron import v2_0 as neutronv20
19
20
21 def add_common_args(parser):
22 parser.add_argument(
23 '--name',
24 help=_('Name for the firewall.'))
25 parser.add_argument(
26 '--description',
27 help=_('Description for the firewall.'))
28 router = parser.add_mutually_exclusive_group()
29 router.add_argument(
30 '--router',
31 dest='routers',
32 metavar='ROUTER',
33 action='append',
34 help=_('ID or name of the router associated with the firewall '
35 '(requires FWaaS router insertion extension to be enabled). '
36 'This option can be repeated.'))
37 router.add_argument(
38 '--no-routers',
39 action='store_true',
40 help=_('Associate no routers with the firewall (requires FWaaS '
41 'router insertion extension).'))
42
43
44 def parse_common_args(client, parsed_args):
45 body = {}
46 if parsed_args.policy:
47 body['firewall_policy_id'] = neutronv20.find_resourceid_by_name_or_id(
48 client, 'firewall_policy',
49 parsed_args.policy)
50
51 if parsed_args.routers:
52 body['router_ids'] = [
53 neutronv20.find_resourceid_by_name_or_id(client, 'router', r)
54 for r in parsed_args.routers]
55 elif parsed_args.no_routers:
56 body['router_ids'] = []
57
58 neutronv20.update_dict(parsed_args, body,
59 ['name', 'description'])
60 return body
61
62
63 class ListFirewall(neutronv20.ListCommand):
64 """List firewalls that belong to a given tenant."""
65
66 resource = 'firewall'
67 list_columns = ['id', 'name', 'firewall_policy_id']
68 _formatters = {}
69 pagination_support = True
70 sorting_support = True
71
72
73 class ShowFirewall(neutronv20.ShowCommand):
74 """Show information of a given firewall."""
75
76 resource = 'firewall'
77
78
79 class CreateFirewall(neutronv20.CreateCommand):
80 """Create a firewall."""
81
82 resource = 'firewall'
83
84 def add_known_arguments(self, parser):
85 add_common_args(parser)
86 parser.add_argument(
87 'policy', metavar='POLICY',
88 help=_('ID or name of the firewall policy '
89 'associated to this firewall.'))
90 parser.add_argument(
91 '--admin-state-down',
92 dest='admin_state',
93 action='store_false',
94 help=_('Set admin state up to false.'))
95
96 def args2body(self, parsed_args):
97 body = parse_common_args(self.get_client(), parsed_args)
98 neutronv20.update_dict(parsed_args, body, ['tenant_id'])
99 body['admin_state_up'] = parsed_args.admin_state
100 return {self.resource: body}
101
102
103 class UpdateFirewall(neutronv20.UpdateCommand):
104 """Update a given firewall."""
105
106 resource = 'firewall'
107
108 def add_known_arguments(self, parser):
109 add_common_args(parser)
110 parser.add_argument(
111 '--policy', metavar='POLICY',
112 help=_('ID or name of the firewall policy '
113 'associated to this firewall.'))
114 utils.add_boolean_argument(
115 parser, '--admin-state-up', dest='admin_state_up',
116 help=_('Update the admin state for the firewall '
117 '(True means UP).'))
118
119 def args2body(self, parsed_args):
120 body = parse_common_args(self.get_client(), parsed_args)
121 neutronv20.update_dict(parsed_args, body, ['admin_state_up'])
122 return {self.resource: body}
123
124
125 class DeleteFirewall(neutronv20.DeleteCommand):
126 """Delete a given firewall."""
127
128 resource = 'firewall'