# Delete Orphaned Allocations Using Nova-Manage

## Issue

* When an instance is deleted/migrated/evacuated, sometimes its corresponding allocation on the source host is not deleted from placement, and they remain stale.

## Resolution

* Query the placement API to list all the stale allocations. The command below will list allocations for instances that are either deleted or moved to other compute nodes. Run the below command from any one compute node.

{% tabs %}
{% tab title="Command" %}

```bash
$ kubectl exec -it deploy/nova_api_osapi -n <NS> -- bash
$ nova-manage placement audit --verbose
```

{% endtab %}
{% endtabs %}

* Verify if the instance exists or is on another compute node.

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack server list --all-projects --host <SOURCE_HOST>
$ openstack server show -c OS-EXT-SRV-ATTR:host <INSTANCE_UUID>
```

{% endtab %}
{% endtabs %}

* Identify the resource provider ID

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack resource provider list
//For Specific VM check
$ openstack resource provider allocation show <INSTANCE_UUID>
```

{% endtab %}
{% endtabs %}

* After validating that the allocation is stale and the instance is deleted or moved to another compute node, delete the orphaned allocation using the command below.

{% tabs %}
{% tab title="Command" %}

```bash
$  kubectl exec -it <nova_api_osapi-pod_name> -n <NS> -- bash
$  nova-manage placement audit --verbose --delete <INSTANCE_UUID>
```

{% endtab %}
{% endtabs %}

* If there are multiple orphaned allocations, delete them altogether with the command below.

```bash
$ kubectl exec -it deploy/nova_api_osapi -n <NS> -- bash
$ nova-manage placement audit --verbose --delete
```

* After running above we can run a heal allocations for placement to ensure that all placement entries are consistent

{% tabs %}
{% tab title="Command" %}

```bash
$ kubectl exec -it deploy/nova_api_osapi -n <NS> -- bash
$ nova-manage placement heal_allocations
```

{% endtab %}
{% endtabs %}

* To validate that there are no more orphaned allocations, please run the command

{% tabs %}
{% tab title="Command" %}

```bash
$ kubectl exec -it deploy/nova_api_osapi -n <NS> -- bash
$ nova-manage placement audit --verbose
```

{% endtab %}
{% endtabs %}

## Root Cause

* When evacuating an instance, if the compute service on the source host is stopped, then the records in placement are not deleted automatically.
* As a result, `ostackhost` service cannot communicate with the nova-conductor service running on the control plane, so details are not shared there, and it results in nova-compute remaining in an impression that still holds the instance.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform9.com/kb/pcd-ts/host/delete-orphaned-allocations-using-nova-manage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
