yakumo.neutron.v2.lb.pool

Package yakumo :: Package neutron :: Package v2 :: Package lb :: Module pool |
[hide private]
[frames] | no frames]

# Source Code for Module yakumo.neutron.v2.lb.pool

      1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>.
      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  Resource class and its manager for LB Pools in Networking V2 API
     18  """
     19
     20  from yakumo import base
     21  from yakumo.constant import UNDEF
     22  from yakumo import mapper
     23  from yakumo import utils
     24  from . import member
     25  from . import vip
     26
     27
     28  ATTRIBUTE_MAPPING = [
     29      ('id', 'id', mapper.Noop),
     30      ('name', 'name', mapper.Noop),
     31      ('description', 'description', mapper.Noop),
     32      ('lb_method', 'lb_method', mapper.Noop),
     33      ('protocol', 'protocol', mapper.Noop),
     34      ('subnet', 'subnet_id', mapper.Resource('neutron.subnet')),
     35      ('project', 'tenant_id', mapper.Resource('project')),
     36      ('health_monitors', 'health_monitors',
     37       mapper.List(mapper.Resource('neutron.lb.health_monitor'))),
     38      ('is_enabled', 'admin_state_up', mapper.Noop),
     39      ('status', 'status', mapper.Noop),
     40  ]
     41
     42
     43 -class Resource(base.Resource):
     44      """Resource class for LB Pools in Networking V2 API"""
     45
     46      _sub_manager_list = {
     47          'member': member.Manager,
     48          'vip': vip.Manager
     49      }
     50
     51 -    def update(self, name=UNDEF, lb_method=UNDEF):
     52          """
     53          Update properties of a load balancer pool
     54
     55          @keyword name: Pool name (str)
     56          @type name: Pool name (str)
     57          @keyword lb_method: Load balance method (str)
     58          ('ROUND_ROBIN', 'LEAST_CONNECTIONS' or 'SOURCE_IP')
     59          @type lb_method: Load balance method (str)
     60          @rtype: None
     61          """
     62          super(Resource, self).update(name=name, lb_method=lb_method)
     63
     64 -    def add_health_monitor(self, health_monitor=None):
     65          """
     66          Add a health monitor to a pool
     67
     68          @keyword health_monitor: Health monitor
     69          @type health_monitor: yakumo.neutron.v2.lb.health_monitor.Resource
     70          @rtype: None
     71          """
     72          self._http.post(self._url_resource_path, "health_monitors",
     73                          data=dict(health_monitor=health_monitor.id))
     74
     75 -    def remove_health_monitor(self, health_monitor=None):
     76          """
     77          Remove a health monitor from a pool
     78
     79          @keyword health_monitor: Health monitor
     80          @type health_monitor: yakumo.neutron.v2.lb.health_monitor.Resource
     81          @rtype: None
     82          """
     83          self._http.delete(self._url_resource_path, "health_monitors",
     84                            health_monitor.id)
     85
     86
     87 -class Manager(base.Manager):
     88      """Manager class for LB Pools in Networking V2 API"""
     89
     90      resource_class = Resource
     91      service_type = 'network'
     92      _attr_mapping = ATTRIBUTE_MAPPING
     93      _json_resource_key = 'pool'
     94      _json_resources_key = 'pools'
     95      _url_resource_path = '/v2.0/lb/pools'
     96
     97 -    def create(self, name=UNDEF, description=UNDEF, lb_method=UNDEF,
     98                 protocol=UNDEF, subnet=UNDEF, is_enabled=UNDEF):
     99          """
    100          Create a load balancer pool
    101
    102          @keyword name: Pool name
    103          @type name: str
    104          @keyword description: Description
    105          @type description: str
    106          @keyword lb_method: Load balancing method
    107          ('ROUND_ROBIN', 'LEAST_CONNECTIONS' or 'SOURCE_IP')
    108          @type lb_method: str
    109          @keyword protocol: 'TCP', 'HTTP' or 'HTTPS'
    110          @type protocol: str
    111          @keyword subnet: Subnet
    112          @type subnet: yakumo.neutron.v2.subnet.Resource
    113          @keyword is_enabled: Whether the pool is enabled
    114          @type is_enabled: bool
    115          @return: Created pool
    116          @rtype: yakumo.neutron.v2.lb.pool.Resource
    117          """
    118          return super(Manager, self).create(name=name,
    119                                             description=description,
    120                                             lb_method=lb_method,
    121                                             protocol=protocol,
    122                                             subnet=subnet,
    123                                             is_enabled=is_enabled)
    124