Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
doubletao318 committed Mar 5, 2020
0 parents commit 6ab0dbb
Show file tree
Hide file tree
Showing 79 changed files with 9,376 additions and 0 deletions.
1,564 changes: 1,564 additions & 0 deletions README.md

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions playbook/az/get_az_by_name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---

# Required Parameters:
# azName: availability zone name
#
# Examples:
# --extra-vars "azName='room1'"
#
- name: Get AZ by name
hosts: localhost
vars_files:
- ../global.yml
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: Get AZ by name
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{ URI.azs }}?az_name={{azName|urlencode}}"
method: GET
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
register: AZ

- name: Check AZ
vars:
query: "[?name=='{{ azName }}']"
debug:
msg: "No matched AZ: '{{ azName }}'"
when: AZ.json.az_list | json_query(query) | length < 1

- name: Show AZ
vars:
query: "[?name=='{{ azName }}']"
debug:
msg: "{{ AZ.json.az_list | json_query(query) }}"
when: AZ.json.az_list | json_query(query) | length >= 1
64 changes: 64 additions & 0 deletions playbook/az/list_azs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

# Optional Parameters:
# pageNo: page number, default 1
# pageSize: page size, default: 10
# sortKey: sort key, options: name
# sortDir: sort direction, default: asc, options: desc, asc
# azName: availability zone name
#
# Examples:
# --extra-vars "azName='room' sortKey='name' sortDir='desc'"
#
- name: List AZs
hosts: localhost
vars:
pageNo: 1
pageSize: 10
params: "{{'limit=' + pageSize|string + '&start=' + (pageSize|int * (pageNo|int - 1) + 1) | string }}"
sortDir: asc
vars_files:
- ../global.yml
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: Set params - sortKey & sortDir
set_fact:
params: "{{ params + '&sort_key=' + sortKey + '&sort_dir=' + sortDir }}"
when:
- sortKey is defined

- name: Set params - azName
set_fact:
params: "{{ params + '&az_name=' + azName|urlencode }}"
when:
- azName is defined

- name: Show Param
debug:
msg: "{{params}}"

- name: List AZs
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{ URI.azs }}?{{params}}"
method: GET
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
register: AZs

- name: Show AZs
vars:
objList: "{{ AZs.json.az_list }}"
totalNum: "{{AZs.json.total}}"
sortDesc: "{{ 'True' if sortDir == 'desc' else 'False' }}"
debug:
msg:
objList: "{{ ( objList | sort(attribute=sortKey,reverse=sortDesc) ) if sortKey is defined else ( objList | sort(reverse=sortDesc) ) }}"
totalNum: "{{ totalNum }}"
pageSize: "{{ pageSize }}"
pageNo: "{{ pageNo }}"
39 changes: 39 additions & 0 deletions playbook/cmdb/get_instance_by_id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Required Parameters:
# objType: object type name, see ../global.yml to get supported object types in INVENTORY
# instanceId: instance ID
#
# Examples:
# --extra-vars "objType=volume instanceId=07C1C88199643614A4836E725C73F17D"

# Generated Parameters (can be overwritten):
# className: CI class Name, see ../global.yml to get supported className in INVENTORY.objType.className
#
# Examples:
# --extra-vars "className=SYS_Lun instanceId=07C1C88199643614A4836E725C73F17D"

- name: GET Instance by ID
hosts: localhost
vars:
className: "{{ INVENTORY[objType].className }}" # map objType to className
vars_files:
- ../global.yml
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: Get Instance
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{URI.instances}}/{{className}}/{{instanceId}}"
method: GET
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
register: INSTANCE

- name: Show Instance
debug:
msg: "{{ INSTANCE.json }}"
25 changes: 25 additions & 0 deletions playbook/cmdb/get_relation_by_id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

- name: GET Relation by ID
hosts: localhost
vars_files:
- ../global.yml
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: Get Relation
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{URI.relations}}/{{relationName}}/instances/{{instanceId}}"
method: GET
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
register: RELATION

- name: Show Relation
debug:
msg: "{{ RELATION.json }}"
61 changes: 61 additions & 0 deletions playbook/cmdb/list_instances.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
# Required Parameters:
# objType: object type name, see ../global.yml to get supported object types in INVENTORY
#
# Examples:
# --extra-vars "objType=volume"
#
# Optional Parameters:
# params: query parameters, see Examples
# export: export file path
# sep: separator, default '|'
#
# Examples:
# --extra-vars "params='pageNo=1&pageSize=10'"
# --extra-vars "params='condition={\"constraint\":[{\"simple\":{\"name\":\"dataStatus\",\"operator\":\"equal\",\"value\":\"normal\"}},{\"logOp\":\"and\",\"simple\":{\"name\":\"name\",\"operator\":\"contain\",\"value\":\"ansible\"}}]}'"
# --extra-vars "export='volumes.csv' sep='|'"
#
# Generated Parameters (can be overwritten):
# className: CI class Name, see ../global.yml to get supported className in INVENTORY.objType.className
#
# Examples:
# --extra-vars "className=SYS_Lun"
#
- name: List Instances
hosts: localhost
vars_files:
- ../global.yml
vars:
params: 'pageNo=1&pageSize=10'
className: "{{ INVENTORY[objType].className }}" # map objType to className
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: List Instances
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{URI.instances}}/{{className}}?{{params|replace(' ','%20')}}"
method: GET
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
register: INSTANCES

