Skip to content

Commit ba4d997

Browse files
authored
Merge pull request #333 from djburns/master
Add new loadbalancer options to the loadbalancer object
2 parents 20a76ff + f68d0b3 commit ba4d997

7 files changed

Lines changed: 200 additions & 205 deletions

File tree

digitalocean/LoadBalancer.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class LoadBalancer(BaseAPI):
9191
Args:
9292
name (str): The Load Balancer's name
9393
region (str): The slug identifier for a DigitalOcean region
94+
size (str): The size of the load balancer. The available sizes \
95+
are "lb-small", "lb-medium", or "lb-large". Once you have \
96+
created a load balancer, you can't change its size
9497
algorithm (str, optional): The load balancing algorithm to be \
9598
used. Currently, it must be either "round_robin" or \
9699
"least_connections"
@@ -100,6 +103,11 @@ class LoadBalancer(BaseAPI):
100103
redirect_http_to_https (bool, optional): A boolean indicating \
101104
whether HTTP requests to the Load Balancer should be \
102105
redirected to HTTPS
106+
enable_proxy_protocol (bool, optional): A boolean value indicating \
107+
whether PROXY Protocol is in use
108+
enable_backend_keepalive (bool, optional): A boolean value \
109+
indicating whether HTTP keepalive connections are maintained \
110+
to target Droplets.
103111
droplet_ids (obj:`list` of `int`): A list of IDs representing \
104112
Droplets to be added to the Load Balancer (mutually \
105113
exclusive with 'tag')
@@ -112,6 +120,7 @@ class LoadBalancer(BaseAPI):
112120
* id (str): An unique identifier for a LoadBalancer
113121
* ip (str): Public IP address for a LoadBalancer
114122
* region (str): The slug identifier for a DigitalOcean region
123+
* size (str): The size of the load balancer
115124
* algorithm (str, optional): The load balancing algorithm to be \
116125
used. Currently, it must be either "round_robin" or \
117126
"least_connections"
@@ -121,6 +130,11 @@ class LoadBalancer(BaseAPI):
121130
* redirect_http_to_https (bool, optional): A boolean indicating \
122131
whether HTTP requests to the Load Balancer should be \
123132
redirected to HTTPS
133+
* enable_proxy_protocol (bool, optional): A boolean value indicating \
134+
whether PROXY Protocol is in use
135+
* enable_backend_keepalive (bool, optional): A boolean value \
136+
indicating whether HTTP keepalive connections are maintained \
137+
to target Droplets.
124138
* droplet_ids (obj:`list` of `int`): A list of IDs representing \
125139
Droplets to be added to the Load Balancer
126140
* tag (str): A string representing a DigitalOcean Droplet tag
@@ -132,11 +146,14 @@ def __init__(self, *args, **kwargs):
132146
self.id = None
133147
self.name = None
134148
self.region = None
149+
self.size = None
135150
self.algorithm = None
136151
self.forwarding_rules = []
137152
self.health_check = None
138153
self.sticky_sessions = None
139154
self.redirect_http_to_https = False
155+
self.enable_proxy_protocol = False
156+
self.enable_backend_keepalive = False
140157
self.droplet_ids = []
141158
self.tag = None
142159
self.status = None
@@ -195,6 +212,9 @@ def create(self, *args, **kwargs):
195212
Args:
196213
name (str): The Load Balancer's name
197214
region (str): The slug identifier for a DigitalOcean region
215+
size (str): The size of the load balancer. The available sizes
216+
are "lb-small", "lb-medium", or "lb-large". Once you have
217+
created a load balancer, you can't change its size
198218
algorithm (str, optional): The load balancing algorithm to be
199219
used. Currently, it must be either "round_robin" or
200220
"least_connections"
@@ -204,6 +224,11 @@ def create(self, *args, **kwargs):
204224
redirect_http_to_https (bool, optional): A boolean indicating
205225
whether HTTP requests to the Load Balancer should be
206226
redirected to HTTPS
227+
enable_proxy_protocol (bool, optional): A boolean value indicating
228+
whether PROXY Protocol is in use
229+
enable_backend_keepalive (bool, optional): A boolean value
230+
indicating whether HTTP keepalive connections are maintained
231+
to target Droplets.
207232
droplet_ids (obj:`list` of `int`): A list of IDs representing
208233
Droplets to be added to the Load Balancer (mutually
209234
exclusive with 'tag')
@@ -215,8 +240,11 @@ def create(self, *args, **kwargs):
215240
rules_dict = [rule.__dict__ for rule in self.forwarding_rules]
216241

217242
params = {'name': self.name, 'region': self.region,
243+
'size': self.size,
218244
'forwarding_rules': rules_dict,
219245
'redirect_http_to_https': self.redirect_http_to_https,
246+
'enable_proxy_protocol': self.enable_proxy_protocol,
247+
'enable_backend_keepalive': self.enable_backend_keepalive,
220248
'vpc_uuid': self.vpc_uuid}
221249

