SDN
SDN

How-To: Remove stale virtual machines (VMs) and virtual machine interfaces (VMIs)

by Cordelia on ‎08-13-2015 04:07 PM - edited on ‎09-19-2017 10:16 AM by Administrator Administrator (1,368 Views)

Remove Stale VMs and VMIs

 

Before you can remove a stale virtual machine (VM) or virtual machine interface (VMI), you must first remove any back references associated to the VM or VMI.


Problem Example

 

A net-delete of the virtual machine 2a8120ec-bd18-49f4-aca0-acfc6e8fe74f returned the following messages that there are two VMIs that still have back-references to the stale VM. You must first delete the two VMIs, then the neutron net-delete <> command will complete without errors.

 

 

From neutron.log:

2014-03-10 14:18:05.208    

DEBUG [urllib3.connectionpool]

"DELETE/virtual-network/2a8120ec-bd18-49f4-aca0-acfc6e8fe74f HTTP/1.1" 409 203

2014-03-10 14:18:05.278    

ERROR [neutron.api.v2.resource] delete failed

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/neutron/api/v2/resource.py", line

84, in resource

    result = method(request=request, **args)

  File "/usr/lib/python2.7/dist-packages/neutron/api/v2/base.py", line

432, in delete

    obj_deleter(request.context, id, **kwargs)

  File

"/usr/lib/python2.7/dist-packages/neutron/plugins/juniper/contrail/contrail

plugin.py", line 294, in delete_network

    raise e

RefsExistError: Back-References from

http: //127.0.0.1:8082/virtual-machine-interface/51daf6f4-7366-4463-a819-bd1

17fe3a8c8,

http: //127.0.0.1:8082/virtual-machine-interface/30882e66-e175-4fbb-862e-354

bb700b579 still exist

 

Show Virtual Machines

 

Use the following command to show all virtual machines known to the Contrail API server. Replace the variable <config-node-IP> (example-node) with the IP address of the config-node in your setup:

http://<config-node-IP>:8082/virtual-machines

 

Example:

 

virtual-machines:

[

{

href:"http: //example-node:8082/virtual-machine/03443891-99cc-4784-89bb-9d1e045f8aa6",

fq_name:

[

"03443891-99cc-4784-89bb-9d1e045f8aa6"

],

uuid:"03443891-99cc-4784-89bb-9d1e045f8aa6"

},

In the example, 03443891-99cc-4784-89bb-9d1e045f8aa6 is a stale VM that you need to remove.


When you attempt to delete the stale VM, a message displays that children to the VM still exist:

 

root@example-node:~# curl -X DELETE -H "Content-Type: application/json; charset=UTF-8" http: //127.0.0.1:8082/virtual-machine/03443891-99cc-4784-89bb-9d1e045f8aa6 

Children http: //127.0.0.1:8082/virtual-machine-interface/0c32a82a-7bd3-46c7-b262-6d85b9911a0d still exist

root@example-node:~# 

 

Open http://example-node:8082/virtual-machine/03443891-99cc-4784-89bb-9d1e045f8aa6, and you see a virtual-machine-interface (VMI) attached to it. You must remove this VMI first.

 

However, when you attempt to delete the VMI from the stale VM, you receive a message that there is still a back-reference:

 

root@example-node:~# curl -X DELETE -H "Content-Type: application/json; charset=UTF-8" http: //<example-IP>:8082/virtual-machine-interface/0c32a82a-7bd3-46c7-b262-6d85b9911a0d
Back-References from http: //<example-IP>:8082/instance-ip/6ffa29a1-023f-462b-b205-353da8e3a2a4 still exist
root@example-node:~#

 

Because there is a back-reference from an instance-ip object still present, you must first delete the instance-ip object as follows:

 

root@example-node:~# curl -X DELETE -H "Content-Type: application/json; charset=UTF-8" http: //<example-IP>:8082/instance-ip/6ffa29a1-023f-462b-b205-353da8e3a2a4
root@example-node:~# 

 

After you delete the instance-ip object, you can delete the VMI and the VM.

NOTE: To prevent inconsistency, be sure that the VM is NOT present in the nova db before deleting the VM.

 

Show Virtual Machines Using Python API

 

The following example shows how to view virtual machines using a Python API. This example shows virtual machines and back-references. Once you identify back-references and existing children, you can delete them first, then delete the stale VM:

 
root@example-node:~# source /opt/contrail/api-venv/bin/activate
(api-venv)root@example-node:~# pythonPython 2.7.5 (default, Mar 10 2014, 03:55:35) [GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> from vnc_api.vnc_api import VncApi>>> vh=VncApi()>>> vh.virtual_machine_interface_delete(id='0c32a82a-7bd3-46c7-b262-6d85b9911a0d')Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/opt/contrail/api-venv/lib/python2.7/site-packages/vnc_api/gen/vnc_api_client_gen.py", line 3793, in virtual_machine_interface_delete    content = self._request_server(rest.OP_DELETE, uri)  File "/opt/contrail/api-venv/lib/python2.7/site-packages/vnc_api/vnc_api.py", line 342, in _request_server    raise RefsExistError(content)cfgm_common.exceptions.RefsExistError: Back-References from http: // <example-IP>:8082/instance-ip/6ffa29a1-023f-462b-b205-353da8e3a2a4 still exist
>>> 

 

Delete Methods 

 

Use help (vh) to show all delete methods supported.


Typical commands for deleting VMs and VMIs include:

 

  • virtual_machine_delete() to delete a virtual machine
  • instance_ip_delete() to delete an instance-ip