[Openstack] Guest VM IP configuration script
Satish Patel
satish.txt at gmail.com
Thu Aug 25 21:57:55 UTC 2016
This is perfect!
In your script, does it automatically query to neutron to get IP
ADDRESS of instance? or i need to manually set IP address in script
variable $IPADDR
In setup Openstack start VM and also assign IP address from allocated
pool but i want to automatically pass that IP address to script
(cloud-init or heat) whatever to set IP in instance.
On Thu, Aug 25, 2016 at 10:11 AM, Kaustubh Kelkar
<kaustubh.kelkar at casa-systems.com> wrote:
> Here is a heat template that I use (the indentation might be off). I have one network with DHCP enabled that connects to metadata server:
>
> heat_template_version: 2015-04-30
>
> parameters:
> mgmt:
> type: json
> description: ID of the mgmt network
> default: { "name": "mgmt" ,
> "id": "abcd1234" }
>
> no_dhcp_net:
> type: string
> default: "wxyz6789"
>
> resources:
> server:
> type: OS::Nova::Server
> properties:
> name:test-vm
> image: ubuntu-16.04
> flavor: m1.small
> networks:
> - network: { get_param: [ mgmt, id ] }
> - port: { get_resource: server_port }
> user_data_format: RAW
> user_data:
> str_replace:
> template: |
> #!/bin/bash
> echo -e "\n" >> /etc/network/interfaces
> echo "auto ens4" >> /etc/network/interfaces
> echo "iface ens4 inet static" >> /etc/network/interfaces
> echo "address $IPADDR" >> /etc/network/interfaces
> echo "netmask 255.255.255.0" >> /etc/network/interfaces
> ifdown ens4 2>/dev/null
> ifup ens4 2>/dev/null
> params:
> $IPADDR: { get_attr: [ server_port, fixed_ips, 0, ip_address ] }
>
> server_port:
> type: OS::Neutron::Port
> properties:
> network_id: { get_param: no_dhcp_net }
>
> outputs:
> dump:
> value: { get_attr: [ server, show ] }
>
>
> Hope this helps.
>
> As for config-drive, I hope the folks can shed some light.
>
>
> -Kaustubh
>
>> -----Original Message-----
>> From: Satish Patel [mailto:satish.txt at gmail.com]
>> Sent: Thursday, August 25, 2016 9:27 AM
>> To: Eugen Block <eblock at nde.ag>
>> Cc: openstack <openstack at lists.openstack.org>
>> Subject: Re: [Openstack] Guest VM IP configuration script
>>
>> Eugen,
>>
>> I think config-drive make sense when you don't have initial network in place. In
>> my case i don't care about fixed-IP for instance. I only need to setup network
>> using whatever IP neutron provide in that case how do i query neutron port to
>> find out what IP address is available or neutron going to provide so i can take
>> that information and pass to userdata. Its sounds tricky any idea how to do that?
>>
>> On Thu, Aug 25, 2016 at 2:53 AM, Eugen Block <eblock at nde.ag> wrote:
>> > Hi,
>> >
>> > we've been trying to learn how to feed cloud-init with ip addresses,
>> > too. If DHCP is disabled in your network, the instance won't get it's
>> > eth0 configured and won't be able to query the metadata server.
>> > Creating a port before attaching it to a booting instance also doesn't
>> > work if no dhcp is running on that network, I just tried that to be sure.
>> >
>> > I've tried several ways but I only found one working option. For
>> > external networks (or networks without dhcp) we are using config-drive
>> > now. Depending on the OpenStack version it could be possible that
>> > you'll need cloud-init-0.7.7, we had to fix two issues ourselves in
>> > version 0.7.6 to get it working, one of them was a missing default route.
>> >
>> > With enabled config-drive the instance doesn't need a configured
>> > interface, it's a temporarily mounted drive from where the required
>> > information is read by cloud-init.
>> > You can either add the option "--config-drive true" in your nova boot
>> > call or check the checkbox in Horizon.
>> >
>> > To answer your question about ports, you can create a new port either
>> > in Horizon, but there you won't be able to assign a specific ip
>> > address. If you want a specific ip address you have to call neutron
>> > port-create (port-name is optional):
>> >
>> > neutron port-create <NETWORK-ID> --fixed-ip
>> > subnet_id=<SUBNET-ID>,ip_address=<IP> --name <PORT-NAME>
>> >
>> > The resulting ID of that port can be used in nova boot call:
>> >
>> > nova boot --flavor 2 --image <IMAGE> --nic port-id=<PORT-ID>
>> > <INSTANCE-NAME>
>> >
>> > Another way to assign a specific ip address to a booting instance
>> > without port-creation (but DHCP has to be enabled) would be:
>> >
>> > nova boot --flavor 2 --image <IMAGE> --nic
>> > net-id=<NET-ID>,v4-fixed-ip=<IP> <INSTANCE-NAME>
>> >
>> > for example:
>> > nova boot --flavor 2 --image dc05b777-3122-4021-b7eb-8d96fdab2980
>> > --nic
>> > net-id=4421e160-d675-49f2-8c29-9722aebf03b2,v4-fixed-ip=192.168.124.6
>> > test1
>> >
>> > Hope this helps!
>> >
>> >
>> > Zitat von Satish Patel <satish.txt at gmail.com>:
>> >
>> >
>> >> My question is how to query ports and pass info to cloud-init? is
>> >> there any document or api which i can call using script and setup
>> >> network ifcfg-eth0 file
>> >>
>> >> On Wed, Aug 24, 2016 at 5:38 PM, Kaustubh Kelkar
>> >> <kaustubh.kelkar at casa-systems.com> wrote:
>> >>>
>> >>> You can create the ports beforehand and plug them in while creating
>> >>> the instance. As for assigning IP addresses, you can query the ports
>> >>> and pass the information to cloud-init. I am not sure if there is
>> >>> any other way to do this.
>> >>>
>> >>> Even if DHCP is disabled, OpenStack assigns IP information to ports
>> >>> when a VM is created, and you can see this in your dashboard. The
>> >>> MAC and IP information is used to configure iptables rules within
>> >>> security groups. Here is the archived thread that provides this information:
>> >>> http://lists.openstack.org/pipermail/openstack-dev/2014-
>> December/053069.html.
>> >>>
>> >>>
>> >>> -Kaustubh
>> >>>
>> >>>> -----Original Message-----
>> >>>> From: Satish Patel [mailto:satish.txt at gmail.com]
>> >>>> Sent: Wednesday, August 24, 2016 5:05 PM
>> >>>> To: James Downs <egon at egon.cc>
>> >>>> Cc: openstack <openstack at lists.openstack.org>
>> >>>> Subject: Re: [Openstack] Guest VM IP configuration script
>> >>>>
>> >>>> I am using neutron networking with vlan ( its provider VLAN). We
>> >>>> are not using DHCP but i need some kind of hack to inject IP
>> >>>> address in instance using
>> >>>> cloud-
>> >>>> init.
>> >>>>
>> >>>> We are using cloud-init but i don't know how does it work and get
>> >>>> IP from neutron. I am new with neutron stuff.
>> >>>>
>> >>>> On Wed, Aug 24, 2016 at 4:29 PM, James Downs <egon at egon.cc> wrote:
>> >>>> > On Wed, Aug 24, 2016 at 03:25:26PM -0400, Satish Patel wrote:
>> >>>> >> I enabled following in nova.conf on compute node but didn't work
>> >>>> >> :(
>> >>>> >>
>> >>>> >> flat_injected=true
>> >>>> >>
>> >>>> >> Do i need to do anything else?
>> >>>> >
>> >>>> > Are you using flat networking?
>> >>>> > Nova-networks or Neutron?
>> >>>> >
>> >>>> > At this point, if you're not using DHCP, your only option is to
>> >>>> > arrange to feed
>> >>>> the networking information into the metadata for the VM at creation
>> >>>> time, and use someting like cloud-init to configure the networking.
>> >>>> The ancient networking injection stuff has either been removed, or
>> >>>> been broken for years.
>> >>>> >
>> >>>> > Cheers,
>> >>>> > -j
>> >>>> >
>> >>>> > _______________________________________________
>> >>>> > Mailing list:
>> >>>> > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> >>>> > Post to : openstack at lists.openstack.org
>> >>>> > Unsubscribe :
>> >>>> > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> >>>>
>> >>>> _______________________________________________
>> >>>> Mailing list:
>> >>>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> >>>> Post to : openstack at lists.openstack.org
>> >>>> Unsubscribe :
>> >>>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> >>
>> >>
>> >> _______________________________________________
>> >> Mailing list:
>> >> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> >> Post to : openstack at lists.openstack.org
>> >> Unsubscribe :
>> >> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> >
>> >
>> >
>> >
>> > --
>> > Eugen Block voice : +49-40-559 51 75
>> > NDE Netzdesign und -entwicklung AG fax : +49-40-559 51 77
>> > Postfach 61 03 15
>> > D-22423 Hamburg e-mail : eblock at nde.ag
>> >
>> > Vorsitzende des Aufsichtsrates: Angelika Mozdzen
>> > Sitz und Registergericht: Hamburg, HRB 90934
>> > Vorstand: Jens-U. Mozdzen
>> > USt-IdNr. DE 814 013 983
>> >
>> >
>> >
>> > _______________________________________________
>> > Mailing list: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> > Post to : openstack at lists.openstack.org
>> > Unsubscribe :
>> > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>>
>> _______________________________________________
>> Mailing list: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>> Post to : openstack at lists.openstack.org
>> Unsubscribe : http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
More information about the Openstack
mailing list