Automatic OS IP assignment. What do I need to make this happen?

Hi All,

Is it possible to get ON to automatically assign an IP to the OS (similar to cloud-init) ?

Tried. Not able to get that quite right. VM instances show an IP has been assigned to the profile but it’s not assigned on the guest VM.

Ideally, I’m looking for a solution whereby I run my own tool to look for a free IP on my network and assign it. ON’s approach appears sequential as seen from the UI. This is good for a free range, but I need something more dynamic.

Cheers,

Hi All,

“Tried. Not able to get that quite right. VM instances show an IP has been assigned to the profile but it’s not assigned on the guest VM.”

I’ve solved the first part above. I would like to find out if there is a way to modify the OneGate and OneGate Context logic to include the running off a custom script responsible for selecting a free IP. Is there such a way built-in?

Thx,
TK

I’m looking for something along the lines of a plugin system such as the following:

  1. Define a variable such as EXT_IP_ASSIGN = “yes” followed by EXT_IP_ASSIGN_CMD = “/path/to/my/ip-script.sh”

  2. Above returns an IP from a subnet which already has preallocated IP’s for other servers. How I determine the available IP would be up to me.

Thx,

Hi,

I’d guess you’ve followed Open Cloud Contextualization ?

I think that instead of looking how to alter the OneGate service you should to take a look at the IPAM Driver. Just for a refence/ideas/ you could take a look at the Included driver for Packet.

Hope this helps.

Best Regards,
Anton Todorov

Hi,

I’d guess you’ve followed Open Cloud Contextualization ?

Correct.

I think that instead of looking how to alter the OneGate service you should to take a look at the IPAM Driver. Just for a refence/ideas/ you could take a look at the Included driver for Packet.

That looks very promising. I’ll take a look and get back to you if it meets our needs. Thank you!

Hope this helps.

Best Regards,
Anton Todorov

Hey Anton,

I’m revisiting this topic.

Given this:

[root@one01 dummy]# ls -altri
total 32
202709534 -rwxr-xr-x. 1 oneadmin oneadmin 2287 Sep 24 09:59 unregister_address_range
202709533 -rwxr-xr-x. 1 oneadmin oneadmin 4666 Sep 24 09:59 register_address_range
202709532 -rwxr-xr-x. 1 oneadmin oneadmin 4249 Sep 24 09:59 get_address
202709531 -rwxr-xr-x. 1 oneadmin oneadmin 3768 Sep 24 09:59 free_address
202709530 -rwxr-xr-x. 1 oneadmin oneadmin 3866 Sep 24 09:59 allocate_address
202709529 drwxr-x---. 2 oneadmin oneadmin 4096 Nov  3 19:37 .
134569729 drwxr-x---. 4 oneadmin oneadmin   31 Nov  3 19:37 ..
[root@one01 dummy]# pwd
/var/lib/one/remotes/ipam/dummy
[root@one01 dummy]# cd ..
[root@one01 ipam]# ls -altri
total 12
202709529 drwxr-x---.  2 oneadmin oneadmin 4096 Nov  3 19:37 dummy
134569729 drwxr-x---.  4 oneadmin oneadmin   31 Nov  3 19:37 .
   635507 drwxr-x---.  2 oneadmin oneadmin 4096 Nov  3 19:37 packet
134569666 drwxr-x---. 13 oneadmin oneadmin 4096 Nov  3 19:37 ..
[root@one01 ipam]#

and the above two pages, I’m free to write any code in any language as long as it has the following components?

allocate_address  
free_address  
get_address  
register_address_range  
unregister_address_range

In my case, my VLAN has randomly allocated addressed and I don’t know ahead of time what these could be. In that respect I can only define the top three (perhaps) to get and free single addresses. To that end, have the following questions:

  1. Will the plugin system break or have issues if I don’t define all the functions in my code?

  2. I need to return a single IP address to register a VM with and unregister the IP when VM is disposed of. There will be a VLAN (subnet) to choose from that I could pass but it will represent randomly allocated IP’s. How will this look like if I want to reserve a single IP and free a single IP.

  3. Does the plugin system support calling subscripts as root to automatically register the environment with said IP to the DNS?

Thx,
TK

Hello @TomK

1 - You have to define all the functions, but if one of them has to be empty, just put exit 0.
2 - With allocate script you can just allocate one IP, see comments in this file. Just use size 1 and it will allocate just one IP.
3 - Yes, you can call all the scripts you want, but remember that the main script has to return the needed information by OpenNebula, you can find this information here.

1 - Ok

2 - So I’m thinking something like this then for say the get_address script as an example. Assuming a range of 10.0.0.1/24 is available but half of the IP’s are used randomly within this subnet. So my script should accept an XML message like this then it determines a free IP available on this subnet:

<IPAM_DRIVER_ACTION_DATA>
<AR>
  <TYPE>IP4</TYPE>
  <IP>10.0.0.117</IP>
  <MAC>AA:BB:CC:DD:EE:FF:00:01</MAC
  <SIZE>1</SIZE>
  <NETWORK_ADDRESS>10.0.0.117</NETWORK_ADDRESS>
  <NETWORK_MASK>255.255.255.0</NETWORK_MASK>
  <GATEWAY>10.0.0.1</GATEWAY>
  <DNS>192.168.0.1 192.168.0.2 192.168.0.3</DNS>
  <GUEST_MTU>1500</GUEST_MTU>
  <SEARCH_DOMAIN>dom.com sub.dom.com new.dom.com</SEARCH_DOMAIN>
</AR>
</IPAM_DRIVER_ACTION_DATA>

The script should then return:

ADDRESS = [ IP = "10.0.0.117", SIZE=1 ]

to STDOUT. And also return -1 if it fails to allocate, otherwise it must exit 0.

3 - Great!

Cheers,
TK

Hi

A few more questions if I may please.

  1. Are the above assumptions I posted correct?

Additional questions:

  1. Which IPAM module does OpenNebula use right now? The list on my install has the following: dummy, packet. Does it use the packet IPAM module to allocate right now or an internal system not exposed via IPAM?

  2. Looking at the existing ipam module packet code for register_address_range, there is code that instantiates objects from OpenNebula, decrypts a few elements from the first parameter passed ARGV[0], which is the XML input message, from Base64 using nokogiri, retrieves ONE_KEY from the object. It then get’s a PACKET_TOKEN from the passed ARGV[0] parameter, which is not mentioned on the docs page. Should I care about all this or just focus on what the docs page has? The reason is I need to do this in bash and in case I need higher-level functions to interact with OpenNebula objects or perform API calls, I may need to go the python route. Are there examples of ipam modules in bash or python I can use as examples and extend for my purpose?

Thx,
TK

Hello @TomK

  1. Are the above assumptions I posted correct?

Yes, they are correct.

4- Yes, currently only dummy and Packet are available. The Packet IPAM is used in VMs deployed on baremetal Packet host so they get public connectivity.

5 - In the new version (5.10) you don’t need to decrypt anything, it’s done in the core using the ENCRYPTED_ATTR. PACKET_TOKEN is needed by Packet, so you don’t need this token. We don’t have examples in Python, but of course you can use it, the only thing is to respect the inputs and outputs.

Álex.

Thank you very much. Let me give these a try this weekend.