222250
if self.droplet_ids and self.tag:
@@ -239,13 +267,17 @@ def create(self, *args, **kwargs):
239267
self.id = data['load_balancer']['id']
240268
self.ip = data['load_balancer']['ip']
241269
self.algorithm = data['load_balancer']['algorithm']
270+
self.size = data['load_balancer']['size']
242271
self.health_check = HealthCheck(
243272
**data['load_balancer']['health_check'])
244273
self.sticky_sessions = StickySessions(
245274
**data['load_balancer']['sticky_sessions'])
246275
self.droplet_ids = data['load_balancer']['droplet_ids']
247276
self.status = data['load_balancer']['status']
248277
self.created_at = data['load_balancer']['created_at']
278+
self.redirect_http_to_https = data['load_balancer']['redirect_http_to_https']
279+
self.enable_proxy_protocol = data['load_balancer']['enable_proxy_protocol']
280+
self.enable_backend_keepalive = data['load_balancer']['enable_backend_keepalive']
249281
self.vpc_uuid = data['load_balancer']['vpc_uuid']
250282

251283
return self
@@ -261,6 +293,8 @@ def save(self):
261293
'region': self.region['slug'],
262294
'forwarding_rules': forwarding_rules,
263295
'redirect_http_to_https': self.redirect_http_to_https,
296+
'enable_proxy_protocol': self.enable_proxy_protocol,
297+
'enable_backend_keepalive': self.enable_backend_keepalive,
264298
'vpc_uuid': self.vpc_uuid
265299
}
266300

