| 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 |
from neutronclient._i18n import _ |
| 18 |
from neutronclient.common import utils |
| 19 |
from neutronclient.neutron import v2_0 as neutronv20 |
| 20 |
|
| 21 |
|
| 22 |
def add_common_args(parser): |
| 23 |
parser.add_argument( |
| 24 |
'--name', |
| 25 |
help=_('Name for the VPN service.')) |
| 26 |
parser.add_argument( |
| 27 |
'--description', |
| 28 |
help=_('Description for the VPN service.')) |
| 29 |
|
| 30 |
|
| 31 |
def common_args2body(parsed_args, body): |
| 32 |
neutronv20.update_dict(parsed_args, body, |
| 33 |
['name', 'description']) |
| 34 |
|
| 35 |
|
| 36 |
class ListVPNService(neutronv20.ListCommand): |
| 37 |
"""List VPN service configurations that belong to a given tenant.""" |
| 38 |
|
| 39 |
resource = 'vpnservice' |
| 40 |
list_columns = [ |
| 41 |
'id', 'name', 'router_id', 'status' |
| 42 |
] |
| 43 |
_formatters = {} |
| 44 |
pagination_support = True |
| 45 |
sorting_support = True |
| 46 |
|
| 47 |
|
| 48 |
class ShowVPNService(neutronv20.ShowCommand): |
| 49 |
"""Show information of a given VPN service.""" |
| 50 |
|
| 51 |
resource = 'vpnservice' |
| 52 |
help_resource = 'VPN service' |
| 53 |
|
| 54 |
|
| 55 |
class CreateVPNService(neutronv20.CreateCommand): |
| 56 |
"""Create a VPN service.""" |
| 57 |
resource = 'vpnservice' |
| 58 |
|
| 59 |
def add_known_arguments(self, parser): |
| 60 |
parser.add_argument( |
| 61 |
'--admin-state-down', |
| 62 |
dest='admin_state', action='store_false', |
| 63 |
help=_('Set admin state up to false.')) |
| 64 |
parser.add_argument( |
| 65 |
'router', metavar='ROUTER', |
| 66 |
help=_('Router unique identifier for the VPN service.')) |
| 67 |
parser.add_argument( |
| 68 |
'subnet', nargs='?', metavar='SUBNET', |
| 69 |
help=_('[DEPRECATED in Mitaka] Unique identifier for the local ' |
| 70 |
'private subnet.')) |
| 71 |
add_common_args(parser) |
| 72 |
|
| 73 |
def args2body(self, parsed_args): |
| 74 |
if parsed_args.subnet: |
| 75 |
_subnet_id = neutronv20.find_resourceid_by_name_or_id( |
| 76 |
self.get_client(), 'subnet', parsed_args.subnet) |
| 77 |
else: |
| 78 |
_subnet_id = None |
| 79 |
_router_id = neutronv20.find_resourceid_by_name_or_id( |
| 80 |
self.get_client(), 'router', |
| 81 |
parsed_args.router) |
| 82 |
|
| 83 |
body = {'subnet_id': _subnet_id, |
| 84 |
'router_id': _router_id, |
| 85 |
'admin_state_up': parsed_args.admin_state} |
| 86 |
neutronv20.update_dict(parsed_args, body, |
| 87 |
['tenant_id']) |
| 88 |
common_args2body(parsed_args, body) |
| 89 |
return {self.resource: body} |
| 90 |
|
| 91 |
|
| 92 |
class UpdateVPNService(neutronv20.UpdateCommand): |
| 93 |
"""Update a given VPN service.""" |
| 94 |
|
| 95 |
resource = 'vpnservice' |
| 96 |
help_resource = 'VPN service' |
| 97 |
|
| 98 |
def add_known_arguments(self, parser): |
| 99 |
add_common_args(parser) |
| 100 |
utils.add_boolean_argument( |
| 101 |
parser, '--admin-state-up', |
| 102 |
help=_('Update the admin state for the VPN Service.' |
| 103 |
'(True means UP)')) |
| 104 |
|
| 105 |
def args2body(self, parsed_args): |
| 106 |
body = {} |
| 107 |
common_args2body(parsed_args, body) |
| 108 |
neutronv20.update_dict(parsed_args, body, |
| 109 |
['admin_state_up']) |
| 110 |
return {self.resource: body} |
| 111 |
|
| 112 |
|
| 113 |
class DeleteVPNService(neutronv20.DeleteCommand): |
| 114 |
"""Delete a given VPN service.""" |
| 115 |
|
| 116 |
resource = 'vpnservice' |
| 117 |
help_resource = 'VPN service' |