Skip to content

Commit

Permalink
Remove non-API params; fix DOCUMENTATION and EXAMPLES; consistently r…
Browse files Browse the repository at this point in the history
…eference $DO_API_TOKEN (#253)

* Consistently reference DO_API_TOKEN

* 251-252 Remove non-API params and fix EXAMPLES

* 251-252 Change the Spaces bucket

* 251-252 Switch to time.monotonic and fixed 10s interval
  • Loading branch information
mamercad authored May 10, 2022
1 parent c4dc691 commit 3ee9dfe
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 35 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/248-oauth-token-consistency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- digital_ocean - reference C(DO_API_TOKEN) consistently in module documentation and examples (https://github.com/ansible-collections/community.digitalocean/issues/248).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- digital_ocean_cdn_endpoints - use the correct module name in the C(EXAMPLES) (https://github.com/ansible-collections/community.digitalocean/issues/251).
2 changes: 2 additions & 0 deletions changelogs/fragments/252-cdn-endpoints-http-500.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- digital_ocean_cdn_endpoints - remove non-API parameters before posting to the API (https://github.com/ansible-collections/community.digitalocean/issues/252).
14 changes: 7 additions & 7 deletions plugins/modules/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,18 @@
- name: Ensure a SSH key is present
community.digitalocean.digital_ocean:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: ssh
name: my_ssh_key
ssh_pub_key: 'ssh-rsa AAAA...'
api_token: XXX
# Will return the droplet details including the droplet id (used for idempotence)
- name: Create a new Droplet
community.digitalocean.digital_ocean:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: droplet
name: mydroplet
api_token: XXX
size_id: 2gb
region_id: ams2
image_id: fedora-19-x64
Expand All @@ -160,10 +160,10 @@
- name: Ensure a droplet is present
community.digitalocean.digital_ocean:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: droplet
id: 123
name: mydroplet
api_token: XXX
size_id: 2gb
region_id: ams2
image_id: fedora-19-x64
Expand All @@ -177,9 +177,9 @@
- name: Create a droplet with ssh key
community.digitalocean.digital_ocean:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
ssh_key_ids: 123,456
name: mydroplet
api_token: XXX
size_id: 2gb
region_id: ams2
image_id: fedora-19-x64
Expand Down Expand Up @@ -261,9 +261,9 @@ def ensure_powered_on(self, wait=True, wait_timeout=300):
self.power_on()

if wait:
end_time = time.time() + wait_timeout
while time.time() < end_time:
time.sleep(min(20, end_time - time.time()))
end_time = time.monotonic() + wait_timeout
while time.monotonic() < end_time:
time.sleep(10)
self.update_attr()
if self.is_powered_on():
if not self.ip_address:
Expand Down
18 changes: 9 additions & 9 deletions plugins/modules/digital_ocean_block_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@
- name: Create new Block Storage
community.digitalocean.digital_ocean_block_storage:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: create
api_token: <TOKEN>
region: nyc1
block_size: 10
volume_name: nyc1-block-storage
- name: Create new Block Storage (and assign to Project "test")
community.digitalocean.digital_ocean_block_storage:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: create
api_token: <TOKEN>
region: nyc1
block_size: 10
volume_name: nyc1-block-storage
Expand All @@ -103,34 +103,34 @@
- name: Resize an existing Block Storage
community.digitalocean.digital_ocean_block_storage:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: create
api_token: <TOKEN>
region: nyc1
block_size: 20
volume_name: nyc1-block-storage
- name: Delete Block Storage
community.digitalocean.digital_ocean_block_storage:
state: absent
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: create
api_token: <TOKEN>
region: nyc1
volume_name: nyc1-block-storage
- name: Attach Block Storage to a Droplet
community.digitalocean.digital_ocean_block_storage:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: attach
api_token: <TOKEN>
volume_name: nyc1-block-storage
region: nyc1
droplet_id: <ID>
- name: Detach Block Storage from a Droplet
community.digitalocean.digital_ocean_block_storage:
state: absent
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
command: attach
api_token: <TOKEN>
volume_name: nyc1-block-storage
region: nyc1
droplet_id: <ID>
Expand Down Expand Up @@ -194,9 +194,9 @@ def get_key_or_fail(self, k):

def poll_action_for_complete_status(self, action_id):
url = "actions/{0}".format(action_id)
end_time = time.time() + self.module.params["timeout"]
while time.time() < end_time:
time.sleep(2)
end_time = time.monotonic() + self.module.params["timeout"]
while time.monotonic() < end_time:
time.sleep(10)
response = self.rest.get(url)
status = response.status_code
json = response.json
Expand Down
12 changes: 9 additions & 3 deletions plugins/modules/digital_ocean_cdn_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@

EXAMPLES = r"""
- name: Create DigitalOcean CDN Endpoint
community.digitalocean.digital_ocean_cdn_endpoints_info:
community.digitalocean.digital_ocean_cdn_endpoints:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
origin: mamercad.nyc3.digitaloceanspaces.com
- name: Update DigitalOcean CDN Endpoint (change ttl to 600, default is 3600)
community.digitalocean.digital_ocean_cdn_endpoints_info:
community.digitalocean.digital_ocean_cdn_endpoints:
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
origin: mamercad.nyc3.digitaloceanspaces.com
ttl: 600
- name: Delete DigitalOcean CDN Endpoint
community.digitalocean.digital_ocean_cdn_endpoints_info:
community.digitalocean.digital_ocean_cdn_endpoints:
state: absent
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
origin: mamercad.nyc3.digitaloceanspaces.com
Expand Down Expand Up @@ -219,6 +219,12 @@ def delete(self):
def run(module):
state = module.params.pop("state")
c = DOCDNEndpoint(module)

# Pop these away (don't need them beyond DOCDNEndpoint)
module.params.pop("baseurl")
module.params.pop("validate_certs")
module.params.pop("timeout")

if state == "present":
c.create()
elif state == "absent":
Expand Down
14 changes: 7 additions & 7 deletions plugins/modules/digital_ocean_domain_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,26 @@
EXAMPLES = """
- name: Create default A record for example.com
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
type: A
name: "@"
data: 127.0.0.1
- name: Create A record for www
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
type: A
name: www
data: 127.0.0.1
- name: Update A record for www based on name/type/data
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
type: A
name: www
Expand All @@ -120,8 +120,8 @@
- name: Update A record for www based on record_id
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
record_id: 123456
type: A
Expand All @@ -131,24 +131,24 @@
- name: Remove www record based on name/type/data
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: absent
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
type: A
name: www
data: 127.0.0.1
- name: Remove www record based on record_id
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: absent
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
record_id: 1234567
- name: Create MX record with priority 10 for example.com
community.digitalocean.digital_ocean_domain_record:
oauth_token: xxxx
state: present
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
type: MX
data: mail1.example.com
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/digital_ocean_domain_record_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@
- name: Retrieve all domain records for example.com
community.digitalocean.digital_ocean_domain_record_info:
state: present
oauth_token: xxxx
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
- name: Get specific domain record by ID
community.digitalocean.digital_ocean_domain_record_info:
state: present
oauth_token: xxxx
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
record_id: 12345789
register: result
- name: Retrieve all A domain records for example.com
community.digitalocean.digital_ocean_domain_record_info:
state: present
oauth_token: xxxx
oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}"
domain: example.com
type: A
"""
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/digital_ocean_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ def get_kubernetes_options(self):

def ensure_running(self):
"""Waits for the newly created DigitalOcean Kubernetes cluster to be running"""
end_time = time.time() + self.wait_timeout
while time.time() < end_time:
end_time = time.monotonic() + self.wait_timeout
while time.monotonic() < end_time:
cluster = self.get_by_id()
if cluster["kubernetes_cluster"]["status"]["state"] == "running":
return cluster
time.sleep(min(2, end_time - time.time()))
time.sleep(10)
self.module.fail_json(msg="Wait for Kubernetes cluster to be running")

def create(self):
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/digital_ocean_load_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def ensure_active(self):
self.id, self.region
)
)
time.sleep(min(10, end_time - time.monotonic()))
time.sleep(10)
self.module.fail_json(
msg="Timed out waiting for Load Balancer {0} in {1} to be active".format(
self.id, self.region
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
endpoint: gh-ci-space.nyc3.cdn.digitaloceanspaces.com
origin: gh-ci-space.nyc3.digitaloceanspaces.com
# endpoint: gh-ci-space.nyc3.cdn.digitaloceanspaces.com
# origin: gh-ci-space.nyc3.digitaloceanspaces.com
endpoint: ansible-gh-ci-space.nyc3.cdn.digitaloceanspaces.com
origin: ansible-gh-ci-space.nyc3.digitaloceanspaces.com

0 comments on commit 3ee9dfe

Please sign in to comment.