| 1 |
# Copyright 2013 Mirantis 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 |
class ListVip(neutronV20.ListCommand): |
| 22 |
"""List vips that belong to a given tenant.""" |
| 23 |
|
| 24 |
resource = 'vip' |
| 25 |
list_columns = ['id', 'name', 'algorithm', 'address', 'protocol', |
| 26 |
'admin_state_up', 'status'] |
| 27 |
pagination_support = True |
| 28 |
sorting_support = True |
| 29 |
|
| 30 |
|
| 31 |
class ShowVip(neutronV20.ShowCommand): |
| 32 |
"""Show information of a given vip.""" |
| 33 |
|
| 34 |
resource = 'vip' |
| 35 |
|
| 36 |
|
| 37 |
class CreateVip(neutronV20.CreateCommand): |
| 38 |
"""Create a vip.""" |
| 39 |
|
| 40 |
resource = 'vip' |
| 41 |
|
| 42 |
def add_known_arguments(self, parser): |
| 43 |
parser.add_argument( |
| 44 |
'pool_id', metavar='POOL', |
| 45 |
help=_('ID or name of the pool to which this vip belongs.')) |
| 46 |
parser.add_argument( |
| 47 |
'--address', |
| 48 |
help=_('IP address of the vip.')) |
| 49 |
parser.add_argument( |
| 50 |
'--admin-state-down', |
| 51 |
dest='admin_state', action='store_false', |
| 52 |
help=_('Set admin state up to false.')) |
| 53 |
parser.add_argument( |
| 54 |
'--connection-limit', |
| 55 |
help=_('The maximum number of connections per second allowed for ' |
| 56 |
'the vip. Valid values: a positive integer or -1 ' |
| 57 |
'for unlimited (default).')) |
| 58 |
parser.add_argument( |
| 59 |
'--description', |
| 60 |
help=_('Description of the vip to be created.')) |
| 61 |
parser.add_argument( |
| 62 |
'--name', |
| 63 |
required=True, |
| 64 |
help=_('Name of the vip to be created.')) |
| 65 |
parser.add_argument( |
| 66 |
'--protocol-port', |
| 67 |
required=True, |
| 68 |
help=_('TCP port on which to listen for client traffic that is ' |
| 69 |
'associated with the vip address.')) |
| 70 |
parser.add_argument( |
| 71 |
'--protocol', |
| 72 |
required=True, choices=['TCP', 'HTTP', 'HTTPS'], |
| 73 |
help=_('Protocol for balancing.')) |
| 74 |
parser.add_argument( |
| 75 |
'--subnet-id', metavar='SUBNET', |
| 76 |
required=True, |
| 77 |
help=_('The subnet on which to allocate the vip address.')) |
| 78 |
|
| 79 |
def args2body(self, parsed_args): |
| 80 |
_pool_id = neutronV20.find_resourceid_by_name_or_id( |
| 81 |
self.get_client(), 'pool', parsed_args.pool_id) |
| 82 |
_subnet_id = neutronV20.find_resourceid_by_name_or_id( |
| 83 |
self.get_client(), 'subnet', parsed_args.subnet_id) |
| 84 |
|
| 85 |
body = {'pool_id': _pool_id, |
| 86 |
'admin_state_up': parsed_args.admin_state, |
| 87 |
'subnet_id': _subnet_id} |
| 88 |
neutronV20.update_dict(parsed_args, body, |
| 89 |
['address', 'connection_limit', 'description', |
| 90 |
'name', 'protocol_port', 'protocol', |
| 91 |
'tenant_id']) |
| 92 |
return {self.resource: body} |
| 93 |
|
| 94 |
|
| 95 |
class UpdateVip(neutronV20.UpdateCommand): |
| 96 |
"""Update a given vip.""" |
| 97 |
|
| 98 |
resource = 'vip' |
| 99 |
|
| 100 |
|
| 101 |
class DeleteVip(neutronV20.DeleteCommand): |
| 102 |
"""Delete a given vip.""" |
| 103 |
|
| 104 |
resource = 'vip' |