| 1 |
# Copyright 2013 Mirantis Inc. |
| 2 |
# Copyright 2014 Blue Box Group, Inc. |
| 3 |
# All Rights Reserved |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 |
# not use this file except in compliance with the License. You may obtain |
| 7 |
# a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 |
# License for the specific language governing permissions and limitations |
| 15 |
# under the License. |
| 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, is_create=True): |
| 23 |
parser.add_argument( |
| 24 |
'--delay', |
| 25 |
required=is_create, |
| 26 |
help=_('The time in seconds between sending probes to members.')) |
| 27 |
parser.add_argument( |
| 28 |
'--name', |
| 29 |
help=_('Name of the health monitor.')) |
| 30 |
parser.add_argument( |
| 31 |
'--timeout', |
| 32 |
required=is_create, |
| 33 |
help=_('Maximum number of seconds for a monitor to wait for a ' |
| 34 |
'connection to be established before it times out. The ' |
| 35 |
'value must be less than the delay value.')) |
| 36 |
parser.add_argument( |
| 37 |
'--http-method', |
| 38 |
type=utils.convert_to_uppercase, |
| 39 |
help=_('The HTTP method used for requests by the monitor of type ' |
| 40 |
'HTTP.')) |
| 41 |
parser.add_argument( |
| 42 |
'--url-path', |
| 43 |
help=_('The HTTP path used in the HTTP request used by the monitor ' |
| 44 |
'to test a member health. This must be a string ' |
| 45 |
'beginning with a / (forward slash).')) |
| 46 |
parser.add_argument( |
| 47 |
'--max-retries', |
| 48 |
required=is_create, |
| 49 |
help=_('Number of permissible connection failures before changing ' |
| 50 |
'the member status to INACTIVE. [1..10].')) |
| 51 |
parser.add_argument( |
| 52 |
'--expected-codes', |
| 53 |
help=_('The list of HTTP status codes expected in ' |
| 54 |
'response from the member to declare it healthy. This ' |
| 55 |
'attribute can contain one value, ' |
| 56 |
'or a list of values separated by comma, ' |
| 57 |
'or a range of values (e.g. "200-299"). If this attribute ' |
| 58 |
'is not specified, it defaults to "200".')) |
| 59 |
|
| 60 |
|
| 61 |
def _parse_common_args(body, parsed_args): |
| 62 |
neutronV20.update_dict(parsed_args, body, |
| 63 |
['expected_codes', 'http_method', 'url_path', |
| 64 |
'timeout', 'name', 'delay', 'max_retries']) |
| 65 |
|
| 66 |
|
| 67 |
class ListHealthMonitor(neutronV20.ListCommand): |
| 68 |
"""LBaaS v2 List healthmonitors that belong to a given tenant.""" |
| 69 |
|
| 70 |
resource = 'healthmonitor' |
| 71 |
shadow_resource = 'lbaas_healthmonitor' |
| 72 |
list_columns = ['id', 'name', 'type', 'admin_state_up'] |
| 73 |
pagination_support = True |
| 74 |
sorting_support = True |
| 75 |
|
| 76 |
|
| 77 |
class ShowHealthMonitor(neutronV20.ShowCommand): |
| 78 |
"""LBaaS v2 Show information of a given healthmonitor.""" |
| 79 |
|
| 80 |
resource = 'healthmonitor' |
| 81 |
shadow_resource = 'lbaas_healthmonitor' |
| 82 |
|
| 83 |
|
| 84 |
class CreateHealthMonitor(neutronV20.CreateCommand): |
| 85 |
"""LBaaS v2 Create a healthmonitor.""" |
| 86 |
|
| 87 |
resource = 'healthmonitor' |
| 88 |
shadow_resource = 'lbaas_healthmonitor' |
| 89 |
|
| 90 |
def add_known_arguments(self, parser): |
| 91 |
_add_common_args(parser) |
| 92 |
parser.add_argument( |
| 93 |
'--admin-state-down', |
| 94 |
dest='admin_state', action='store_false', |
| 95 |
help=_('Set admin state up to false.')) |
| 96 |
parser.add_argument( |
| 97 |
'--type', |
| 98 |
required=True, choices=['PING', 'TCP', 'HTTP', 'HTTPS'], |
| 99 |
help=_('One of the predefined health monitor types.')) |
| 100 |
parser.add_argument( |
| 101 |
'--pool', required=True, |
| 102 |
help=_('ID or name of the pool that this healthmonitor will ' |
| 103 |
'monitor.')) |
| 104 |
|
| 105 |
def args2body(self, parsed_args): |
| 106 |
pool_id = neutronV20.find_resourceid_by_name_or_id( |
| 107 |
self.get_client(), 'pool', parsed_args.pool, |
| 108 |
cmd_resource='lbaas_pool') |
| 109 |
body = {'admin_state_up': parsed_args.admin_state, |
| 110 |
'type': parsed_args.type, |
| 111 |
'pool_id': pool_id} |
| 112 |
neutronV20.update_dict(parsed_args, body, |
| 113 |
['tenant_id']) |
| 114 |
_parse_common_args(body, parsed_args) |
| 115 |
return {self.resource: body} |
| 116 |
|
| 117 |
|
| 118 |
class UpdateHealthMonitor(neutronV20.UpdateCommand): |
| 119 |
"""LBaaS v2 Update a given healthmonitor.""" |
| 120 |
|
| 121 |
resource = 'healthmonitor' |
| 122 |
shadow_resource = 'lbaas_healthmonitor' |
| 123 |
|
| 124 |
def add_known_arguments(self, parser): |
| 125 |
_add_common_args(parser, is_create=False) |
| 126 |
utils.add_boolean_argument( |
| 127 |
parser, '--admin-state-up', |
| 128 |
help=_('Update the administrative state of ' |
| 129 |
'the health monitor (True meaning "Up").')) |
| 130 |
|
| 131 |
def args2body(self, parsed_args): |
| 132 |
body = {} |
| 133 |
_parse_common_args(body, parsed_args) |
| 134 |
neutronV20.update_dict(parsed_args, body, |
| 135 |
['admin_state_up']) |
| 136 |
return {self.resource: body} |
| 137 |
|
| 138 |
|
| 139 |
class DeleteHealthMonitor(neutronV20.DeleteCommand): |
| 140 |
"""LBaaS v2 Delete a given healthmonitor.""" |
| 141 |
|
| 142 |
resource = 'healthmonitor' |
| 143 |
shadow_resource = 'lbaas_healthmonitor' |