Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit f1b3609

Browse files
authored
Merge pull request #38 from hynd/backend_weight
Add support for some extra fields to the "backend" config
2 parents de1e32c + 6ee4def commit f1b3609

File tree

40 files changed

+3046
-2512
lines changed

40 files changed

+3046
-2512
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,22 @@ $ ansible-galaxy install Jimdo.fastly
3636

3737
[Fastly documentation](https://docs.fastly.com/api/config#backend)
3838

39-
| Field | Required | Type | Default |
40-
|:------------------|:---------|:--------------------------------------------------------|:--------|
41-
| name | true | string | |
42-
| port | false | integer | 80 |
43-
| address | true | string | |
44-
| ssl_hostname | false | string | |
45-
| ssl_ca_cert | false | string | |
46-
| ssl_cert_hostname | false | string | |
47-
| shield | false | string | |
48-
| healthcheck | false | string | |
39+
| Field | Required | Type | Default |
40+
|:----------------------|:---------|:--------------------------------------------------|:--------|
41+
| name | true | string | |
42+
| port | false | integer | 80 |
43+
| address | true | string | |
44+
| ssl_hostname | false | string | |
45+
| ssl_ca_cert | false | string | |
46+
| ssl_cert_hostname | false | string | |
47+
| shield | false | string | |
48+
| healthcheck | false | string | |
49+
| weight | false | integer | 100 |
50+
| connect_timeout | false | integer | 1000 |
51+
| first_byte_timeout | false | integer | 15000 |
52+
| between_bytes_timeout | false | integer | 10000 |
53+
| error_threshold | false | integer | 0 |
54+
| max_conn | false | integer | 200 |
4955

5056
### Cache Settings
5157

library/fastly_service.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ class FastlyBackend(FastlyObject):
249249
'ssl_cert_hostname': dict(required=False, type='str', default=None, exclude_empty_str=True),
250250
'shield': dict(required=False, type='str', default=None, exclude_empty_str=True),
251251
'healthcheck': dict(required=False, type='str', default=None, exclude_empty_str=True),
252+
'weight': dict(required=False, type='int', default=100),
253+
'connect_timeout': dict(required=False, type='int', default=1000),
254+
'first_byte_timeout': dict(required=False, type='int', default=15000),
255+
'between_bytes_timeout': dict(required=False, type='int', default=10000),
256+
'error_threshold': dict(required=False, type='int', default=0),
257+
'max_conn': dict(required=False, type='int', default=200),
252258
}
253259

254260
def __init__(self, config, validate_choices):
@@ -261,6 +267,12 @@ def __init__(self, config, validate_choices):
261267
self.ssl_cert_hostname = self.read_config(config, validate_choices, 'ssl_cert_hostname')
262268
self.shield = self.read_config(config, validate_choices, 'shield')
263269
self.healthcheck = self.read_config(config, validate_choices, 'healthcheck')
270+
self.weight = self.read_config(config, validate_choices, 'weight')
271+
self.connect_timeout = self.read_config(config, validate_choices, 'connect_timeout')
272+
self.first_byte_timeout = self.read_config(config, validate_choices, 'first_byte_timeout')
273+
self.between_bytes_timeout = self.read_config(config, validate_choices, 'between_bytes_timeout')
274+
self.error_threshold = self.read_config(config, validate_choices, 'error_threshold')
275+
self.max_conn = self.read_config(config, validate_choices, 'max_conn')
264276

265277
def sort_key(f):
266278
return f.name

