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

Source Code for Module yakumo.neutron.v2.lbaas.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 LBaaS 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 health_monitor 
 26   
 27   
 28  ATTRIBUTE_MAPPING = [ 
 29      ('id', 'id', mapper.Noop), 
 30      ('name', 'name', mapper.Noop), 
 31      ('description', 'description', mapper.Noop), 
 32      ('lb_algorithm', 'lb_algorithm', mapper.Noop), 
 33      ('protocol', 'protocol', mapper.Noop), 
 34      ('listeners', 'listeners', 
 35       mapper.List(mapper.Resource('neutron.lbaas.listeners'))), 
 36      ('members', 'members', 
 37       mapper.List(mapper.Resource('neutron.lbaas.member'))), 
 38      ('project', 'tenant_id', mapper.Resource('project')), 
 39      ('healthmonitor', 'healthmonitor_id', 
 40       mapper.Resource('neutron.lbaas.health_monitor')), 
 41      ('is_enabled', 'admin_state_up', mapper.Noop), 
 42  ] 
 43   
 44   
45 -class Resource(base.Resource):
46 """Resource class for LBaaS Pools in Networking V2 API""" 47 48 _sub_manager_list = { 49 'member': member.Manager, 50 'health_monitor': health_monitor.Manager 51 } 52
53 - def update(self, name=UNDEF, lb_method=UNDEF):
54 """ 55 Update a load balancer pool 56 57 @keyword name: Pool name 58 @type name: str 59 @keyword lb_method: Load balance method 60 ('ROUND_ROBIN', 'LEAST_CONNECTIONS' or 'SOURCE_IP') 61 @type lb_method: str 62 @rtype: None 63 """ 64 super(Resource, self).update(name=name, 65 description=description, 66 lb_algorithm=lb_algorithm, 67 protocol=protocol, 68 protocol_port=protocol_port, 69 listener_id=listener_id, 70 project=project, 71 health_monitor=health_monitor, 72 is_enabled=is_enabled, 73 session_persistence=session_persistence)
74
75 - def add_health_monitor(self, health_monitor=None):
76 """ 77 Add a health monitor into a pool 78 79 @keyword health_monitor: LB health monitor (required) 80 @type health_monitor: 81 yakumo.neutron.v2.lbaas.health_monitor.Resource 82 @rtype: None 83 """ 84 self._http.post(self._url_resource_path, self._id, "health_monitors", 85 data=dict(health_monitor=health_monitor.id))
86
87 - def remove_health_monitor(self, health_monitor=None):
88 """ 89 Remove a health monitor from a pool 90 91 @keyword health_monitor: LB health monitor (required) 92 @type health_monitor: 93 yakumo.neutron.v2.lbaas.health_monitor.Resource 94 @rtype: None 95 """ 96 self._http.delete(self._url_resource_path, self._id, "health_monitors", 97 health_monitor.id)
98 99
100 -class Manager(base.Manager):
101 """Manager class for LBaaS Pools in Networking V2 API""" 102 103 resource_class = Resource 104 service_type = 'network' 105 _attr_mapping = ATTRIBUTE_MAPPING 106 _json_resource_key = 'pool' 107 _json_resources_key = 'pools' 108 _url_resource_path = '/v2.0/lbaas/pools' 109
110 - def create(self, name=UNDEF, description=UNDEF, lb_algorithm=UNDEF, 111 protocol=UNDEF, protocol_port=UNDEF, listener=UNDEF, 112 project=UNDEF, health_monitor=UNDEF, is_enabled=UNDEF, 113 session_persistence=UNDEF):
114 """ 115 Create a load balancer pool 116 117 @keyword name: Pool name 118 @type name: str 119 @keyword description: Description 120 @type description: str 121 @keyword lb_algorithm: Load balance algorithm 122 ('ROUND_ROBIN', 'LEAST_CONNECTIONS' or 'SOURCE_IP') 123 @type lb_algorithm: str 124 @keyword protocol: 'TCP', 'HTTP' or 'HTTPS' 125 @type protocol: str 126 @keyword protocol_port: Port number 127 @type protocol_port: int 128 @keyword subnet: Subnet object 129 @type subnet: yakumo.neutron.v2.subnet.Resource 130 @keyword is_enabled: Whether the pool is enabled 131 @type is_enabled: bool 132 @return: Created pool 133 @rtype: yakumo.neutron.v2.lbaas.pool.Resource 134 """ 135 return super(Manager, self).create( 136 name=name, 137 description=description, 138 lb_algorithm=lb_algorithm, 139 protocol=protocol, 140 protocol_port=protocol_port, 141 listener_id=listener_id, 142 project=project, 143 health_monitor=health_monitor, 144 is_enabled=is_enabled, 145 session_persistence=session_persistence)
146