On 11/30/2016 07:22 PM, Allen Swackhamer wrote:
I am attempting to run a VM with a cloud-init script, but can't seem to
get the syntax working for the python ovirtsdk4 library.  We are running
ovirt 4.

My cloud init script never appears to work and the users option does not
work either.  If I use root_password and user_name
for types.Initialization (as in the example below) it will generate the
correct users, but if I put in the types.CloudInit piece it will break it.

types.Initialization(
     user_name=cloud_init_username,
     root_password=cloud_init_password,
     regenerate_ssh_keys=True,
     host_name="testingcloudinit",
     nic_configurations=[
         types.NicConfiguration(
             boot_protocol=types.BootProtocol.DHCP,
             name='ens3',
             on_boot=True
         )
     ],
     custom_script=cloud_init_script
)

^ This script works for me fine. Can you send cloud-init logs? It
should be in /var/log/cloud-init*log.

Note that script *must* be properly formatted as it's YAML.

my_script="""
write_files:
  - content: |
      Hello, world!
    path: /tmp/greeting.txt
    permissions: '0644'
"""

vm_service.start(
    use_cloud_init=True,
    vm=types.Vm(
        initialization=types.Initialization(
            user_name='root',
            root_password='password',
            host_name='myvm.example.com',
            nic_configurations=[
                types.NicConfiguration(
                    name='eth0',
                    on_boot=True,
                    boot_protocol=types.BootProtocol.STATIC,
                    ip=types.Ip(
                        version=types.IpVersion.V4,
                        address='192.168.0.100',
                        netmask='255.255.255.0',
                        gateway='192.168.0.1'
                    )
                )
            ],
            custom_script=my_script,
        )
    )
)

If you are familiar with Ansible you can also since Ansible 2.2 use
following task:

# Run VM with cloud init:
ovirt_vms:
    name: rhel7
    template: rhel7
    cluster: mycluster
    cloud_init:
      nic_boot_protocol: static
      nic_ip_address: 192.168.0.100
      nic_netmask: 255.255.255.0
      nic_gateway: 192.168.0.1
      nic_name: eth0
      nic_on_boot: true
      host_name: host.example.com
      custom_script: |
        write_files:
         - content: |
             Hello, world!
           path: /tmp/greeting.txt
           permissions: '0644'
      user_name: root
      root_password: password




What I currently have is below.  cloud_init_script is the script I want
to run as a string.  Looking at the REST API documentation it shows that
I need to upload the file as a CDATA entry, but I am unsure of how I can
ensure that in python.  Is there potentially a way I could get the full
XML call in python to ensure API compliance?

vm_service.start(
    use_cloud_init=True,
    vm=types.Vm(
        initialization=types.Initialization(
            nic_configurations=[types.NicConfiguration(
                boot_protocol=types.BootProtocol.DHCP,
                name="ens3",
                on_boot=True
            )],
            cloud_init=types.CloudInit(
                files=[types.File(
                    name="initialrunner",
                    content=cloud_init_script,
                    type="plaintext"
                ),
                ],
                users=[types.User(
                    user_name=cloud_init_username,
                    password=cloud_init_password
                )]
            )
        )
    )
)

I've didn't try with cloud_init parameter I will investigate and report
back here.


Documentation that I have been using:
http://www.ovirt.org/develop/release-management/features/cloud/cloud-init-integration/
<http://www.ovirt.org/develop/release-management/features/cloud/cloud-init-integration/>
 (seems
old and for a earlier ovirtsdk version)
http://cloudinit.readthedocs.io/en/latest/topics/examples.html#run-commands-on-first-boot
<http://cloudinit.readthedocs.io/en/latest/topics/examples.html#run-commands-on-first-boot>
 (official
cloud init documentation)
https://www.mail-archive.com/users@ovirt.org/msg35549.html
<https://www.mail-archive.com/users@ovirt.org/msg35549.html> (message
board conversation about this REST API)
http://lists.ovirt.org/pipermail/users/2014-September/027198.html
<http://lists.ovirt.org/pipermail/users/2014-September/027198.html> (about
the cloud-init script specifically)
http://lists.ovirt.org/pipermail/users/2014-November/028878.html
<http://lists.ovirt.org/pipermail/users/2014-November/028878.html> (for
a old version of ovirtsdk it appears)
http://www.ovirt.org/develop/api/rest-api/rest-api/#How_can_I_run_a_custom_script_using_cloud-init.3F
<http://www.ovirt.org/develop/api/rest-api/rest-api/#How_can_I_run_a_custom_script_using_cloud-init.3F>
 (appears
to be up to date but just documents the REST API)


_______________________________________________
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users

_______________________________________________
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users

Reply via email to