| 1 |
# (c) Copyright 2015 Cisco Systems, Inc. |
| 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 |
from neutronclient._i18n import _ |
| 18 |
from neutronclient.neutron import v2_0 as neutronv20 |
| 19 |
|
| 20 |
|
| 21 |
def add_known_endpoint_group_arguments(parser, is_create=True): |
| 22 |
parser.add_argument( |
| 23 |
'--name', |
| 24 |
help=_('Set a name for the endpoint group.')) |
| 25 |
parser.add_argument( |
| 26 |
'--description', |
| 27 |
help=_('Set a description for the endpoint group.')) |
| 28 |
if is_create: |
| 29 |
parser.add_argument( |
| 30 |
'--type', |
| 31 |
required=is_create, |
| 32 |
help=_('Type of endpoints in group (e.g. subnet, cidr, vlan).')) |
| 33 |
parser.add_argument( |
| 34 |
'--value', |
| 35 |
action='append', dest='endpoints', |
| 36 |
required=is_create, |
| 37 |
help=_('Endpoint(s) for the group. Must all be of the same type.')) |
| 38 |
|
| 39 |
|
| 40 |
class ListEndpointGroup(neutronv20.ListCommand): |
| 41 |
"""List VPN endpoint groups that belong to a given tenant.""" |
| 42 |
|
| 43 |
resource = 'endpoint_group' |
| 44 |
list_columns = ['id', 'name', 'type', 'endpoints'] |
| 45 |
_formatters = {} |
| 46 |
pagination_support = True |
| 47 |
sorting_support = True |
| 48 |
|
| 49 |
|
| 50 |
class ShowEndpointGroup(neutronv20.ShowCommand): |
| 51 |
"""Show a specific VPN endpoint group.""" |
| 52 |
|
| 53 |
resource = 'endpoint_group' |
| 54 |
|
| 55 |
|
| 56 |
class CreateEndpointGroup(neutronv20.CreateCommand): |
| 57 |
"""Create a VPN endpoint group.""" |
| 58 |
resource = 'endpoint_group' |
| 59 |
|
| 60 |
def add_known_arguments(self, parser): |
| 61 |
add_known_endpoint_group_arguments(parser) |
| 62 |
|
| 63 |
def subnet_name2id(self, endpoint): |
| 64 |
return neutronv20.find_resourceid_by_name_or_id(self.get_client(), |
| 65 |
'subnet', endpoint) |
| 66 |
|
| 67 |
def args2body(self, parsed_args): |
| 68 |
if parsed_args.type == 'subnet': |
| 69 |
endpoints = [self.subnet_name2id(ep) |
| 70 |
for ep in parsed_args.endpoints] |
| 71 |
else: |
| 72 |
endpoints = parsed_args.endpoints |
| 73 |
|
| 74 |
body = {'endpoints': endpoints} |
| 75 |
|
| 76 |
neutronv20.update_dict(parsed_args, body, |
| 77 |
['name', 'description', |
| 78 |
'tenant_id', 'type']) |
| 79 |
return {self.resource: body} |
| 80 |
|
| 81 |
|
| 82 |
class UpdateEndpointGroup(neutronv20.UpdateCommand): |
| 83 |
"""Update a given VPN endpoint group.""" |
| 84 |
|
| 85 |
resource = 'endpoint_group' |
| 86 |
|
| 87 |
def add_known_arguments(self, parser): |
| 88 |
add_known_endpoint_group_arguments(parser, is_create=False) |
| 89 |
|
| 90 |
def args2body(self, parsed_args): |
| 91 |
body = {} |
| 92 |
neutronv20.update_dict(parsed_args, body, |
| 93 |
['name', 'description']) |
| 94 |
return {self.resource: body} |
| 95 |
|
| 96 |
|
| 97 |
class DeleteEndpointGroup(neutronv20.DeleteCommand): |
| 98 |
"""Delete a given VPN endpoint group.""" |
| 99 |
|
| 100 |
resource = 'endpoint_group' |