Assign floating IP to instance through REST API

Asked by Andrey Sereda

Hello All!

I've spent last 2 days trying to find a simple solution for the following problem: how could I assign floating IP I have created to the running instance on OpenStack through REST API? I can do this through web ui (dashboard) or through nova tool, but I need it through REST API.
I have been using this page (http://api.openstack.org/) and I was able to find how to list floating ips, allocate new or deallocate existing, but unfortunatelly it does not answer my question.

Many thanks for your help!

Question information

Language:
English Edit question
Status:
Solved
For:
OpenStack Compute (nova) Edit question
Assignee:
No assignee Edit question
Solved by:
John Garbutt
Solved:
Last query:
Last reply:
Revision history for this message
Best John Garbutt (johngarbutt) said :
#1

While not definitive, you can look at the example in devstack:
https://github.com/openstack-dev/devstack/blob/master/exercises/floating_ips.sh#L165

if you try that command with --debug it will give you all the raw requests that it made.

Looking at the code, you can see the floating ip call here:
https://github.com/openstack/python-novaclient/blob/master/novaclient/v1_1/shell.py#L1326

That points towards this code:
https://github.com/openstack/python-novaclient/blob/master/novaclient/v1_1/servers.py#L329
def add_floating_ip(self, server, address):
        """
        Add a floating ip to an instance
        :param server: The :class:`Server` (or its ID) to add an IP to.
        :param address: The FloatingIP or string floating address to add.
        """
        address = address.ip if hasattr(address, 'ip') else address
        self._action('addFloatingIp', server, {'address': address})

It can be compared to the ones that are better documented:
https://github.com/openstack/python-novaclient/blob/master/novaclient/v1_1/servers.py#L562

Looks like the doc should say something like:
v2/{tenant_id}/servers/{server_id}/action and specify the addFloatingIp action

Revision history for this message
Andrey Sereda (andrey-sereda-kharkiv) said :
#2

Hi John, thanks a lot, it worked brilliantly!

POST to v2/{tenant_id}/servers/{server_id}/action

XML:
<addFloatingIp>
    <address>ip_here</address>
</addFloatingIp>

Revision history for this message
Andrey Sereda (andrey-sereda-kharkiv) said :
#3

Thanks John Garbutt, that solved my question.