--_=__=_XaM3_.1406037058.2A.600036.42.2016.52.42.007.1017900328
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
many thanks Juan it works!=0A=0Abest regards=0Aa=0A=0A=0A=0ADa: "Juan Her=
nandez" jhernand(a)redhat.com=0AA: "Amedeo Salvati" amedeo(a)oscert.net, user=
s(a)ovirt.org=0ACc: =0AData: Tue, 22 Jul 2014 15:32:45 +0200=0AOggetto: Re:=
[ovirt-users] cloud-init options under python-sdk=0A=0A=0A> On 07/22/201=
4 02:55 PM, Amedeo Salvati wrote:=0A> > hi Juan|guys,=0A> > =0A> >
thanks=
for hints! but unfortunatly it seems wont works, because I've=0A> > laun=
ched vm with this simple code:=0A> > =0A> > action =3D=0A> >
params.Actio=
n(vm=3Dparams.VM(initialization=3Dparams.Initialization(cloud_init=3Dpara=
ms.CloudInit(host=3Dparams.Host(name=3D"rheltest014")))))=0A> >
vm.start(=
action )=0A> > =0A> > but after boot the VM, cloud-init service hasn't
s=
et hostname and on=0A> > cloud-init.log and cloud-init-output.log I canno=
t find any entry for=0A> > setting hostname, instead if I use web ui it w=
ork's fine...=0A> > =0A> > there are any ways to debug cloud-init
jobs?=0A=
> the params params.Host is right for CloudInit host or is
intended for=
=0A> > host / hypervisor?=0A> > =0A> > Best
regards=0A> > Amedeo Salvati=0A=
> =0A> =0A> To change the hostname you have to use the
"address" proper=
ty of the=0A> "Host" class:=0A> =0A>
host=3Dparams.Host(=0A> addr=
ess=3D"myhostname.example.com"=0A> )=0A> =0A> The "Host"
class is used =
for many things, including CloudInit and=0A> hypervisors. But in this con=
text it is just a container for the host name.=0A> =0A> To debug cloud-in=
it start the VM (with the GUI or with the RESTAPI),=0A> then go to the hy=
pervisor where it is actually running, and look for the=0A> corresponding=
qemu-kvm process:=0A> =0A> # ps -ef | grep qemu-kvm | grep myvm=0A> =0A=
The qemu-kvm command line will have a parameter indicating the file
tha=
t=0A> contains the cloud-init data:=0A> =0A> -drive
file=3D/var/run/vds=
m/payload/...img=0A> =0A> Copy that file somewhere, then mount it and ins=
pect the content:=0A> =0A> # cp /var/run/vdsm/payload/...img /tmp/my.im=
g=0A> # mount -o loop,ro /tmp/my.img /mnt=0A> # find /mnt=0A> ...=0A=
# umount /mnt=0A> =0A> =0A> > Da: "Juan
Hernandez" jhernand(a)redhat.co=
m=0A> > A: "Amedeo Salvati"
amedeo(a)oscert.net, users(a)ovirt.org=0A> > Cc:=0A=
> Data: Tue, 22 Jul 2014 12:21:01 +0200=0A> > Oggetto: Re:
[ovirt-users=
] cloud-init options under python-sdk=0A> > =0A> >> On
07/22/2014 11:48 A=
M, Amedeo Salvati wrote:=0A> >> > hello guys!=0A> >> >=0A>
>> > I'm writi=
ng some python code to start VMs, and based on operating system=0A> >> > =
(at this moment centos6 nad centos7), I would like to use cloud-init=0A> =
> > options (available on web ui at run-once) to start them and
resettin=
g=0A> >> > root password, change hostname and write some
configuration fi=
les by=0A> >> > using yaml semantics, but at this moment I was unable to =
find a way to=0A> >> > do it...=0A> >> >=0A> >> >
somebody know a way (or=
could send me some hints) using python-sdk to=0A> >> > start A VM and pa=
ss to it cloud-init options?=0A> >> >=0A> >> > e.g. the portion of
code I=
would like to change is vm.start() under=0A> > rhel6|7:=0A> >> >=0A>
>> =
try:=0A> >> > osVersion =3D vm.get_os().get_type()=0A>
>> > if (osVersi=
on =3D=3D "rhel_6x64" or osVersion =3D=3D
"rhel_6" or=0A> >> > osVersion =
=3D=3D "rhel_7x64") and CLOUDINIT =3D=3D "yes":=0A> >> >
print "Starting =
VM: " + vm.name + " with cloud-init=0A> >> > options"=0A>
>> > ----> vm.s=
tart() <---------- > else:=0A> >> > print "Starting VM " +
vm.name=0A> >>=
vm.start()=0A> >> > while vmstat !=3D
'down':=0A> >> > sleep(1)=0A> >>=
vmstat =3D vm.get_status().state=0A> >> > except Exception, err:=0A>
>=
> print "Error on starting VM"=0A> >> > print err=0A>
>> >=0A> >> >=0A>=
> > Best regards=0A> >> > Amedeo Salvati=0A> >> >=0A>
>>=0A> >> It shou=
ld be something like this:=0A> >>=0A>
>> from ovirtsdk.xml import params=0A=
>>=0A> >> action =3D params.Action(=0A> >>
vm=3Dparams.VM(=0A> >> initi=
alization=3Dparams.Initialization(=0A>
>> cloud_init=3Dparams.CloudInit(=0A=
>> host=3Dparams.Host(=0A> >>
name=3D"myvm"=0A> >> ),=0A> >> users=3D..=
.,=0A>
>> files=3D...,=0A> >> ...=0A> >> )=0A> >> )=0A>
>> )=0A> >> )=0A>=
>=0A> >> vm.start(action)=0A> >>=0A>
>>=0A> >> --=0A> >> Direcci=C3=B3n=
Comercial: C/Jose
Bardasano Baos, 9, Edif. Gorbea 3, planta=0A> >> 3=C2=BA=
D, 28016 Madrid, Spain=0A> >> Inscrita en el Reg. Mercantil de Madrid =E2=
=80=93 C.I.F. B82657941 - Red Hat S.L.=0A> =0A> =0A> -- =0A> Direcci=C3=B3=
n Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta=0A> 3=C2=BA=
D, 28016 Madrid, Spain=0A> Inscrita en el Reg. Mercantil de Madrid =E2=80=
=93 C.I.F. B82657941 - Red Hat S.L.
--_=__=_XaM3_.1406037058.2A.600036.42.2016.52.42.007.1017900328
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
=0A<div class=3D"xam_msg_class">=0A<div style=3D"font: normal 13px
Arial;=
color:rgb(31, 28, 27);">many thanks Juan it works!<br><br>best
regards<b=
r>a<br><br><br>=0A<div><span
style=3D"font-family:Arial; font-size:11px; =
color:#5F5F5F;">Da</span><span style=3D"font-family:Arial;
font-size:12px=
; color:#5F5F5F; padding-left:5px;">: "Juan Hernandez"
jhernand(a)redhat.co=
m</span></div>=0A<div><span style=3D"font-family:Arial;
font-size:11px; c=
olor:#5F5F5F;">A</span><span style=3D"font-family:Arial;
font-size:12px; =
color:#5F5F5F; padding-left:5px;">: "Amedeo Salvati" amedeo(a)oscert.net,
u=
sers(a)ovirt.org</span></div>=0A<div><span
style=3D"font-family:Arial; font=
-size:11px; color:#5F5F5F;">Cc</span><span
style=3D"font-family:Arial; fo=
nt-size:12px; color:#5F5F5F; padding-left:5px;">:
</span></div>=0A<div><s=
pan style=3D"font-family:Arial; font-size:11px;
color:#5F5F5F;">Data</spa=
n><span style=3D"font-family:Arial; font-size:12px; color:#5F5F5F; paddin=
g-left:5px;">: Tue, 22 Jul 2014 15:32:45
+0200</span></div>=0A<div><span =
style=3D"font-family:Arial; font-size:11px;
color:#5F5F5F;">Oggetto</span=
<span style=3D"font-family:Arial; font-size:12px;
color:#5F5F5F; padding=
-left:5px;">: Re: [ovirt-users] cloud-init options
under python-sdk</span=
</div>=0A<br>=0A<div>> On 07/22/2014 02:55
PM, Amedeo Salvati wrote:<=
/div><div>> > hi
Juan|guys,</div><div>> > </div><div>>
>=
; thanks for hints! but unfortunatly it seems wont works, because I've</d=
iv><div>> > launched vm with this simple
code:</div><div>> > =
</div><div>> > action =3D</div><div>>
> params.Action(vm=3Dpa=
rams.VM(initialization=3Dparams.Initialization(cloud_init=3Dparams.CloudI=
nit(host=3Dparams.Host(name=3D"rheltest014")))))</div><div>>
> vm.s=
tart( action )</div><div>> > </div><div>>
> but after boot th=
e VM, cloud-init service hasn't set hostname and on</div><div>>
> c=
loud-init.log and cloud-init-output.log I cannot find any entry for</div>=
<div>> > setting hostname, instead if I use web ui it work's
fine..=
.</div><div>> > </div><div>> > there
are any ways to debug cl=
oud-init jobs?</div><div>> > the params params.Host is right for
Cl=
oudInit host or is intended for</div><div>> > host /
hypervisor?</d=
iv><div>> > </div><div>> > Best
regards</div><div>> > A=
medeo Salvati</div><div>> > </div><div>>
</div><div>> To chan=
ge the hostname you have to use the "address" property of
the</div><div>&=
gt; "Host" class:</div><div>> </div><div>>
host=3Dparams.Host(</d=
iv><div>>
address=3D"myhostname.example.com"</div><div>> )<=
/div><div>> </div><div>> The "Host" class is
used for many things, =
including CloudInit and</div><div>> hypervisors. But in this context
i=
t is just a container for the host name.</div><div>>
</div><div>> T=
o debug cloud-init start the VM (with the GUI or with the RESTAPI),</div>=
<div>> then go to the hypervisor where it is actually running, and loo=
k for the</div><div>> corresponding qemu-kvm
process:</div><div>> <=
/div><div>> # ps -ef | grep qemu-kvm | grep
myvm</div><div>> </di=
v><div>> The qemu-kvm command line will have a parameter indicating th=
e file that</div><div>> contains the cloud-init
data:</div><div>> <=
/div><div>> -drive
file=3D/var/run/vdsm/payload/...img</div><div>>=
; </div><div>> Copy that file somewhere, then mount it and inspect
the=
content:</div><div>> </div><div>> # cp
/var/run/vdsm/payload/...=
img /tmp/my.img</div><div>> # mount -o loop,ro /tmp/my.img
/mnt</div=
<div>> # find /mnt</div><div>>
...</div><div>> # umount /=
mnt</div><div>>
</div><div>> </div><div>> > Da: "Juan
Hernand=
ez" jhernand(a)redhat.com</div><div>&gt; > A: "Amedeo
Salvati" amedeo@os=
cert.net, users(a)ovirt.org</div><div>&gt; >
Cc:</div><div>> > Dat=
a: Tue, 22 Jul 2014 12:21:01 +0200</div><div>> > Oggetto: Re:
[ovir=
t-users] cloud-init options under python-sdk</div><div>> >
</div><d=
iv>> >> On 07/22/2014 11:48 AM, Amedeo Salvati
wrote:</div><div>=
> >> > hello guys!</div><div>>
>> ></div><div>>=
; >> > I'm writing some python code to start VMs, and based on
o=
perating system</div><div>> >> > (at this moment
centos6 nad =
centos7), I would like to use cloud-init</div><div>> >>
> opt=
ions (available on web ui at run-once) to start them and resetting</div><=
div>> >> > root password, change hostname and write some
conf=
iguration files by</div><div>> >> > using yaml
semantics, but=
at this moment I was unable to find a way to</div><div>>
>> >=
; do it...</div><div>> >>
></div><div>> >> > some=
body know a way (or could send me some hints) using python-sdk to</div><d=
iv>> >> > start A VM and pass to it cloud-init
options?</div>=
<div>> >> ></div><div>>
>> > e.g. the portion of =
code I would like to change is vm.start() under</div><div>> >
rhel6=
|7:</div><div>> >>
></div><div>> >> > try:</div><=
div>> >> > osVersion =3D
vm.get_os().get_type()</div><div>>=
; >> > if (osVersion =3D=3D "rhel_6x64" or osVersion =3D=3D
"rhe=
l_6" or</div><div>> >> > osVersion =3D=3D
"rhel_7x64") and CL=
OUDINIT =3D=3D "yes":</div><div>> >> >
print "Starting VM: " =
+ vm.name + " with cloud-init</div><div>> >>
> options"</div>=
<div>> >> > ----> vm.start() <----------
> else:</di=
v><div>> >> > print "Starting VM " +
vm.name</div><div>> &=
gt;> > vm.start()</div><div>> >> >
while vmstat !=3D 'd=
own':</div><div>> >> >
sleep(1)</div><div>> >> > =
vmstat =3D vm.get_status().state</div><div>> >> >
except Exce=
ption, err:</div><div>> >> > print "Error on
starting VM"</di=
v><div>> >> > print
err</div><div>> >> ></div><di=
v>> >> ></div><div>> >>
> Best regards</div><div>=
> >> > Amedeo Salvati</div><div>>
>> ></div><div>=
> >></div><div>> >> It should be
something like this:</=
div><div>> >></div><div>>
>> from ovirtsdk.xml import p=
arams</div><div>> >></div><div>>
>> action =3D params.A=
ction(</div><div>> >>
vm=3Dparams.VM(</div><div>> >> in=
itialization=3Dparams.Initialization(</div><div>> >>
cloud_init=3D=
params.CloudInit(</div><div>> >>
host=3Dparams.Host(</div><div>&=
gt; >> name=3D"myvm"</div><div>>
>> ),</div><div>> >=
> users=3D...,</div><div>> >>
files=3D...,</div><div>> >=
;> ...</div><div>> >>
)</div><div>> >> )</div><div>&=
gt; >> )</div><div>> >>
)</div><div>> >></div><di=
v>> >> vm.start(action)</div><div>>
>></div><div>> &=
gt;></div><div>> >>
--</div><div>> >> Direcci=C3=B3n=
Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3,
planta</div><div>&g=
t; >> 3=C2=BAD, 28016 Madrid, Spain</div><div>>
>> Inscrit=
a en el Reg. Mercantil de Madrid =E2=80=93 C.I.F. B82657941 - Red Hat S.L=
.</div><div>> </div><div>>
</div><div>> -- </div><div>> Direc=
ci=C3=B3n Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta</di=
v><div>> 3=C2=BAD, 28016 Madrid, Spain</div><div>>
Inscrita en el R=
eg. Mercantil de Madrid =E2=80=93 C.I.F. B82657941 - Red Hat S.L.</div></=
div>=0A</div>=0A
--_=__=_XaM3_.1406037058.2A.600036.42.2016.52.42.007.1017900328--