1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
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
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
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