OpenStack: placement (resource provider)

Install CLI client
https://docs.openstack.org/releasenotes/osc-placement/

pip install openstack-placement
 
echo 3.5.6 > .python-version

resource provider allocation

# list hypervisor
openstack resource provider list --sort-column name
 
# show
openstack resource provider allocation show ${SERVER_ID}
 
# delete
openstack resource provider allocation delete ${SERVER_ID}

Check multiple / broken resource provider allocation

for SERVER_ID in $(openstack server list --all -c ID -f value); do
    HYPERVISOR_HOSTNAME=$(openstack server show ${SERVER_ID} -c OS-EXT-SRV-ATTR:hypervisor_hostname -f value)
    RESOURCE_PROVIDER=$(openstack resource provider allocation show ${SERVER_ID} -c resource_provider -f value)
 
    # openstack resource provider list -c uuid -c name -f value
    case ${RESOURCE_PROVIDER} in
        bcf1cfcc-0b97-43e1-bb09-1bfd64ebc4fa) RESOURCE_PROVIDER_NAME=com1-stage.example.com;;
        231bd9d5-be18-4466-9865-923f463cd378) RESOURCE_PROVIDER_NAME=com2-stage.example.com;;
        b9e37e4a-28cf-4f63-bcdd-6463a7828b04) RESOURCE_PROVIDER_NAME=com3-stage.example.com;;
    esac
 
    if [ "${HYPERVISOR_HOSTNAME}" != "${RESOURCE_PROVIDER_NAME}" ]; then
        echo "SERVER_ID: ${SERVER_ID}"
        echo "HYPERVISOR_HOSTNAME: ${HYPERVISOR_HOSTNAME}"
        echo "RESOURCE_PROVIDER_NAME: ${RESOURCE_PROVIDER_NAME}"
        echo
    fi
done

Remove double allocation

# get RESOURCE_PROVIDER_ID
openstack resource provider allocation show ${SERVER_ID} -c resource_provider
 
# delete double RESOURCE_PROVIDER_ID
openstack resource provider allocation unset --provider ${RESOURCE_PROVIDER_ID} ${SERVER_ID} --os-placement-api-version 1.12

Delete

openstack catalog list | grep placement
PLACEMENT_ENDPOINT=placement-endpoint-returned-by-previous-command
 
TOKEN=$(openstack token issue -f value -c id)
 
curl ${PLACEMENT_ENDPOINT}/resource_providers -H "x-auth-token: $TOKEN" | python -m json.tool
 
# show allocations
openstack resource provider list
RESOURCE_PROVIDER_UUID=f4984285-2562-4210-99d2-2ee5f72d968f
curl -s -H "X-Auth-Token: ${TOKEN}" "${PLACEMENT_ENDPOINT}/resource_providers/${RESOURCE_PROVIDER_UUID}/allocations" | python -m json.tool
 
openstack resource provider allocation delete 4044e24b-099b-444a-863a-f14c0287d85b
 
# remove resource provider
UUID=uuid-of-resource-provider-named-openstack
curl ${PLACEMENT_ENDPOINT}/resource_providers/$UUID -H "x-auth-token: $TOKEN" -X DELETE

Links
https://docs.openstack.org/osc-placement/latest/cli/index.html