Blog Viewer

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

By Erdem posted 08-13-2015 16:07


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/", line

84, in resource

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

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

432, in delete

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


"/usr/lib/python2.7/dist-packages/neutron/plugins/juniper/contrail/contrail", line 294, in delete_network

    raise e

RefsExistError: Back-References from

http: //


http: //

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:








href:"http: //example-node:8082/virtual-machine/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: // 

Children http: // still exist



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


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


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/", 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/", 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