Lines changed: 75 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,85 @@
11
{
22
"load_balancers": [
3-
{
4-
"id": "4de2ac7b-495b-4884-9e69-1050d6793cd4",
5-
"name": "example-lb-02",
6-
"ip": "104.131.186.248",
7-
"algorithm": "round_robin",
8-
"status": "new",
9-
"created_at": "2017-02-01T22:22:58Z",
10-
"forwarding_rules": [
11-
{
12-
"entry_protocol": "http",
13-
"entry_port": 80,
14-
"target_protocol": "http",
15-
"target_port": 80,
16-
"certificate_id": "",
17-
"tls_passthrough": false
18-
},
19-
{
20-
"entry_protocol": "https",
21-
"entry_port": 444,
22-
"target_protocol": "https",
23-
"target_port": 443,
24-
"certificate_id": "",
25-
"tls_passthrough": true
26-
}
27-
],
28-
"health_check": {
29-
"protocol": "http",
30-
"port": 80,
31-
"path": "/",
32-
"check_interval_seconds": 10,
33-
"response_timeout_seconds": 5,
34-
"healthy_threshold": 5,
35-
"unhealthy_threshold": 3
36-
},
37-
"sticky_sessions": {
38-
"type": "none"
39-
},
40-
"region": {
41-
"name": "New York 3",
42-
"slug": "nyc3",
43-
"sizes": [
44-
"512mb",
45-
"1gb",
46-
"2gb",
47-
"4gb",
48-
"8gb",
49-
"16gb",
50-
"m-16gb",
51-
"32gb",
52-
"m-32gb",
53-
"48gb",
54-
"m-64gb",
55-
"64gb",
56-
"m-128gb",
57-
"m-224gb"
58-
],
59-
"features": [
60-
"private_networking",
61-
"backups",
62-
"ipv6",
63-
"metadata",
64-
"install_agent"
3+
{
4+
"id": "4de7ac8b-495b-4884-9a69-1050c6793cd6",
5+
"name": "example-lb-01",
6+
"ip": "104.131.186.241",
7+
"size": "lb-small",
8+
"algorithm": "round_robin",
9+
"status": "new",
10+
"created_at": "2017-02-01T22:22:58Z",
11+
"forwarding_rules": [
12+
{
13+
"entry_protocol": "http",
14+
"entry_port": 80,
15+
"target_protocol": "http",
16+
"target_port": 80,
17+
"certificate_id": "",
18+
"tls_passthrough": false
19+
},
20+
{
21+
"entry_protocol": "https",
22+
"entry_port": 444,
23+
"target_protocol": "https",
24+
"target_port": 443,
25+
"certificate_id": "",
26+
"tls_passthrough": true
27+
}
6528
],
66-
"available": true
67-
},
68-
"tag": "web",
69-
"droplet_ids": [
70-
3164444,
71-
3164445
72-
],
73-
"redirect_http_to_https": false,
74-
"vpc_uuid": "08187eaa-90eb-40d6-a8f0-0222b28ded72"
75-
},
76-
{
77-
"id": "4de7ac8b-495b-4884-9a69-1050c6793cd6",
78-
"name": "example-lb-01",
79-
"ip": "104.131.186.241",
80-
"algorithm": "round_robin",
81-
"status": "new",
82-
"created_at": "2017-02-01T22:22:58Z",
83-
"forwarding_rules": [
84-
{
85-
"entry_protocol": "http",
86-
"entry_port": 80,
87-
"target_protocol": "http",
88-
"target_port": 80,
89-
"certificate_id": "",
90-
"tls_passthrough": false
29+
"health_check": {
30+
"protocol": "http",
31+
"port": 80,
32+
"path": "/",
33+
"check_interval_seconds": 10,
34+
"response_timeout_seconds": 5,
35+
"healthy_threshold": 5,
36+
"unhealthy_threshold": 3
9137
},
92-
{
93-
"entry_protocol": "https",
94-
"entry_port": 444,
95-
"target_protocol": "https",
96-
"target_port": 443,
97-
"certificate_id": "",
98-
"tls_passthrough": true
99-
}
100-
],
101-
"health_check": {
102-
"protocol": "http",
103-
"port": 80,
104-
"path": "/",
105-
"check_interval_seconds": 10,
106-
"response_timeout_seconds": 5,
107-
"healthy_threshold": 5,
108-
"unhealthy_threshold": 3
109-
},
110-
"sticky_sessions": {
111-
"type": "none"
112-
},
113-
"region": {
114-
"name": "New York 3",
115-
"slug": "nyc3",
116-
"sizes": [
117-
"512mb",
118-
"1gb",
119-
"2gb",
120-
"4gb",
121-
"8gb",
122-
"16gb",
123-
"m-16gb",
124-
"32gb",
125-
"m-32gb",
126-
"48gb",
127-
"m-64gb",
128-
"64gb",
129-
"m-128gb",
130-
"m-224gb"
131-
],
132-
"features": [
133-
"private_networking",
134-
"backups",
135-
"ipv6",
136-
"metadata",
137-
"install_agent"
38+
"sticky_sessions": {
39+
"type": "none"
40+
},
41+
"region": {
42+
"name": "New York 3",
43+
"slug": "nyc3",
44+
"sizes": [
45+
"s-1vcpu-1gb",
46+
"s-1vcpu-2gb",
47+
"s-1vcpu-3gb",
48+
"s-2vcpu-2gb",
49+
"s-3vcpu-1gb",
50+
"s-2vcpu-4gb",
51+
"s-4vcpu-8gb",
52+
"s-6vcpu-16gb",
53+
"s-8vcpu-32gb",
54+
"s-12vcpu-48gb",
55+
"s-16vcpu-64gb",
56+
"s-20vcpu-96gb",
57+
"s-24vcpu-128gb",
58+
"s-32vcpu-192gb"
59+
],
60+
"features": [
61+
"private_networking",
62+
"backups",
63+
"ipv6",
64+
"metadata",
65+
"install_agent"
66+
],
67+
"available": true
68+
},
69+
"tag": "",
70+
"droplet_ids": [
71+
3164444,
72+
3164445
13873
],
139-
"available": true
140-
},
141-
"tag": "",
142-
"droplet_ids": [
143-
3164444,
144-
3164445
145-
],
146-
"redirect_http_to_https": false,
147-
"vpc_uuid": "08187eaa-90eb-40d6-a8f0-0222b28ded72"
148-
}],
74+
"redirect_http_to_https": false,
75+
"enable_proxy_protocol": false,
76+
"enable_backend_keepalive": false,
77+
"vpc_uuid": "c33931f2-a26a-4e61-b85c-4e95a2ec431b"
78+
}
79+
],
14980
"links": {
15081
},
15182
"meta": {
15283
"total": 1
15384
}
154-
}
85+
}

digitalocean/tests/data/loadbalancer/save.json

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@
4242
"name": "New York 3",
4343
"slug": "nyc3",
4444
"sizes": [
45-
"512mb",
46-
"1gb",
47-
"2gb",
48-
"4gb",
49-
"8gb",
50-
"16gb",
51-
"m-16gb",
52-
"32gb",
53-
"m-32gb",
54-
"48gb",
55-
"m-64gb",
56-
"64gb",
57-
"m-128gb",
58-
"m-224gb"
45+
"s-1vcpu-1gb",
46+
"s-1vcpu-2gb",
47+
"s-1vcpu-3gb",
48+
"s-2vcpu-2gb",
49+
"s-3vcpu-1gb",
50+
"s-2vcpu-4gb",
51+
"s-4vcpu-8gb",
52+
"s-6vcpu-16gb",
53+
"s-8vcpu-32gb",
54+
"s-12vcpu-48gb",
55+
"s-16vcpu-64gb",
56+
"s-20vcpu-96gb",
57+
"s-24vcpu-128gb",
58+
"s-32vcpu-192gb"
5959
],
6060
"features": [
6161
"private_networking",
@@ -71,7 +71,9 @@
7171
34153248,
7272
34153250
7373
],
74-
"redirect_http_to_https": false,
75-
"vpc_uuid": "08187eaa-90eb-40d6-a8f0-0222b28ded72"
74+
"redirect_http_to_https": true,
75+
"enable_proxy_protocol": true,
76+
"enable_backend_keepalive": true,
77+
"vpc_uuid": "c33931f2-a26a-4e61-b85c-4e95a2ec431b"
7678
}
7779
}

0 commit comments

Comments
 (0)