[ovirt-users] cloud-init options under python-sdk

Amedeo Salvati amedeo at oscert.net
Tue Jul 22 13:50:58 UTC 2014


many thanks Juan it works!

best regards
a



Da: "Juan Hernandez" jhernand at redhat.com
A: "Amedeo Salvati" amedeo at oscert.net, users at ovirt.org
Cc: 
Data: Tue, 22 Jul 2014 15:32:45 +0200
Oggetto: Re: [ovirt-users] cloud-init options under python-sdk


> On 07/22/2014 02:55 PM, Amedeo Salvati wrote:
> > hi Juan|guys,
> > 
> > thanks for hints! but unfortunatly it seems wont works, because I've
> > launched vm with this simple code:
> > 
> > action =
> > params.Action(vm=params.VM(initialization=params.Initialization(cloud_init=params.CloudInit(host=params.Host(name="rheltest014")))))
> > vm.start( action )
> > 
> > but after boot the VM, cloud-init service hasn't set hostname and on
> > cloud-init.log and cloud-init-output.log I cannot find any entry for
> > setting hostname, instead if I use web ui it work's fine...
> > 
> > there are any ways to debug cloud-init jobs?
> > the params params.Host is right for CloudInit host or is intended for
> > host / hypervisor?
> > 
> > Best regards
> > Amedeo Salvati
> > 
> 
> To change the hostname you have to use the "address" property of the
> "Host" class:
> 
>   host=params.Host(
>       address="myhostname.example.com"
>   )
> 
> The "Host" class is used for many things, including CloudInit and
> hypervisors. But in this context it is just a container for the host name.
> 
> To debug cloud-init start the VM (with the GUI or with the RESTAPI),
> then go to the hypervisor where it is actually running, and look for the
> corresponding qemu-kvm process:
> 
>   # ps -ef | grep qemu-kvm | grep myvm
> 
> The qemu-kvm command line will have a parameter indicating the file that
> contains the cloud-init data:
> 
>   -drive file=/var/run/vdsm/payload/...img
> 
> Copy that file somewhere, then mount it and inspect the content:
> 
>   # cp /var/run/vdsm/payload/...img /tmp/my.img
>   # mount -o loop,ro /tmp/my.img /mnt
>   # find /mnt
>   ...
>   # umount /mnt
> 
> 
> > Da: "Juan Hernandez" jhernand at redhat.com
> > A: "Amedeo Salvati" amedeo at oscert.net, users at ovirt.org
> > Cc:
> > Data: Tue, 22 Jul 2014 12:21:01 +0200
> > Oggetto: Re: [ovirt-users] cloud-init options under python-sdk
> > 
> >> On 07/22/2014 11:48 AM, Amedeo Salvati wrote:
> >> > hello guys!
> >> >
> >> > I'm writing some python code to start VMs, and based on operating system
> >> > (at this moment centos6 nad centos7), I would like to use cloud-init
> >> > options (available on web ui at run-once) to start them and resetting
> >> > root password, change hostname and write some configuration files by
> >> > using yaml semantics, but at this moment I was unable to find a way to
> >> > do it...
> >> >
> >> > somebody know a way (or could send me some hints) using python-sdk to
> >> > start A VM and pass to it cloud-init options?
> >> >
> >> > e.g. the portion of code I would like to change is vm.start() under
> > rhel6|7:
> >> >
> >> > try:
> >> > osVersion = vm.get_os().get_type()
> >> > if (osVersion == "rhel_6x64" or osVersion == "rhel_6" or
> >> > osVersion == "rhel_7x64") and CLOUDINIT == "yes":
> >> > print "Starting VM: " + vm.name + " with cloud-init
> >> > options"
> >> > ----> vm.start() <---------- > else:
> >> > print "Starting VM " + vm.name
> >> > vm.start()
> >> > while vmstat != 'down':
> >> > sleep(1)
> >> > vmstat = vm.get_status().state
> >> > except Exception, err:
> >> > print "Error on starting VM"
> >> > print err
> >> >
> >> >
> >> > Best regards
> >> > Amedeo Salvati
> >> >
> >>
> >> It should be something like this:
> >>
> >> from ovirtsdk.xml import params
> >>
> >> action = params.Action(
> >> vm=params.VM(
> >> initialization=params.Initialization(
> >> cloud_init=params.CloudInit(
> >> host=params.Host(
> >> name="myvm"
> >> ),
> >> users=...,
> >> files=...,
> >> ...
> >> )
> >> )
> >> )
> >> )
> >>
> >> vm.start(action)
> >>
> >>
> >> --
> >> Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
> >> 3ºD, 28016 Madrid, Spain
> >> Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
> 
> 
> -- 
> Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
> 3ºD, 28016 Madrid, Spain
> Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20140722/92a00d7a/attachment-0001.html>


More information about the Users mailing list