mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 13:44:24 +00:00
feat(dblab): operate via apis
This commit is contained in:
@@ -1246,6 +1246,80 @@
|
||||
all: true
|
||||
register: awx_export_output
|
||||
|
||||
- name: DBLab-specific operations
|
||||
tags: never
|
||||
hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
dblab_port: 2345
|
||||
max_snapshot_age_in_days: 15
|
||||
vars_prompt:
|
||||
- name: dblab_host
|
||||
private: false
|
||||
- name: dblab_token
|
||||
pre_tasks:
|
||||
- name: Print out run's variables
|
||||
ansible.builtin.debug:
|
||||
verbosity: 3
|
||||
msg: >-
|
||||
{{
|
||||
dict([
|
||||
[ 'host', dblab_host ],
|
||||
[ 'port', dblab_port ],
|
||||
[ 'token', dblab_token ],
|
||||
[ 'max_snapshot_age_in_days', max_snapshot_age_in_days ],
|
||||
])
|
||||
}}
|
||||
- name: Check the snapshots
|
||||
block:
|
||||
- name: Gather snapshots' status
|
||||
check_mode: false
|
||||
ansible.builtin.uri:
|
||||
url: https://{{ dblab_host }}:{{ dblab_port }}/snapshots
|
||||
headers:
|
||||
'verification-token': "{{ dblab_token }}"
|
||||
register: snapshots_status
|
||||
- name: Print out the request's results
|
||||
ansible.builtin.debug:
|
||||
verbosity: 3
|
||||
var: snapshots_status.json
|
||||
- name: Check the data is recent enough on both snapshots
|
||||
ansible.builtin.assert:
|
||||
that: >-
|
||||
(
|
||||
ansible_date_time.iso8601|to_datetime('%Y-%m-%dT%H:%M:%SZ') -
|
||||
item.dataStateAt|to_datetime('%Y-%m-%dT%H:%M:%SZ')
|
||||
).days < max_snapshot_age_in_days
|
||||
fail_msg: snapshot {{ item.id }} for pool {{ item.pool }} is too old
|
||||
loop: "{{ snapshots_status.json }}"
|
||||
tasks:
|
||||
- name: Reset protected clones on {{ dblab_host }}
|
||||
tags: reset_protected_clones
|
||||
block:
|
||||
- name: Gather clones on {{ dblab_host }}
|
||||
check_mode: false
|
||||
ansible.builtin.uri:
|
||||
url: http://{{ dblab_host }}:{{ dblab_port }}/status
|
||||
headers:
|
||||
'verification-token': "{{ dblab_token }}"
|
||||
register: instance_status
|
||||
- name: Print out the request's results
|
||||
ansible.builtin.debug:
|
||||
verbosity: 3
|
||||
var: instance_status.json
|
||||
- name: Reset protected clones
|
||||
vars:
|
||||
protected_clones: "{{ instance_status.json.cloning.clones | selectattr('protected', 'equalto', true) }}"
|
||||
ansible.builtin.uri:
|
||||
url: http://{{ dblab_host }}:{{ dblab_port }}/clone/{{ item.id }}/reset
|
||||
headers:
|
||||
'verification-token': "{{ dblab_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
latest: true
|
||||
loop: "{{ protected_clones }}"
|
||||
register: reset_requests
|
||||
|
||||
- name: Gitea-specific operations
|
||||
tags:
|
||||
- gitea
|
||||
|
||||
@@ -1,31 +1,102 @@
|
||||
#!/usr/bin/env fish
|
||||
|
||||
# Check logs
|
||||
docker logs --since '5m' -f 'dblab_server'
|
||||
|
||||
# Reload the configuration
|
||||
docker exec -it 'dblab_server' kill -SIGHUP '1'
|
||||
|
||||
# Check the running container's version
|
||||
# Used to check the instance is up and running
|
||||
curl 'http://127.0.0.1:2345/healthz'
|
||||
dblab --url 'http://dblab.example.org:1234/' --token "$(gopass show -o 'dblab')" instance version
|
||||
|
||||
# Initialize the CLI client
|
||||
dblab init
|
||||
|
||||
# Show global CLI environment configuration
|
||||
dblab config show-global
|
||||
|
||||
# Create CLI environments
|
||||
dblab config create 'staging'
|
||||
|
||||
# Show available CLI environments
|
||||
dblab config list
|
||||
|
||||
# Show current CLI environment configuration
|
||||
dblab config view
|
||||
|
||||
# Modify CLI environments
|
||||
# Errors out should one specify the current set of settings
|
||||
dblab config update --url --insecure=true 'staging'
|
||||
|
||||
# Switch CLI environments
|
||||
dblab config switch 'staging'
|
||||
|
||||
# Get the APIs' specification
|
||||
# JS page
|
||||
open 'https://dblab.example.org:2345/'
|
||||
open 'https://dblab.example.org:1234/api/'
|
||||
|
||||
# Open WebUI
|
||||
open 'http://dblab.example.org:1234/'
|
||||
|
||||
# Get instance status, instance info, and list of clones
|
||||
curl 'https://dblab.example.org:2345/status' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
curl 'https://dblab.example.org:1234/api/status' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
dblab instance status
|
||||
|
||||
# List snapshots
|
||||
curl 'https://dblab.example.org:2345/snapshots' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
curl 'https://dblab.example.org:1234/api/snapshots' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
dblab snapshot list
|
||||
|
||||
# Create clones
|
||||
curl -X 'POST' 'https://dblab.company.com:1234/api/clone' -H "Verification-Token: $(gopass show -o 'dblab')" \
|
||||
curl -X 'POST' 'https://dblab.example.org:1234/api/clone' -H "Verification-Token: $(gopass show -o 'dblab')" \
|
||||
-H 'accept: application/json' -H 'content-type: application/json' \
|
||||
-d '{
|
||||
"id": "smth",
|
||||
"id": "some-clone",
|
||||
"protected": true,
|
||||
"db": {
|
||||
"username": "master",
|
||||
"password": "ofPuppets",
|
||||
"db_name": "puppet"
|
||||
"username": "geppetto",
|
||||
"password": "pinocchio",
|
||||
"db_name": "puppets-workshop"
|
||||
}
|
||||
}'
|
||||
|
||||
# List clones
|
||||
curl 'https://dblab.example.org:1234/api/status' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
dblab clone list
|
||||
|
||||
# Get clones' information
|
||||
curl 'https://dblab.company.com:1234/api/clone/smth' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
dblab --url 'http://dblab.company.com:1234/' --token "$(gopass show -o 'dblab')" clone status 'smth'
|
||||
curl 'https://dblab.example.org:1234/api/clone/some-clone' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
dblab clone status 'some-clone'
|
||||
|
||||
# Reset clones
|
||||
curl -X 'POST' 'https://dblab.company.com:1234/api/clone/smth/reset' -H "Verification-Token: $(gopass show -o 'dblab')" \
|
||||
curl -X 'POST' 'https://dblab.example.org:1234/api/clone/some-clone/reset' \
|
||||
-H "Verification-Token: $(gopass show -o 'dblab')" \
|
||||
-H 'accept: application/json' -H 'content-type: application/json' \
|
||||
-d '{ "latest": true }'
|
||||
dblab clone reset --async='true' --latest='true' 'some-clone'
|
||||
# Reset all protected clones
|
||||
curl --url 'https://dblab.example.org:2345/status' --header 'verification-token: somePassword' \
|
||||
| jq -r '.cloning.clones[]|select(.protected = "true")|.id' \
|
||||
| xargs -I '%%' \
|
||||
curl --request 'POST' --url 'https://dblab.example.org:2345/clone/%%/reset' \
|
||||
--header 'verification-token: somePassword' \
|
||||
--header 'content-type: application/json' \
|
||||
--data '{ "latest": true }'
|
||||
|
||||
# Unprotect clones
|
||||
curl -X 'PATCH' 'https://dblab.company.com:1234/api/clone/smth' -H "Verification-Token: $(gopass show -o 'dblab')" \
|
||||
curl -X 'PATCH' 'https://dblab.example.org:1234/api/clone/some-clone' \
|
||||
-H "Verification-Token: $(gopass show -o 'dblab')" \
|
||||
-H 'accept: application/json' -H 'content-type: application/json' \
|
||||
-d '{ "protected": false }'
|
||||
dblab clone update --protected='false' 'some-clone'
|
||||
|
||||
# Delete clones
|
||||
curl -X 'DELETE' 'https://dblab.company.com:1234/api/clone/smth' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
curl -X 'DELETE' 'https://dblab.example.org:1234/api/clone/some-clone' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
dblab clone destroy 'some-clone'
|
||||
|
||||
# Get admin config in YAML format
|
||||
curl 'https://dblab.example.org:1234/api/admin/config.yaml' -H "Verification-Token: $(gopass show -o 'dblab')"
|
||||
|
||||
Reference in New Issue
Block a user