-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lifecycle functions to Equinix (#4184)
* Add lifecycle functions to Equinix * fix static test
- Loading branch information
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- when: >- | ||
ACTION == 'stop' | ||
or ACTION == 'start' | ||
or ACTION == 'status' | ||
include_role: | ||
name: infra-equinix-metal-resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
ansible/roles-infra/infra-equinix-metal-resources/tasks/start_instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
- name: Get all devices | ||
changed_when: false | ||
uri: | ||
url: >- | ||
{{- equinix_metal_api_uri -}} | ||
/projects/ | ||
{{- equinix_metal_project_ids[0] -}} | ||
/devices | ||
headers: | ||
X-Auth-Token: "{{ equinix_metal_api_token }}" | ||
register: r_equinix_metal_devices | ||
retries: "{{ equinix_metal_api_retries }}" | ||
delay: "{{ equinix_metal_api_delay }}" | ||
until: r_equinix_metal_devices is succeeded | ||
|
||
- name: Start devices | ||
loop: "{{ r_equinix_metal_devices.json.devices | default([]) }}" | ||
loop_control: | ||
loop_var: _device | ||
uri: | ||
url: >- | ||
{{- equinix_metal_api_uri -}} | ||
/devices/ | ||
{{- _device.id -}} | ||
/actions | ||
headers: | ||
X-Auth-Token: "{{ equinix_metal_api_token }}" | ||
method: POST | ||
body_format: json | ||
body: | ||
type: power_on | ||
status_code: [200, 202] | ||
|
||
register: r_start | ||
failed_when: >- | ||
not r_start is succeeded | ||
and not 'Device must be powered off' in r_start.json.errors | default([]) |
34 changes: 34 additions & 0 deletions
34
ansible/roles-infra/infra-equinix-metal-resources/tasks/status_instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
- name: Get all devices | ||
changed_when: false | ||
uri: | ||
url: >- | ||
{{- equinix_metal_api_uri -}} | ||
/projects/ | ||
{{- equinix_metal_project_ids[0] -}} | ||
/devices | ||
headers: | ||
X-Auth-Token: "{{ equinix_metal_api_token }}" | ||
register: r_equinix_metal_devices | ||
retries: "{{ equinix_metal_api_retries }}" | ||
delay: "{{ equinix_metal_api_delay }}" | ||
until: r_equinix_metal_devices is succeeded | ||
|
||
- name: Report status in user info | ||
agnosticd_user_info: | ||
msg: |- | ||
{{ "%-20s %-10s %-14s %s" | format("Instance", "State", "Type", "Location") }} | ||
---------------------------------------------------------------- | ||
{% for device in r_equinix_metal_devices.json.devices | default([]) %} | ||
{{ "%-20s %-10s %-14s %s" | format(device.hostname, device.state, device.plan.slug, device.facility.name) }} | ||
{% endfor %} | ||
- name: Print status information to a file | ||
copy: | ||
dest: "{{ output_dir }}/status.txt" | ||
content: |- | ||
{{ "%-20s %-10s %-14s %s" | format("Instance", "State", "Type", "Location") }} | ||
---------------------------------------------------------------- | ||
{% for device in r_equinix_metal_devices.json.devices | default([]) %} | ||
{{ "%-20s %-10s %-14s %s" | format(device.hostname, device.state, device.plan.slug, device.facility.name) }} | ||
{% endfor %} |
38 changes: 38 additions & 0 deletions
38
ansible/roles-infra/infra-equinix-metal-resources/tasks/stop_instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
- name: Get all devices | ||
changed_when: false | ||
uri: | ||
url: >- | ||
{{- equinix_metal_api_uri -}} | ||
/projects/ | ||
{{- equinix_metal_project_ids[0] -}} | ||
/devices | ||
headers: | ||
X-Auth-Token: "{{ equinix_metal_api_token }}" | ||
register: r_equinix_metal_devices | ||
retries: "{{ equinix_metal_api_retries }}" | ||
delay: "{{ equinix_metal_api_delay }}" | ||
until: r_equinix_metal_devices is succeeded | ||
|
||
- name: Stop devices | ||
loop: "{{ r_equinix_metal_devices.json.devices | default([]) }}" | ||
loop_control: | ||
loop_var: _device | ||
uri: | ||
url: >- | ||
{{- equinix_metal_api_uri -}} | ||
/devices/ | ||
{{- _device.id -}} | ||
/actions | ||
headers: | ||
X-Auth-Token: "{{ equinix_metal_api_token }}" | ||
method: POST | ||
body_format: json | ||
body: | ||
type: power_off | ||
status_code: [200, 202] | ||
|
||
register: r_stop | ||
failed_when: >- | ||
not r_stop is succeeded | ||
and not 'Device must be powered on' in r_stop.json.errors | default([]) |