2 #######################################################################################
3 # Copyright ETSI Contributors and Others.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #######################################################################################
19 # Delete a VM and its resources (nic, disk, nsg, public IP) on Azure.
20 # To do this it reads the following environment variables:
21 # - VM_NAME: name of the VM
22 # - RESOURCE_GROUP: name of the resource-group where the VM is
23 function delete_azure_vm
{
25 INTERFACE_ID
=$
(az vm show
--resource-group ${RESOURCE_GROUP} --name ${VM_NAME} --query networkProfile.networkInterfaces
[0].id
)
26 INTERFACE_ID
=${INTERFACE_ID:1:-1}
27 OS_DISK_ID
=$
(az vm show
--resource-group ${RESOURCE_GROUP} --name ${VM_NAME} --query storageProfile.osDisk.managedDisk.id
)
28 OS_DISK_ID
=${OS_DISK_ID:1:-1}
29 SECURITY_GROUP_ID
=$
(az network nic show
--id ${INTERFACE_ID} --query networkSecurityGroup.id
)
30 SECURITY_GROUP_ID
=${SECURITY_GROUP_ID:1:-1}
31 PUBLIC_IP_ID
=$
(az network nic show
--id ${INTERFACE_ID} --query ipConfigurations
[0].publicIpAddress.id
)
32 PUBLIC_IP_ID
=${PUBLIC_IP_ID:1:-1}
33 az vm delete
--resource-group ${RESOURCE_GROUP} --name ${VM_NAME} --yes
34 az network nic delete
--id ${INTERFACE_ID}
35 az disk delete
--id ${OS_DISK_ID} --yes
36 az network nsg delete
--id ${SECURITY_GROUP_ID}
37 if [ -n "${PUBLIC_IP_ID}" ]; then
38 az network public-ip delete
--id ${PUBLIC_IP_ID}
43 # To do this it reads the following environment variables:
44 # - VM_NAME: name of the VM
45 # - GCP_PROJECT: name of project where the VM is
46 # - GCP_ZONE: name of the zone
47 function delete_gcp_vm
{
48 gcloud compute instances delete
"${VM_NAME}" --project="${GCP_PROJECT}" --zone="${GCP_ZONE}" --delete-disks all
-q
51 if [ -n "${1:-}" ]; then # If there is an argument, it must be the hostname
54 VM_NAME
="${OSM_IMAGE_NAME}"
57 # Branch by CLOUD_TYPE value ("azure", "gcp")
58 if [ "${CLOUD_TYPE}" == "azure" ]; then
61 elif [ "${CLOUD_TYPE}" == "gcp" ]; then
65 echo "Invalid cloud type: ${CLOUD_TYPE}"