
--_=__=_XaM3_.1406285961.2A.813187.42.17781.52.42.007.867559545 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hy guys,=0A=0Aafter some headache I was able to use cloud-init via python= -sdk (thanks to Juan), and I hope no one will fight anymore with them :D,= so if you want I think it's better to document with a simple example it'= s use on web page available at:=0A=0Ahttp://www.ovirt.org/Features/Cloud-= Init_Integration=0A=0Abelow simple change that you can integrate on web p= age:=0A=0A- fix api design example of usage for files xml, on the web pag= e you can find:=0A=0A...=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <files>=0A= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <file>=0A=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <name>/tmp/testFile1.txt</n= ame>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <cont= ent>temp content</content>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 <type>PLAINTEXT</type>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 </file>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </files>=0A= ...=0A=0Abut on params.File there aren't any "type" parameter only "type_= " so you can change xml with:=0A=0A...=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 <files>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <file>=0A=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <name>/tmp/test= File1.txt</name>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 <content>temp content</content>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 <type_>PLAINTEXT</type_>=0A=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </file>=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 </files>=0A...=0A=0A- insert an example of using cloud-init via pytho= n-sdk (I hope java-sdk haven't big differences).=0A=0Afor this you can in= sert on web page an example of setting via cloud-init: hostname, reset ro= ot password and write a simple text file, and finally simple python code = is:=0A=0A...=0Ascontent =3D "write_files:\n-=C2=A0=C2=A0 content: |\n=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #simple file\n=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 PIPPO=3D\"ciao\"\n=C2=A0=C2=A0=C2=A0 path: /etc/pippo.= txt"=0Aaction =3D params.Action(=0A=C2=A0 vm=3Dparams.VM(=0A=C2=A0=C2=A0=C2= =A0 initialization=3Dparams.Initialization(=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 cloud_init=3Dparams.CloudInit(=0A=C2=A0=C2=A0 =C2=A0host=3Dparams.Hos= t(address=3D"rheltest029"),=0A=C2=A0=C2=A0 =C2=A0users=3Dparams.Users(=0A= =C2=A0=C2=A0 =C2=A0=C2=A0 user=3D[params.User(user_name=3D"root", passwor= d=3D"pippolo")]=0A=C2=A0=C2=A0 =C2=A0=C2=A0 ),=0A=C2=A0=C2=A0 =C2=A0files= =3Dparams.Files(=0A=C2=A0=C2=A0 =C2=A0=C2=A0 file=3D[params.File(name=3D"= /etc/pippo.txt", content=3Dscontent, type_=3D"PLAINTEXT")]=0A=C2=A0=C2=A0= =C2=A0=C2=A0 )=0A=C2=A0=C2=A0 =C2=A0)=0A=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 )= =0A=C2=A0 )=0A)=0Avm.start( action )=0A...=0A=0AHTH=0AAmedeo Salvati --_=__=_XaM3_.1406285961.2A.813187.42.17781.52.42.007.867559545 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);">Hy guys,<br><br>after some headache I was able t= o use cloud-init via python-sdk (thanks to Juan), and I hope no one will = fight anymore with them :D, so if you want I think it's better to documen= t with a simple example it's use on web page available at:<br><br>http://= www.ovirt.org/Features/Cloud-Init_Integration<br><br>below simple change = that you can integrate on web page:<br><br>- fix api design example of us= age for files xml, on the web page you can find:<br><br>...<br> &nbs= p; <files><br>  = ; <file><br> &= nbsp; <name>/tmp/testFile1.txt</name><br>&n= bsp; <content>= ;temp content</content><br> &nbs= p; <type>PLAINTEXT</type><br> &n= bsp; </file><br> &nb= sp; </files><br>...<br><br>but on params.File there are= n't any "type" parameter only "type_" so you can change xml with:<br><br>= ...<br> <files><br> = <file><br> &n= bsp; <name>/tmp/testFile1.txt&l= t;/name><br> &nbs= p; <content>temp content</content><br>  = ; <type_>PLAINTEXT</type_>= ;<br> </file><br>&n= bsp; </files><br>...<br><br>- insert = an example of using cloud-init via python-sdk (I hope java-sdk haven't bi= g differences).<br><br>for this you can insert on web page an example of = setting via cloud-init: hostname, reset root password and write a simple = text file, and finally simple python code is:<br><br>...<br>scontent =3D = "write_files:\n- content: |\n &n= bsp; #simple file\n PIPPO= =3D\"ciao\"\n path: /etc/pippo.txt"<br>action =3D param= s.Action(<br> vm=3Dparams.VM(<br> initialization=3D= params.Initialization(<br> cloud_init=3Dpar= ams.CloudInit(<br> host=3Dparams.Host(address=3D"rhelte= st029"),<br> users=3Dparams.Users(<br> &nbs= p; user=3D[params.User(user_name=3D"root", password=3D"pippolo")]<b= r> ),<br> files=3Dparams.Files= (<br> file=3D[params.File(name=3D"/etc/pippo.txt= ", content=3Dscontent, type_=3D"PLAINTEXT")]<br> = )<br> )<br> )<br> = )<br>)<br>vm.start( action )<br>...<br><br>HTH<br>Amedeo Salvati</div>=0A= </div>=0A --_=__=_XaM3_.1406285961.2A.813187.42.17781.52.42.007.867559545--

On 07/25/2014 12:59 PM, Amedeo Salvati wrote:
Hy guys,
after some headache I was able to use cloud-init via python-sdk (thanks to Juan), and I hope no one will fight anymore with them :D, so if you want I think it's better to document with a simple example it's use on web page available at:
http://www.ovirt.org/Features/Cloud-Init_Integration
below simple change that you can integrate on web page:
- fix api design example of usage for files xml, on the web page you can find:
... <files> <file> <name>/tmp/testFile1.txt</name> <content>temp content</content> <type>PLAINTEXT</type> </file> </files> ...
but on params.File there aren't any "type" parameter only "type_" so you can change xml with:
... <files> <file> <name>/tmp/testFile1.txt</name> <content>temp content</content> <type_>PLAINTEXT</type_> </file> </files> ...
This won't be correct, the correct XML tag name is "type", as in the example in the web page. It is not good idea to use this as a parmeter in python because it hides the "type" builtin function. That is why we renamed it to "type_".
- insert an example of using cloud-init via python-sdk (I hope java-sdk haven't big differences).
for this you can insert on web page an example of setting via cloud-init: hostname, reset root password and write a simple text file, and finally simple python code is:
... scontent = "write_files:\n- content: |\n #simple file\n PIPPO=\"ciao\"\n path: /etc/pippo.txt" action = params.Action( vm=params.VM( initialization=params.Initialization( cloud_init=params.CloudInit( host=params.Host(address="rheltest029"), users=params.Users( user=[params.User(user_name="root", password="pippolo")] ), files=params.Files( file=[params.File(name="/etc/pippo.txt", content=scontent, type_="PLAINTEXT")] ) ) ) ) ) vm.start( action ) ...
I think that you can edit that page and add this Python snippet. If you don't have an account for the wiki you can request one here: http://www.ovirt.org/Special:RequestAccount And if you want you can also submit a patch for the ovirt-engine-sdk project, adding your script in the (not yet existing) examples directory.
HTH Amedeo Salvati
-- 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.
participants (2)
-
Amedeo Salvati
-
Juan Hernandez