[Nodepool] Clean up VMs and images using action
* New action in CI/CD App for deleting Nodepool Change-Id: I797ee059432de38656e33ae470e04343d5fa1d05
This commit is contained in:
parent
f26c1ab992
commit
9348c45ac8
@ -187,3 +187,15 @@ Methods:
|
|||||||
- $applications.select($hosts.applyTo($.instance))
|
- $applications.select($hosts.applyTo($.instance))
|
||||||
|
|
||||||
- $._environment.reporter.report($this, 'Hosts added.')
|
- $._environment.reporter.report($this, 'Hosts added.')
|
||||||
|
|
||||||
|
deleteNodepool:
|
||||||
|
Usage: Action
|
||||||
|
Body:
|
||||||
|
- If: $this.nodepool = null
|
||||||
|
Then:
|
||||||
|
- Return:
|
||||||
|
|
||||||
|
- $._environment.reporter.report($this, 'Deleting Nodepool...')
|
||||||
|
- $this.nodepool.releaseResources()
|
||||||
|
- $this.nodepool: null
|
||||||
|
- $._environment.reporter.report($this, 'Nodepool is deleted. Now you can safely delete environment.')
|
||||||
|
@ -128,7 +128,18 @@ Methods:
|
|||||||
- $host: $instance.ipAddresses[0]
|
- $host: $instance.ipAddresses[0]
|
||||||
- Return: $host
|
- Return: $host
|
||||||
|
|
||||||
destroy:
|
releaseResources:
|
||||||
Body:
|
Body:
|
||||||
|
# Release resources.
|
||||||
|
- $resources: new(sys:Resources)
|
||||||
|
- $template: $resources.yaml('ReleaseResources.template')
|
||||||
|
- $._environment.reporter.report($this, 'Deleting nodepool-related VMs and Images from tenant...')
|
||||||
|
- $.instance.agent.call($template, $resources)
|
||||||
|
- $.instance.releaseResources()
|
||||||
|
- $._environment.reporter.report($this, 'Done.')
|
||||||
- $.reportDestroyed()
|
- $.reportDestroyed()
|
||||||
- $.setAttr(deployed, false)
|
- $.setAttr(deployed, false)
|
||||||
|
|
||||||
|
destroy:
|
||||||
|
Body:
|
||||||
|
- $.releaseResources()
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
FormatVersion: 2.1.0
|
||||||
|
Version: 1.0.0
|
||||||
|
Name: Release resources
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
Body: |
|
||||||
|
releaseResources()
|
||||||
|
|
||||||
|
Scripts:
|
||||||
|
releaseResources:
|
||||||
|
Type: Application
|
||||||
|
Version: 1.0.0
|
||||||
|
EntryPoint: release_resources.sh
|
||||||
|
Files:
|
||||||
|
- creds
|
||||||
|
Options:
|
||||||
|
captureStdout: false
|
||||||
|
captureStderr: true
|
||||||
|
verifyExitcode: true
|
4
murano-apps/Nodepool/package/Resources/scripts/creds
Normal file
4
murano-apps/Nodepool/package/Resources/scripts/creds
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export OS_AUTH_URL=`hiera -c /etc/puppet/hiera.yaml os_auth_url`
|
||||||
|
export OS_TENANT_NAME=`hiera -c /etc/puppet/hiera.yaml os_tenant_name`
|
||||||
|
export OS_USERNAME=`hiera -c /etc/puppet/hiera.yaml os_username`
|
||||||
|
export OS_PASSWORD=`hiera -c /etc/puppet/hiera.yaml os_password`
|
28
murano-apps/Nodepool/package/Resources/scripts/release_resources.sh
Executable file
28
murano-apps/Nodepool/package/Resources/scripts/release_resources.sh
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source creds
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# Get server ids.
|
||||||
|
server_ids=$(mysql -u nodepool --password=nodepool nodepool -e 'select external_id from node' | grep -o '[-0-9a-f]\{36\}')
|
||||||
|
image_ids=$(mysql -u nodepool --password=nodepool nodepool -e 'select external_id from snapshot_image' | grep -o '[-0-9a-f]\{36\}')
|
||||||
|
|
||||||
|
# Get token and service catalog.
|
||||||
|
resp=$(curl -H "Content-Type: application/json" -X POST $OS_AUTH_URL/tokens --data '{"auth": {"tenantName": "'$OS_TENANT_NAME'", "passwordCredentials": {"username": "'$OS_USERNAME'", "password": "'$OS_PASSWORD'"}}}')
|
||||||
|
|
||||||
|
token=$(echo $resp | json_pp | grep -A15 '"token"' | sed -e '/"tenant"/,+7d' | grep '"id"' | cut -d '"' -f 4)
|
||||||
|
nova_url=$(echo $resp | json_pp | grep '8774/v2' | grep publicURL | cut -d '"' -f 4)
|
||||||
|
glance_url=$(echo $resp | json_pp | grep ':9292' | grep publicURL | cut -d '"' -f 4)
|
||||||
|
|
||||||
|
# Clean up servers.
|
||||||
|
for id in $server_ids
|
||||||
|
do
|
||||||
|
curl -X DELETE -H "X-Auth-Token: $token" $nova_url/servers/$id
|
||||||
|
done
|
||||||
|
|
||||||
|
# Clean up images.
|
||||||
|
for id in $image_ids
|
||||||
|
do
|
||||||
|
curl -X DELETE -H "X-Auth-Token: $token" $glance_url/v1/images/$id
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user