Skip to content

Commit

Permalink
Added support for some extra fields to the "backend" config
Browse files Browse the repository at this point in the history
"weight", "max_conn", "error_threshold", "connect_timeout", "first_byte_timeout" and "between_bytes_timeout"
  • Loading branch information
hynd committed Oct 10, 2017
1 parent de1e32c commit 6ee4def
Show file tree
Hide file tree
Showing 40 changed files with 3,046 additions and 2,512 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@ $ ansible-galaxy install Jimdo.fastly

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

| Field | Required | Type | Default |
|:------------------|:---------|:--------------------------------------------------------|:--------|
| name | true | string | |
| port | false | integer | 80 |
| address | true | string | |
| ssl_hostname | false | string | |
| ssl_ca_cert | false | string | |
| ssl_cert_hostname | false | string | |
| shield | false | string | |
| healthcheck | false | string | |
| Field | Required | Type | Default |
|:----------------------|:---------|:--------------------------------------------------|:--------|
| name | true | string | |
| port | false | integer | 80 |
| address | true | string | |
| ssl_hostname | false | string | |
| ssl_ca_cert | false | string | |
| ssl_cert_hostname | false | string | |
| shield | false | string | |
| healthcheck | false | string | |
| weight | false | integer | 100 |
| connect_timeout | false | integer | 1000 |
| first_byte_timeout | false | integer | 15000 |
| between_bytes_timeout | false | integer | 10000 |
| error_threshold | false | integer | 0 |
| max_conn | false | integer | 200 |

### Cache Settings

Expand Down
12 changes: 12 additions & 0 deletions library/fastly_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ class FastlyBackend(FastlyObject):
'ssl_cert_hostname': dict(required=False, type='str', default=None, exclude_empty_str=True),
'shield': dict(required=False, type='str', default=None, exclude_empty_str=True),
'healthcheck': dict(required=False, type='str', default=None, exclude_empty_str=True),
'weight': dict(required=False, type='int', default=100),
'connect_timeout': dict(required=False, type='int', default=1000),
'first_byte_timeout': dict(required=False, type='int', default=15000),
'between_bytes_timeout': dict(required=False, type='int', default=10000),
'error_threshold': dict(required=False, type='int', default=0),
'max_conn': dict(required=False, type='int', default=200),
}

def __init__(self, config, validate_choices):
Expand All @@ -261,6 +267,12 @@ def __init__(self, config, validate_choices):
self.ssl_cert_hostname = self.read_config(config, validate_choices, 'ssl_cert_hostname')
self.shield = self.read_config(config, validate_choices, 'shield')
self.healthcheck = self.read_config(config, validate_choices, 'healthcheck')
self.weight = self.read_config(config, validate_choices, 'weight')
self.connect_timeout = self.read_config(config, validate_choices, 'connect_timeout')
self.first_byte_timeout = self.read_config(config, validate_choices, 'first_byte_timeout')
self.between_bytes_timeout = self.read_config(config, validate_choices, 'between_bytes_timeout')
self.error_threshold = self.read_config(config, validate_choices, 'error_threshold')
self.max_conn = self.read_config(config, validate_choices, 'max_conn')

