How to assign fixed-ip to an instance while launch

Asked by Gaurav Gupta

AFAIU In Diablo a new feature got added so that I can specify the fixed IP address at the time I launch an instance. How do I use this feature? I see that in novaclient, there is a command "nova add-fixed-ip <server> <network_id>". Its this related?

I am using FlatDHCPManager

Here is the feature that I am referring to:
https://blueprints.launchpad.net/nova/+spec/add-options-network-create-os-apis

Question information

Language:
English Edit question
Status:
Solved
For:
OpenStack Compute (nova) Edit question
Assignee:
No assignee Edit question
Solved by:
Gaurav Gupta
Solved:
Last query:
Last reply:
Revision history for this message
Sharif Islam (islamsh) said :
#1

I haven't got a change to test the latest diablo. But could get it work diablo3. In nova.conf, you have to add:

--auto_assign_floating_ip=true

Revision history for this message
Gaurav Gupta (gagupta) said :
#2

@Sharif: Thanks for your help, but I am looking to assign a fixed-ip when I launch an instance not floating-ip.

I got the answer in an email. Posting it here as the answer:

"""
Let me explain you a bit about how to use the modified OS Create Server API:

Added new optional parameter "networks" to the Create Server API

"networks" : [
        { "uuid": "31fff79e-6405-48e4-bf40-d3334579dc76", "fixed_ip": "10.0.1.3"},
        { "uuid": "f6152e91-e7d6-4e9c-a435-e5d910e327bd", "fixed_ip": "10.0.2.3"}
]

uuid: The unique identifier of the network

fixed_ip: IP address to be assigned to the NIC. This IP address should belong to the CIDR range of the specified network. If you don’t specify fixed_ip, then it will assign free available IP address to the Nic from the specified network.

Note: networks parameter is an optional parameter, if you don’t specify networks parameter it will behave similar as you see in Cactus release (i.e. it will create number of nics equal to the number of the networks assigned to the project)

API URL :- POST http://<api address>/v1.1/<project_id>/os-create-server-ext

XML Request Format:
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
        name="new-server-test" flavorRef="1"
        imageRef="46">
  <metadata>
    <meta key="My Server Name">Apache1</meta>
  </metadata>
<personality/>
<networks>
      <network uuid="31fff79e-6405-48e4-bf40-d3334579dc76" fixed_ip="10.0.1.3">
      <network uuid="f6152e91-e7d6-4e9c-a435-e5d910e327bd" fixed_ip="10.0.2.3">
  </networks>
</server>

JSON Request format
{
    "server" : {
        "name": "new-server-test",
        "flavorRef": "1",
        "imageRef": "46",
        "metadata": {
                 "My Server Name": "Apache1"
            },
         "networks": [
                        {
                          "uuid":"31fff79e-6405-48e4-bf40-d3334579dc76", "fixed_ip": "10.0.1.3"
                        },
                       {
                          "uuid": "f6152e91-e7d6-4e9c-a435-e5d910e327bd","fixed_ip": "10.0.2.3"
                        }
           ]
    }
}

You can find the uuid of the network when you use the network list command.

Thanks and Best Regards,
Tushar Patil.
"""

Revision history for this message
Vish Ishaya (vishvananda) said :
#3

Assuming you are using the newest ubuntu packages, you may also want to enable the following flag:
--force_dhcp_release

This will kill dhcp leases when terminating an instance so that you can immediately reuse the ip.

Vish

On Sep 27, 2011, at 1:01 PM, Gaurav Gupta wrote:

> Question #172158 on OpenStack Compute (nova) changed:
> https://answers.launchpad.net/nova/+question/172158
>
> Status: Answered => Solved
>
> Gaurav Gupta confirmed that the question is solved:
> @Sharif: Thanks for your help, but I am looking to assign a fixed-ip
> when I launch an instance not floating-ip.
>
> I got the answer in an email. Posting it here as the answer:
>
> """
> Let me explain you a bit about how to use the modified OS Create Server API:
>
> Added new optional parameter "networks" to the Create Server API
>
> "networks" : [
> { "uuid": "31fff79e-6405-48e4-bf40-d3334579dc76", "fixed_ip": "10.0.1.3"},
> { "uuid": "f6152e91-e7d6-4e9c-a435-e5d910e327bd", "fixed_ip": "10.0.2.3"}
> ]
>
> uuid: The unique identifier of the network
>
> fixed_ip: IP address to be assigned to the NIC. This IP address should
> belong to the CIDR range of the specified network. If you don’t specify
> fixed_ip, then it will assign free available IP address to the Nic from
> the specified network.
>
> Note: networks parameter is an optional parameter, if you don’t specify
> networks parameter it will behave similar as you see in Cactus release
> (i.e. it will create number of nics equal to the number of the networks
> assigned to the project)
>
> API URL :- POST http://<api address>/v1.1/<project_id>/os-create-server-
> ext
>
> XML Request Format:
> <?xml version="1.0" encoding="UTF-8"?>
> <server xmlns="http://docs.openstack.org/compute/api/v1.1"
> name="new-server-test" flavorRef="1"
> imageRef="46">
> <metadata>
> <meta key="My Server Name">Apache1</meta>
> </metadata>
> <personality/>
> <networks>
> <network uuid="31fff79e-6405-48e4-bf40-d3334579dc76" fixed_ip="10.0.1.3">
> <network uuid="f6152e91-e7d6-4e9c-a435-e5d910e327bd" fixed_ip="10.0.2.3">
> </networks>
> </server>
>
> JSON Request format
> {
> "server" : {
> "name": "new-server-test",
> "flavorRef": "1",
> "imageRef": "46",
> "metadata": {
> "My Server Name": "Apache1"
> },
> "networks": [
> {
> "uuid":"31fff79e-6405-48e4-bf40-d3334579dc76", "fixed_ip": "10.0.1.3"
> },
> {
> "uuid": "f6152e91-e7d6-4e9c-a435-e5d910e327bd","fixed_ip": "10.0.2.3"
> }
> ]
> }
> }
>
> You can find the uuid of the network when you use the network list
> command.
>
> Thanks and Best Regards,
> Tushar Patil.
> """
>
> --
> You received this question notification because you are a member of Nova
> Core, which is an answer contact for OpenStack Compute (nova).

Revision history for this message
Gaurav Gupta (gagupta) said :
#4

Thanks for the tip Vish.