| 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 |
'--description', |
| 28 |
help=_('Description of the IKE policy.')) |
| 29 |
parser.add_argument( |
| 30 |
'--auth-algorithm', |
| 31 |
type=utils.convert_to_lowercase, |
| 32 |
default='sha1' if is_create else argparse.SUPPRESS, |
| 33 |
choices=['sha1', 'sha256', 'sha384', 'sha512'], |
| 34 |
help=_('Authentication algorithm, default:sha1.')) |
| 35 |
parser.add_argument( |
| 36 |
'--encryption-algorithm', |
| 37 |
default='aes-128' if is_create else argparse.SUPPRESS, |
| 38 |
type=utils.convert_to_lowercase, |
| 39 |
help=_('Encryption algorithm, default:aes-128.')) |
| 40 |
parser.add_argument( |
| 41 |
'--phase1-negotiation-mode', |
| 42 |
default='main' if is_create else argparse.SUPPRESS, |
| 43 |
choices=['main'], |
| 44 |
type=utils.convert_to_lowercase, |
| 45 |
help=_('IKE Phase1 negotiation mode, default:main.')) |
| 46 |
parser.add_argument( |
| 47 |
'--ike-version', |
| 48 |
default='v1' if is_create else argparse.SUPPRESS, |
| 49 |
choices=['v1', 'v2'], |
| 50 |
type=utils.convert_to_lowercase, |
| 51 |
help=_('IKE version for the policy, default:v1.')) |
| 52 |
parser.add_argument( |
| 53 |
'--pfs', |
| 54 |
default='group5' if is_create else argparse.SUPPRESS, |
| 55 |
type=utils.convert_to_lowercase, |
| 56 |
help=_('Perfect Forward Secrecy, default:group5.')) |
| 57 |
parser.add_argument( |
| 58 |
'--lifetime', |
| 59 |
metavar="units=UNITS,value=VALUE", |
| 60 |
type=utils.str2dict_type(optional_keys=['units', 'value']), |
| 61 |
help=vpn_utils.lifetime_help("IKE")) |
| 62 |
|
| 63 |
|
| 64 |
def parse_common_args2body(parsed_args, body): |
| 65 |
neutronv20.update_dict(parsed_args, body, |
| 66 |
['auth_algorithm', 'encryption_algorithm', |
| 67 |
'phase1_negotiation_mode', 'ike_version', |
| 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 ListIKEPolicy(neutronv20.ListCommand): |
| 76 |
"""List IKE policies that belong to a tenant.""" |
| 77 |
|
| 78 |
resource = 'ikepolicy' |
| 79 |
list_columns = ['id', 'name', 'auth_algorithm', |
| 80 |
'encryption_algorithm', 'ike_version', 'pfs'] |
| 81 |
_formatters = {} |
| 82 |
pagination_support = True |
| 83 |
sorting_support = True |
| 84 |
|
| 85 |
|
| 86 |
class ShowIKEPolicy(neutronv20.ShowCommand): |
| 87 |
"""Show information of a given IKE policy.""" |
| 88 |
|
| 89 |
resource = 'ikepolicy' |
| 90 |
help_resource = 'IKE policy' |
| 91 |
|
| 92 |
|
| 93 |
class CreateIKEPolicy(neutronv20.CreateCommand): |
| 94 |
"""Create an IKE policy.""" |
| 95 |
|
| 96 |
resource = 'ikepolicy' |
| 97 |
|
| 98 |
def add_known_arguments(self, parser): |
| 99 |
parser.add_argument( |
| 100 |
'name', metavar='NAME', |
| 101 |
help=_('Name of the IKE policy.')) |
| 102 |
add_common_args(parser) |
| 103 |
|
| 104 |
def args2body(self, parsed_args): |
| 105 |
return {'ikepolicy': parse_common_args2body(parsed_args, body={})} |
| 106 |
|
| 107 |
|
| 108 |
class UpdateIKEPolicy(neutronv20.UpdateCommand): |
| 109 |
"""Update a given IKE policy.""" |
| 110 |
|
| 111 |
resource = 'ikepolicy' |
| 112 |
help_resource = 'IKE policy' |
| 113 |
|
| 114 |
def add_known_arguments(self, parser): |
| 115 |
parser.add_argument( |
| 116 |
'--name', |
| 117 |
help=_('Updated name of the IKE policy.')) |
| 118 |
add_common_args(parser, is_create=False) |
| 119 |
|
| 120 |
def args2body(self, parsed_args): |
| 121 |
return {'ikepolicy': parse_common_args2body(parsed_args, body={})} |
| 122 |
|
| 123 |
|
| 124 |
class DeleteIKEPolicy(neutronv20.DeleteCommand): |
| 125 |
"""Delete a given IKE policy.""" |
| 126 |
|
| 127 |
resource = 'ikepolicy' |
| 128 |
help_resource = 'IKE policy' |