def sort_key(f):
return f.name
Expand Down
54 changes: 28 additions & 26 deletions tests/fixtures/cassettes/TestFastlyCacheSettings_tearDown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,82 @@ interactions:
method: GET
uri: https://api.fastly.com/service/search?name=Fastly%20Ansible%20Module%20Test
response:
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"}'}
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"}'}
headers:
accept-ranges: [bytes]
age: ['0']
cache-control: [no-cache]
connection: [keep-alive]
content-length: ['616']
content-length: ['596']
content-type: [application/json]
date: ['Wed, 27 Sep 2017 00:35:58 GMT']
date: ['Tue, 10 Oct 2017 10:33:29 GMT']
status: [200 OK]
vary: [Accept-Encoding]
via: [1.1 varnish, 1.1 varnish]
x-cache: ['MISS, MISS']
x-cache-hits: ['0, 0']
x-served-by: ['app-slwdc9051-SL, cache-yyz8331-YYZ']
x-timer: ['S1506472558.367430,VS0,VE82']
x-served-by: ['app-slwdc9051-SL, cache-ams4430-AMS']
x-timer: ['S1507631609.073426,VS0,VE135']
status: {code: 200, message: OK}
- request:
body: null
headers:
Content-Type: [application/json]
method: GET
uri: https://api.fastly.com/service/6JpirHt7dTku4S29iY9ZPg/details
uri: https://api.fastly.com/service/3QhmHI5SRhK6mQ8YK5Gmz2/details
response:
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\"
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\"
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
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\"
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\"
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
200 status code","content":"","cache_condition":""}],"snippets":[],"vcls":[],"wordpress":[],"settings":{"general.default_ttl":3600,"general.default_host":"","general.default_pci":0}}}'}
headers:
accept-ranges: [bytes]
age: ['0']
cache-control: [no-cache]
connection: [keep-alive]
content-length: ['4111']
content-length: ['4061']
content-type: [application/json]
date: ['Wed, 27 Sep 2017 00:35:58 GMT']
date: ['Tue, 10 Oct 2017 10:33:29 GMT']
status: [200 OK]
vary: [Accept-Encoding]
via: [1.1 varnish, 1.1 varnish]
x-cache: ['MISS, MISS']
x-cache-hits: ['0, 0']
x-served-by: ['app-slwdc9051-SL, cache-yyz8327-YYZ']
x-timer: ['S1506472559.867946,VS0,VE47']
x-served-by: ['app-slwdc9051-SL, cache-ams4133-AMS']
x-timer: ['S1507631609.335051,VS0,VE121']
status: {code: 200, message: OK}
- request:
body: null
headers:
Content-Type: [application/json]
method: PUT
uri: https://api.fastly.com/service/6JpirHt7dTku4S29iY9ZPg/version/2/deactivate
uri: https://api.fastly.com/service/3QhmHI5SRhK6mQ8YK5Gmz2/version/2/deactivate
response:
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}'}
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}'}
headers:
accept-ranges: [bytes]
cache-control: [no-cache]
connection: [keep-alive]
content-length: ['241']
content-length: ['231']
content-type: [application/json]
date: ['Wed, 27 Sep 2017 00:35:59 GMT']
fastly-ratelimit-remaining: ['989']
fastly-ratelimit-reset: ['1506474000']
date: ['Tue, 10 Oct 2017 10:33:30 GMT']
fastly-ratelimit-remaining: ['984']
fastly-ratelimit-reset: ['1507633200']
status: [200 OK]
vary: [Accept-Encoding]
via: [1.1 varnish, 1.1 varnish]
x-cache: ['MISS, MISS']
x-cache-hits: ['0, 0']
x-served-by: ['app-slwdc9051-SL, cache-yyz8326-YYZ']
x-timer: ['S1506472559.116235,VS0,VE169']
x-served-by: ['app-slwdc9051-SL, cache-ams4422-AMS']
x-timer: ['S1507631610.534354,VS0,VE497']
status: {code: 200, message: OK}
- request:
body: null
headers:
Content-Type: [application/json]
method: DELETE
uri: https://api.fastly.com/service/6JpirHt7dTku4S29iY9ZPg
uri: https://api.fastly.com/service/3QhmHI5SRhK6mQ8YK5Gmz2
response:
body: {string: !!python/unicode '{"status":"ok"}'}
headers:
Expand All @@ -88,15 +90,15 @@ interactions:
connection: [keep-alive]
content-length: ['15']
content-type: [application/json]
date: ['Wed, 27 Sep 2017 00:35:59 GMT']
fastly-ratelimit-remaining: ['988']
fastly-ratelimit-reset: ['1506474000']
date: ['Tue, 10 Oct 2017 10:33:30 GMT']
fastly-ratelimit-remaining: ['983']
fastly-ratelimit-reset: ['1507633200']
status: [200 OK]
vary: [Accept-Encoding]
via: [1.1 varnish, 1.1 varnish]
x-cache: ['MISS, MISS']
x-cache-hits: ['0, 0']
x-served-by: ['app-slwdc9051-SL, cache-yyz8326-YYZ']
x-timer: ['S1506472560.604607,VS0,VE82']
x-served-by: ['app-slwdc9051-SL, cache-ams4149-AMS']
x-timer: ['S1507631610.112493,VS0,VE445']
status: {code: 200, message: OK}
version: 1
Loading

0 comments on commit 6ee4def

Please sign in to comment.