[ovirt-users] Add multiple files to a VM via cloud-init

Amedeo Salvati amedeo at oscert.net
Sun Nov 2 14:37:38 UTC 2014


Hi Juan,

this means that example of python code on 
http://www.ovirt.org/Features/Cloud-Init_Integration that I wrote some 
months ago against v3.4 could be changed by encoding the content on base64?

at this time of this writing I haven't v3.5 to test the script / new code

best regards
Amedeo Salvati

Il 01/11/2014 00:00, users-request at ovirt.org ha scritto:
> The "custom_script" element doesn't work in combination with cloud-init
> and run once. To make it work you have to use cloud-init and a file
> element containing your custom script. Here you have an example:
>
> #!/usr/bin/python
>
> import base64
> import re
>
> from ovirtsdk.api import API
> from ovirtsdk.xml import params
>
> # A simple function to encode using base64 and now new lines:
> def encode(s):
>     return re.sub("\s+", "", base64.encodestring(s))
>
> # Connect to the server:
> api = API(
>    url="https://engine35.example.com/ovirt-engine/api",
>    username="admin at internal",
>    password="redhat123",
>    insecure=True,
>    debug=True
> )
>
> # Find the virtual machine:
> myvm = api.vms.get(name="myvm")
>
> # Prepare the cloud-init custom script to write files:
> myscript = """\
> write_files:
> """
>
> # Append one file:
> myscript += """\
> - encoding: b64
>    content: %s
>    owner: root:root
>    path: /etc/firstfile.txt
>    permissions: '0644'
> """ % encode("The content of the first file")
>
> # Append another file:
> myscript += """\
> - encoding: b64
>    content: %s
>    owner: root:root
>    path: /etc/secondfile.txt
>    permissions: '0644'
> """ % encode("The content of the second file")
>
> # Prepare the action to trigger initialization using cloud-init:
> action = params.Action(
>    vm=params.VM(
>      initialization=params.Initialization(
>        cloud_init=params.CloudInit(
>          files=params.Files(
>            file=[
>              params.File(
>                name="myscript",
>                type_="plaintext",
>                content=myscript
>              )
>            ]
>          )
>        )
>      )
>    )
> )
>
> # Start the virtual machine:
> myvm.start(action)
>
> # Disconnect from the server:
> api.disconnect()
>
> Regarding the problem with the root password we have a bug in 3.5 that
> makes this fail. See here:
>
>    https://bugzilla.redhat.com/1156155
>
> The problem is that we are not passing the user name to cloud-init, and
> as a result it is changing the default cloud-init user password, not the
> root pssword. To workaround the issue you can edit the
> "/etc/cloud/cloud.cfg" file of the VM and change the default user name:
>
>    system_info:
>    distro: ...
>    default_user:
>      name: root  <-- Change this from "fedora" or "cloud-init" to root




More information about the Users mailing list