- name: Show Instances
debug:
msg: "{{ INSTANCES.json }}"
when: export is not defined

- import_tasks: ../util/json2csv.yml
vars:
data: "{{INSTANCES.json.objList}}"
keys: "{{INVENTORY[objType].attributes}}"
file: "{{export}}"
when:
- export is defined
- INSTANCES.json.objList is defined
- INSTANCES.json.objList|length > 0

57 changes: 57 additions & 0 deletions playbook/cmdb/list_relations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# Required Parameters:
# relationName: relation name, see ../global.yml to get supported relations in INVENTORY
#
# Examples:
# --extra-vars "relationName=M_DjHostAttachedLun"
#
# Optional Parameters:
# params: query parameters, see Examples
# export: export file path
# sep: separator, default '|'
#
# Examples:
# --extra-vars "params='pageNo=1&pageSize=10'"
# --extra-vars "params='condition={\"constraint\":[{\"simple\":{\"name\":\"last_Modified\",\"operator\":\"greater%20than\",\"value\":\"1576938117968\"}}]}'"
# --extra-vars "export='volume-map.csv' sep='|'"

- name: List Relations
hosts: localhost
vars:
params: 'pageNo=1&pageSize=10'
vars_files:
- ../global.yml
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: List Relations
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{URI.relations}}/{{relationName}}/instances?{{params}}"
method: GET
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
register: RELATIONS

- name: Show Relations
debug:
msg: "{{ RELATIONS.json }}"
when: export is not defined

- import_tasks: ../util/json2csv.yml
vars:
data: "{{RELATIONS.json.objList}}"
keys:
- id
- last_Modified
- source_Instance_Id
- target_Instance_Id
file: "{{export}}"
when:
- export is defined
- RELATIONS.json.objList is defined
- RELATIONS.json.objList|length > 0
23 changes: 23 additions & 0 deletions playbook/dataset/disk/disk-health-flat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

dummy:

dataset: "stat-storage-disk"
query:
timeRange:
beginTime: 1574179200000
endTime: 1574665590000
granularity: "auto"
filters:
dimensions:
- field: "dimensions.object.name"
values:
- "DAE001.3"
dimensions:
- field: "dimensions.object.name"
index: 1
- field: "timestamp"
index: 2
metrics:
- field: "metrics.healthScore"
aggType: "avg"
32 changes: 32 additions & 0 deletions playbook/dataset/fcswitchport/fcswitchport-perf-flat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

dummy:

dataset: "perf-fcswitch-port"
query:
timeRange:
beginTime: 1574179200000
endTime: 1574665590000
granularity: "auto"
filters:
dimensions:
- field: "dimensions.object.name"
values:
- "port0"
- "port2"
dimensions:
- field: "dimensions.object.name"
index: 1
- field: "dimensions.port.wwn"
index: 2
- field: "timestamp"
index: 3
metrics:
- field: "metrics.bandwidth"
aggType: "sum"
- field: "metrics.utility"
aggType: "avg"
- field: "metrics.error"
aggType: "sum"
- field: "metrics.bbCreditZero"
aggType: "sum"
45 changes: 45 additions & 0 deletions playbook/dataset/flat_query.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---

- name: Flat Query Dataset
hosts: localhost
vars:
pageNo: 1
pageSize: 1000
vars_files:
- ../global.yml
gather_facts: no
become: no
tasks:
- import_tasks: ../user/login.yml

- name: Show Query
debug:
msg: "{{ query }}"

- name: Query Dataset
uri:
url: "https://{{DJ.host}}:{{DJ.port}}/rest/{{URI.datasets}}/{{dataset}}?pageNo={{pageNo}}&pageSize={{pageSize}}"
method: POST
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json;charset=utf8"
X-Auth-Token: "{{DJ.token}}"
body_format: json
body: "{{ query }}"
register: RESULT

- name: Show Result
debug:
msg: "{{ RESULT.json }}"
when: export is not defined

- import_tasks: ../util/json2csv.yml
vars:
data: "{{ RESULT.json.datas }}"
keys: "{{ RESULT.json.datas[0] | dict2items | json_query('[*].key') }}"
file: "{{ export }}"
when:
- export is defined
- RESULT.json.datas is defined
- RESULT.json.datas|length > 0
Loading

0 comments on commit 6ab0dbb

Please sign in to comment.