Skip to content

Commit 7816b2e

Browse files
committed
Update Blog “how-to-use-dscc-api-and-ansible-to-collect-the-storage-configuration”
1 parent 64639f1 commit 7816b2e

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

content/blog/how-to-use-dscc-api-and-ansible-to-collect-the-storage-configuration.md

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Now in order to be independent of any python library (or the lack of updates to
2626

2727
## Retrieving a DSCC access token
2828

29-
The steps to first generate the client Id and the client secret used to access the DSCC REST API was already described in a blog on the HPE Developer Portal: <!--StartFragment--> [Using HPE GreenLake Console's API Gateway for Data Services Cloud Console ](https://developer.hpe.com/blog/api-console-for-data-services-cloud-console/)<!--EndFragment-->.
29+
The steps to first generate the client id and the client secret used to access the DSCC REST API was already described in a blog on the HPE Developer Portal: <!--StartFragment--> [Using HPE GreenLake Console's API Gateway for Data Services Cloud Console ](https://developer.hpe.com/blog/api-console-for-data-services-cloud-console/)<!--EndFragment-->.
3030

31-
Once you do have your client id and client secret, you can generate an access token that is valid for two hours.
31+
Once you do have your client id and client secret, you can generate an access token, that is valid for two hours. This access token will allow you to issue REST API calls to the Data Services Cloud Console - you will have the empowerment on the REST API as the user that is linked with the client id and secret used to create the access token. Hence, it is best practice to store the client id and secret in a secure place. The below code example had the client credentials stored in the credentials.yml file, that was encrypted using ansible-vault. The current Ansible playbook stores the access token in a file that grants access only to the current user (hence, the access mode 600 for this file) to avoid misuse of the retrieved access token.
3232

3333
```
3434
- name: Include encrypted vars
@@ -53,11 +53,15 @@ Once you do have your client id and client secret, you can generate an access to
5353
ansible.builtin.copy:
5454
content: "{{ token }}"
5555
dest: 'vars/token.txt'
56-
mode: "0644"
56+
mode: "0600"
5757
```
5858

5959
## DSCC REST API call
6060

61+
62+
63+
64+
6165
```
6266
- name: Include encrypted vars
6367
include_vars: vars/credentials.yml
@@ -125,6 +129,75 @@ Once you do have your client id and client secret, you can generate an access to
125129
when: status not in ['200', '201', '202','401']
126130
```
127131

132+
133+
134+
135+
136+
# System Configuration capture
137+
138+
```
139+
hosts: localhost
140+
vars:
141+
method: "GET"
142+
143+
tasks:
144+
- name: DSCC API Call GET storage systems
145+
vars:
146+
request_uri: "/api/v1/storage-systems"
147+
ansible.builtin.include_tasks:
148+
file: DSCC-API-Call.yaml
149+
150+
- name: Retry the command if status 401
151+
vars:
152+
request_uri: "/api/v1/storage-systems"
153+
ansible.builtin.include_tasks:
154+
file: DSCC-API-401.yaml
155+
when: status == '401'
156+
157+
- name: Set Systems
158+
ansible.builtin.set_fact:
159+
systems: "{{ response.json['items'] }}"
160+
when: status in ['200', '201']
161+
162+
- name: Initialize Storage system dictionary if not defined
163+
ansible.builtin.set_fact:
164+
storage_systems: "{{ storage_systems | default({}) }}"
165+
- name: Create StorageSystems Dictionary
166+
ansible.builtin.set_fact:
167+
storage_systems: "{{ storage_systems | combine({item.name: {'id': item.id, 'resourceUri': item.resourceUri}}) }}"
168+
with_items: "{{ systems }}"
169+
170+
- name: Loop Systems
171+
vars:
172+
ansible.builtin.include_tasks:
173+
file: Loop-Systems.yaml
174+
with_dict: "{{storage_systems}}"
175+
loop_control:
176+
loop_var: my_system
177+
178+
- name: Get HostGroups
179+
vars:
180+
request_uri: "/api/v1/host-initiator-groups"
181+
ansible.builtin.include_tasks:
182+
file: DSCC-API-Call.yaml
183+
- name: Store the HostGroups
184+
ansible.builtin.copy:
185+
content: "{{ response.json | to_nice_json }}"
186+
dest: "../Outputs/hostGroups.json"
187+
mode: '0644'
188+
when: response.json is defined
189+
190+
- name: Get Hosts
191+
ansible.builtin.include_tasks:
192+
file: GetAllHosts.yaml
193+
- name: Store the Hosts
194+
ansible.builtin.copy:
195+
content: "{{ response.json | to_nice_json }}"
196+
dest: "../Outputs/hosts.json"
197+
mode: '0644'
198+
when: response.json is defined
199+
```
200+
128201
Used Playbook hierarchy:
129202

130203
* Capture-Systems.yaml

0 commit comments

Comments
 (0)