Debian Codegraph @

neutronclient/neutron/v2_0/vpn/ipsecpolicy.py

raw
1 # (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
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
17 import argparse
18
19 from neutronclient._i18n import _
20 from neutronclient.common import utils
21 from neutronclient.neutron import v2_0 as neutronv20
22 from neutronclient.neutron.v2_0.vpn import utils as vpn_utils
23
24
25 def add_common_args(parser, is_create=True):
26 parser.add_argument(
27 '--auth-algorithm',
28 default='sha1' if is_create else argparse.SUPPRESS,
29 type=utils.convert_to_lowercase,
30 choices=['sha1', 'sha256', 'sha384', 'sha512'],
31 help=_('Authentication algorithm for IPsec policy, default:sha1.'))
32 parser.add_argument(
33 '--description',
34 help=_('Description of the IPsec policy.'))
35 parser.add_argument(
36 '--encapsulation-mode',
37 default='tunnel' if is_create else argparse.SUPPRESS,
38 choices=['tunnel', 'transport'],
39 type=utils.convert_to_lowercase,
40 help=_('Encapsulation mode for IPsec policy, default:tunnel.'))
41 parser.add_argument(
42 '--encryption-algorithm',
43 default='aes-128' if is_create else argparse.SUPPRESS,
44 type=utils.convert_to_lowercase,
45 help=_('Encryption algorithm for IPsec policy, default:aes-128.'))
46 parser.add_argument(
47 '--lifetime',
48 metavar="units=UNITS,value=VALUE",
49 type=utils.str2dict_type(optional_keys=['units', 'value']),
50 help=vpn_utils.lifetime_help("IPsec"))
51 parser.add_argument(
52 '--pfs',
53 default='group5' if is_create else argparse.SUPPRESS,
54 type=utils.convert_to_lowercase,
55 help=_('Perfect Forward Secrecy for IPsec policy, default:group5.'))
56 parser.add_argument(
57 '--transform-protocol',
58 default='esp' if is_create else argparse.SUPPRESS,
59 type=utils.convert_to_lowercase,
60 choices=['esp', 'ah', 'ah-esp'],
61 help=_('Transform protocol for IPsec policy, default:esp.'))
62
63
64 def parse_common_args2body(parsed_args, body):
65 neutronv20.update_dict(parsed_args, body,
66 ['auth_algorithm', 'encryption_algorithm',
67 'encapsulation_mode', 'transform_protocol',
68 'pfs', 'name', 'description', 'tenant_id'])
69 if parsed_args.lifetime:
70 vpn_utils.validate_lifetime_dict(parsed_args.lifetime)
71 body['lifetime'] = parsed_args.lifetime
72 return body
73
74
75 class ListIPsecPolicy(neutronv20.ListCommand):
76 """List IPsec policies that belong to a given tenant connection."""
77
78 resource = 'ipsecpolicy'
79 list_columns = ['id', 'name', 'auth_algorithm',
80 'encryption_algorithm', 'pfs']
81 _formatters = {}
82 pagination_support = True
83 sorting_support = True
84
85
86 class ShowIPsecPolicy(neutronv20.ShowCommand):
87 """Show information of a given IPsec policy."""
88
89 resource = 'ipsecpolicy'
90 help_resource = 'IPsec policy'
91
92
93 class CreateIPsecPolicy(neutronv20.CreateCommand):
94 """Create an IPsec policy."""
95
96 resource = 'ipsecpolicy'
97 help_resource = 'IPsec policy'
98
99 def add_known_arguments(self, parser):
100 parser.add_argument(
101 'name', metavar='NAME',
102 help=_('Name of the IPsec policy.'))
103 add_common_args(parser)
104
105 def args2body(self, parsed_args):
106 return {'ipsecpolicy': parse_common_args2body(parsed_args, body={})}
107
108
109 class UpdateIPsecPolicy(neutronv20.UpdateCommand):
110 """Update a given IPsec policy."""
111
112 resource = 'ipsecpolicy'
113 help_resource = 'IPsec policy'
114
115 def add_known_arguments(self, parser):
116 parser.add_argument(
117 '--name',
118 help=_('Updated name of the IPsec policy.'))
119 add_common_args(parser, is_create=False)
120
121 def args2body(self, parsed_args):
122 return {'ipsecpolicy': parse_common_args2body(parsed_args, body={})}
123
124
125 class DeleteIPsecPolicy(neutronv20.DeleteCommand):
126 """Delete a given IPsec policy."""
127
128 resource = 'ipsecpolicy'
129 help_resource = 'IPsec policy'