tests/fixtures/cassettes/TestFastlyCacheSettings_tearDown.yml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,80 +6,82 @@ interactions:
66
method: GET
77
uri: https://api.fastly.com/service/search?name=Fastly%20Ansible%20Module%20Test
88
response:
9-
body: {string: !!python/unicode '{"name":"Fastly Ansible Module Test","deleted_at":null,"versions":[{"testing":false,"locked":false,"number":1,"active":false,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"created_at":"2017-09-27T00:35:50+00:00","deleted_at":null,"comment":"","updated_at":"2017-09-27T00:35:50+00:00","deployed":false},{"testing":false,"number":2,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"deployed":false,"locked":true,"active":true,"comment":""}],"created_at":"2017-09-27T00:35:50+00:00","customer_id":"1z3ENiEMpKOrsGqTBLhkF2","comment":"","updated_at":"2017-09-27T00:35:50+00:00","id":"6JpirHt7dTku4S29iY9ZPg"}'}
9+
body: {string: !!python/unicode '{"name":"Fastly Ansible Module Test","deleted_at":null,"versions":[{"testing":false,"locked":false,"number":1,"active":false,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"created_at":"2017-10-10T10:33:22Z","deleted_at":null,"comment":"","updated_at":"2017-10-10T10:33:22Z","deployed":false},{"testing":false,"number":2,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"deployed":false,"locked":true,"active":true,"comment":""}],"created_at":"2017-10-10T10:33:22Z","customer_id":"1z3ENiEMpKOrsGqTBLhkF2","comment":"","updated_at":"2017-10-10T10:33:22Z","id":"3QhmHI5SRhK6mQ8YK5Gmz2"}'}
1010
headers:
1111
accept-ranges: [bytes]
12+
age: ['0']
1213
cache-control: [no-cache]
1314
connection: [keep-alive]
14-
content-length: ['616']
15+
content-length: ['596']
1516
content-type: [application/json]
16-
date: ['Wed, 27 Sep 2017 00:35:58 GMT']
17+
date: ['Tue, 10 Oct 2017 10:33:29 GMT']
1718
status: [200 OK]
1819
vary: [Accept-Encoding]
1920
via: [1.1 varnish, 1.1 varnish]
2021
x-cache: ['MISS, MISS']
2122
x-cache-hits: ['0, 0']
22-
x-served-by: ['app-slwdc9051-SL, cache-yyz8331-YYZ']
23-
x-timer: ['S1506472558.367430,VS0,VE82']
23+
x-served-by: ['app-slwdc9051-SL, cache-ams4430-AMS']
24+
x-timer: ['S1507631609.073426,VS0,VE135']
2425
status: {code: 200, message: OK}
2526
- request:
2627
body: null
2728
headers:
2829
Content-Type: [application/json]
2930
method: GET
30-
uri: https://api.fastly.com/service/6JpirHt7dTku4S29iY9ZPg/details
31+
uri: https://api.fastly.com/service/3QhmHI5SRhK6mQ8YK5Gmz2/details
3132
response:
32-
body: {string: !!python/unicode '{"name":"Fastly Ansible Module Test","deleted_at":null,"versions":[{"testing":false,"locked":false,"number":1,"active":false,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"created_at":"2017-09-27T00:35:50+00:00","deleted_at":null,"comment":"","updated_at":"2017-09-27T00:35:50+00:00","deployed":false},{"testing":false,"locked":true,"number":2,"active":true,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"created_at":"2017-09-27T00:35:50+00:00","deleted_at":null,"comment":"","updated_at":"2017-09-27T00:35:55+00:00","deployed":false}],"created_at":"2017-09-27T00:35:50+00:00","customer_id":"1z3ENiEMpKOrsGqTBLhkF2","comment":"","updated_at":"2017-09-27T00:35:50+00:00","id":"6JpirHt7dTku4S29iY9ZPg","version":{"testing":false,"number":2,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"updated_at":"2017-09-27T00:35:55+00:00","deployed":false,"locked":true,"active":true,"deleted_at":null,"created_at":"2017-09-27T00:35:50+00:00","comment":"","acls":[],"backends":[{"max_tls_version":null,"ssl_ca_cert":null,"auto_loadbalance":false,"ssl_check_cert":true,"shield":null,"hostname":null,"ssl_client_cert":null,"error_threshold":0,"request_condition":"","first_byte_timeout":15000,"ssl_cert_hostname":null,"weight":100,"client_cert":null,"address":"127.0.0.1","ssl_hostname":null,"ssl_sni_hostname":null,"min_tls_version":null,"ipv6":null,"ipv4":"127.0.0.1","connect_timeout":1000,"ssl_ciphers":null,"name":"localhost","healthcheck":null,"port":80,"max_conn":200,"use_ssl":false,"comment":"","between_bytes_timeout":10000,"ssl_client_key":null}],"cache_settings":[{"stale_ttl":"10","ttl":null,"name":"cache-settings-config-name","action":null,"cache_condition":""}],"conditions":[],"dictionaries":[],"directors":[],"domains":[{"comment":"","name":"example8000.com"}],"gzips":[],"headers":[{"priority":"100","src":"\"https://u.jimcdn.com\"
33+
body: {string: !!python/unicode '{"name":"Fastly Ansible Module Test","deleted_at":null,"versions":[{"testing":false,"locked":false,"number":1,"active":false,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"created_at":"2017-10-10T10:33:22Z","deleted_at":null,"comment":"","updated_at":"2017-10-10T10:33:22Z","deployed":false},{"testing":false,"locked":true,"number":2,"active":true,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"created_at":"2017-10-10T10:33:23Z","deleted_at":null,"comment":"","updated_at":"2017-10-10T10:33:27Z","deployed":false}],"created_at":"2017-10-10T10:33:22Z","customer_id":"1z3ENiEMpKOrsGqTBLhkF2","comment":"","updated_at":"2017-10-10T10:33:22Z","id":"3QhmHI5SRhK6mQ8YK5Gmz2","version":{"testing":false,"number":2,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"updated_at":"2017-10-10T10:33:27Z","deployed":false,"locked":true,"active":true,"deleted_at":null,"created_at":"2017-10-10T10:33:23Z","comment":"","acls":[],"backends":[{"max_tls_version":null,"ssl_ca_cert":null,"auto_loadbalance":false,"ssl_check_cert":true,"shield":null,"hostname":null,"ssl_client_cert":null,"error_threshold":0,"request_condition":"","first_byte_timeout":15000,"ssl_cert_hostname":null,"weight":100,"client_cert":null,"address":"127.0.0.1","ssl_hostname":null,"ssl_sni_hostname":null,"min_tls_version":null,"ipv6":null,"ipv4":"127.0.0.1","connect_timeout":1000,"ssl_ciphers":null,"name":"localhost","healthcheck":null,"port":80,"max_conn":200,"use_ssl":false,"comment":"","between_bytes_timeout":10000,"ssl_client_key":null}],"cache_settings":[{"stale_ttl":"10","ttl":null,"name":"cache-settings-config-name","action":null,"cache_condition":""}],"conditions":[],"dictionaries":[],"directors":[],"domains":[{"comment":"","name":"example8000.com"}],"gzips":[],"headers":[{"priority":"100","src":"\"https://u.jimcdn.com\"
3334
req.url.path","name":"Set Location header","substitution":"","ignore_if_set":"0","cache_condition":null,"request_condition":null,"regex":"","response_condition":null,"action":"set","type":"response","dst":"http.Location"}],"healthchecks":[],"request_settings":[],"response_objects":[{"request_condition":"","content_type":"","status":"200","response":"Ok","name":"Set
34-
200 status code","content":"","cache_condition":""}],"snippets":[],"vcls":[],"wordpress":[],"settings":{"general.default_ttl":3600,"general.default_host":"","general.default_pci":0}},"active_version":{"testing":false,"number":2,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"updated_at":"2017-09-27T00:35:55+00:00","deployed":false,"locked":true,"active":true,"deleted_at":null,"created_at":"2017-09-27T00:35:50+00:00","comment":"","acls":[],"backends":[{"max_tls_version":null,"ssl_ca_cert":null,"auto_loadbalance":false,"ssl_check_cert":true,"shield":null,"hostname":null,"ssl_client_cert":null,"error_threshold":0,"request_condition":"","first_byte_timeout":15000,"ssl_cert_hostname":null,"weight":100,"client_cert":null,"address":"127.0.0.1","ssl_hostname":null,"ssl_sni_hostname":null,"min_tls_version":null,"ipv6":null,"ipv4":"127.0.0.1","connect_timeout":1000,"ssl_ciphers":null,"name":"localhost","healthcheck":null,"port":80,"max_conn":200,"use_ssl":false,"comment":"","between_bytes_timeout":10000,"ssl_client_key":null}],"cache_settings":[{"stale_ttl":"10","ttl":null,"name":"cache-settings-config-name","action":null,"cache_condition":""}],"conditions":[],"dictionaries":[],"directors":[],"domains":[{"comment":"","name":"example8000.com"}],"gzips":[],"headers":[{"priority":"100","src":"\"https://u.jimcdn.com\"
35+
200 status code","content":"","cache_condition":""}],"snippets":[],"vcls":[],"wordpress":[],"settings":{"general.default_ttl":3600,"general.default_host":"","general.default_pci":0}},"active_version":{"testing":false,"number":2,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"updated_at":"2017-10-10T10:33:27Z","deployed":false,"locked":true,"active":true,"deleted_at":null,"created_at":"2017-10-10T10:33:23Z","comment":"","acls":[],"backends":[{"max_tls_version":null,"ssl_ca_cert":null,"auto_loadbalance":false,"ssl_check_cert":true,"shield":null,"hostname":null,"ssl_client_cert":null,"error_threshold":0,"request_condition":"","first_byte_timeout":15000,"ssl_cert_hostname":null,"weight":100,"client_cert":null,"address":"127.0.0.1","ssl_hostname":null,"ssl_sni_hostname":null,"min_tls_version":null,"ipv6":null,"ipv4":"127.0.0.1","connect_timeout":1000,"ssl_ciphers":null,"name":"localhost","healthcheck":null,"port":80,"max_conn":200,"use_ssl":false,"comment":"","between_bytes_timeout":10000,"ssl_client_key":null}],"cache_settings":[{"stale_ttl":"10","ttl":null,"name":"cache-settings-config-name","action":null,"cache_condition":""}],"conditions":[],"dictionaries":[],"directors":[],"domains":[{"comment":"","name":"example8000.com"}],"gzips":[],"headers":[{"priority":"100","src":"\"https://u.jimcdn.com\"
3536
req.url.path","name":"Set Location header","substitution":"","ignore_if_set":"0","cache_condition":null,"request_condition":null,"regex":"","response_condition":null,"action":"set","type":"response","dst":"http.Location"}],"healthchecks":[],"request_settings":[],"response_objects":[{"request_condition":"","content_type":"","status":"200","response":"Ok","name":"Set
3637
200 status code","content":"","cache_condition":""}],"snippets":[],"vcls":[],"wordpress":[],"settings":{"general.default_ttl":3600,"general.default_host":"","general.default_pci":0}}}'}
3738
headers:
3839
accept-ranges: [bytes]
40+
age: ['0']
3941
cache-control: [no-cache]
4042
connection: [keep-alive]
41-
content-length: ['4111']
43+
content-length: ['4061']
4244
content-type: [application/json]
43-
date: ['Wed, 27 Sep 2017 00:35:58 GMT']
45+
date: ['Tue, 10 Oct 2017 10:33:29 GMT']
4446
status: [200 OK]
4547
vary: [Accept-Encoding]
4648
via: [1.1 varnish, 1.1 varnish]
4749
x-cache: ['MISS, MISS']
4850
x-cache-hits: ['0, 0']
49-
x-served-by: ['app-slwdc9051-SL, cache-yyz8327-YYZ']
50-
x-timer: ['S1506472559.867946,VS0,VE47']
51+
x-served-by: ['app-slwdc9051-SL, cache-ams4133-AMS']
52+
x-timer: ['S1507631609.335051,VS0,VE121']
5153
status: {code: 200, message: OK}
5254
- request:
5355
body: null
5456
headers:
5557
Content-Type: [application/json]
5658
method: PUT
57-
uri: https://api.fastly.com/service/6JpirHt7dTku4S29iY9ZPg/version/2/deactivate
59+
uri: https://api.fastly.com/service/3QhmHI5SRhK6mQ8YK5Gmz2/version/2/deactivate
5860
response:
59-
body: {string: !!python/unicode '{"testing":false,"locked":true,"number":2,"active":false,"service_id":"6JpirHt7dTku4S29iY9ZPg","staging":false,"created_at":"2017-09-27T00:35:50+00:00","deleted_at":null,"comment":"","updated_at":"2017-09-27T00:35:55+00:00","deployed":false}'}
61+
body: {string: !!python/unicode '{"testing":false,"locked":true,"number":2,"active":false,"service_id":"3QhmHI5SRhK6mQ8YK5Gmz2","staging":false,"created_at":"2017-10-10T10:33:23Z","deleted_at":null,"comment":"","updated_at":"2017-10-10T10:33:27Z","deployed":false}'}
6062
headers:
6163
accept-ranges: [bytes]
6264
cache-control: [no-cache]
6365
connection: [keep-alive]
64-
content-length: ['241']
66+
content-length: ['231']
6567
content-type: [application/json]
66-
date: ['Wed, 27 Sep 2017 00:35:59 GMT']
67-
fastly-ratelimit-remaining: ['989']
68-
fastly-ratelimit-reset: ['1506474000']
68+
date: ['Tue, 10 Oct 2017 10:33:30 GMT']
69+
fastly-ratelimit-remaining: ['984']
70+
fastly-ratelimit-reset: ['1507633200']
6971
status: [200 OK]
7072
vary: [Accept-Encoding]
7173
via: [1.1 varnish, 1.1 varnish]
7274
x-cache: ['MISS, MISS']
7375
x-cache-hits: ['0, 0']
74-
x-served-by: ['app-slwdc9051-SL, cache-yyz8326-YYZ']
75-
x-timer: ['S1506472559.116235,VS0,VE169']
76+
x-served-by: ['app-slwdc9051-SL, cache-ams4422-AMS']
77+
x-timer: ['S1507631610.534354,VS0,VE497']
7678
status: {code: 200, message: OK}
7779
- request:
7880
body: null
7981
headers:
8082
Content-Type: [application/json]
8183
method: DELETE
82-
uri: https://api.fastly.com/service/6JpirHt7dTku4S29iY9ZPg
84+
uri: https://api.fastly.com/service/3QhmHI5SRhK6mQ8YK5Gmz2
8385
response:
8486
body: {string: !!python/unicode '{"status":"ok"}'}
8587
headers:
@@ -88,15 +90,15 @@ interactions:
8890
connection: [keep-alive]
8991
content-length: ['15']
9092
content-type: [application/json]
91-
date: ['Wed, 27 Sep 2017 00:35:59 GMT']
92-
fastly-ratelimit-remaining: ['988']
93-
fastly-ratelimit-reset: ['1506474000']
93+
date: ['Tue, 10 Oct 2017 10:33:30 GMT']
94+
fastly-ratelimit-remaining: ['983']
95+
fastly-ratelimit-reset: ['1507633200']
9496
status: [200 OK]
9597
vary: [Accept-Encoding]
9698
via: [1.1 varnish, 1.1 varnish]
9799
x-cache: ['MISS, MISS']
98100
x-cache-hits: ['0, 0']
99-
x-served-by: ['app-slwdc9051-SL, cache-yyz8326-YYZ']
100-
x-timer: ['S1506472560.604607,VS0,VE82']
101+
x-served-by: ['app-slwdc9051-SL, cache-ams4149-AMS']
102+
x-timer: ['S1507631610.112493,VS0,VE445']
101103
status: {code: 200, message: OK}
102104
version: 1

0 commit comments

Comments
 (0)