[ovirt-devel] oVirt Cloud-init

Marc Young 3vilpenguin at gmail.com
Fri Feb 17 05:00:32 UTC 2017


I'm apparently really bad at email, I replied only to Shahar, not the whole
thread.

Vinzenz your email slipped first, so to answer your question:

It's the latest Centos 7 with these installed:

cloud-init-0.7.5-10.el7.centos.1
kernel-3.10.0-514.el7
ovirt-guest-agent-common-1.0.13-1.20161220085008.git165fff1.el7.centos

The setup script I use to create a template is here:
https://github.com/myoung34/vagrant-ovirt4/blob/master/
tools/prepare_redhat_for_box.sh

The engine-host is oVirt Engine Version: 4.1.0.4-1.el7.centos
The ruby SDK i'm working with is 4.1.2

Halfway through I realized that it's actually supported in the API:

custom_script String
dns_search String
dns_servers String


It also shows usage here:
https://github.com/oVirt/ovirt-engine-sdk-ruby/blob/
master/sdk/examples/start_vm_with_cloud_init.rb

Here's some verification:

    66:           vm_configuration[:initialization][:dns_servers] =
iface_options[:dns_servers] unless iface_options[:dns_servers].nil?
    67:           vm_configuration[:initialization][:dns_search] =
iface_options[:dns_search] unless iface_options[:dns_search].nil?
    68:           require 'pry'
    69:           binding.pry
    70:
 => 71:           machine.start(
    72:             use_cloud_init: true,
    73:             vm: vm_configuration
    74:           )
    75:
    76:           @app.call(env)

[1] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)> vm_configuration
=> {:initialization=>
  {:host_name=>"test",
   :nic_configurations=>[{:name=>"eth0", :on_boot=>true,
:boot_protocol=>"static", :ip=>{:version=>"v4",
:address=>"192.168.2.200", :gateway=>"192.168.2.1",
:netmask=>"255.255.255.0"}}],
   :custom_script=>nil,
   :dns_servers=>"192.168.2.1",
   :dns_search=>"test.local"}}


But it didn't do anything:

[vagrant at test ~]$ cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain

[vagrant at test ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
NM_CONTROLLED=no
NETMASK=255.255.255.0
BOOTPROTO=static
DEVICE=eth0
IPADDR=192.168.2.200
GATEWAY=192.168.2.1
ONBOOT=yes


The same is also true using cloud_init:

    ovirt.cloud_init =<<EOF
write_files:
  - content: |
      wat
    path: /tmp/something.txt
    permissions: '0644'
network-interfaces: |
  auto eth0
  iface eth0 inet static
    address 192.168.2.201
    network 192.168.2.0
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameservers 192.168.2.113 192.168.2.1
EOF


and inspection:

    66:           vm_configuration[:initialization][:dns_servers] =
iface_options[:dns_servers] unless iface_options[:dns_servers].nil?
    67:           vm_configuration[:initialization][:dns_search] =
iface_options[:dns_search] unless iface_options[:dns_search].nil?
    68:           require 'pry'
    69:           binding.pry
    70:
 => 71:           machine.start(
    72:             use_cloud_init: true,
    73:             vm: vm_configuration
    74:           )
    75:
    76:           @app.call(env)
[1] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)> vm_configuration
=> {:initialization=>
  {:host_name=>"test",
   :nic_configurations=>[{:name=>"eth0", :on_boot=>true,
:boot_protocol=>"static", :ip=>{:version=>"v4",
:address=>"192.168.2.200", :gateway=>"192.168.2.1",
:netmask=>"255.255.255.0"}}],
   :custom_script=>
    "write_files:\n  - content: |\n      wat\n    path:
/tmp/something.txt\n    permissions: '0644'\nnetwork-interfaces: |\n
auto eth0\n  iface eth0 inet static\n    address 192.168.2.201\n
network 192.168.2.0\n    netmask 255.255.255.0\n    gateway
192.168.2.1\n    dns-nameservers 192.168.2.113 192.168.2.1\n",
   :dns_servers=>"192.168.2.1",
   :dns_search=>"test.local"}}


And here's my debugging after it comes up:

[vagrant at test ~]$ cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
[vagrant at test ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
NM_CONTROLLED=no
NETMASK=255.255.255.0
BOOTPROTO=static
DEVICE=eth0
IPADDR=192.168.2.200
GATEWAY=192.168.2.1
ONBOOT=yes
[vagrant at test ~]$ cat /tmp/something.txt
wat
[vagrant at test ~]$ ping -c 3 www.google.com
ping: www.google.com: Name or service not known
[vagrant at test ~]$ echo $'nameserver 192.168.2.113\nnameserver
192.168.2.1' | sudo tee -a /etc/resolv.conf >/dev/null
[vagrant at test ~]$ ping -c 3 www.google.com
PING www.google.com (216.58.217.4) 56(84) bytes of data.
64 bytes from den03s09-in-f4.1e100.net (216.58.217.4): icmp_seq=1
ttl=54 time=47.5 ms
64 bytes from den03s09-in-f4.1e100.net (216.58.217.4): icmp_seq=2
ttl=54 time=46.9 ms
64 bytes from den03s09-in-f4.1e100.net (216.58.217.4): icmp_seq=3
ttl=54 time=44.3 ms
--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 44.385/46.307/47.555/1.390 ms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/devel/attachments/20170216/745c5c5c/attachment-0001.html>


More information about the Devel mailing list