Build VM in oVirt from Image. How to assign static ip as its not on network when it comes up from image

Problem:
Need to understand how to change static ip on a VM build out of image using Foreman GUI…

Expected outcome:
IP should get configured on the VM built in oVirt resource.
Foreman and Proxy versions:
2.0.0 2.0.0

Foreman and Proxy plugin versions:
foreman-tasks 1.1.1
foreman_hooks 0.3.16
foreman_remote_execution 3.2.1

Distribution and version:

Other relevant data:

Hello,

this is currently not possible, unless you hack our own script and pass it via user data (cloud-init). Although oVirt supports setting up NICs via cloud-init network OpenStack provider and it as API flags for that, neither Foreman nor fog-ovirt supports that.

This is not the first time we hear about this.

1 Like

Has anyone posted their solution to this? We have to do the same thing and if someone has come up with their solution it could be useful. Thanks.

Keith

Oh , that’s dissapointing… Any other possible alternatives or workarounds we can use to address this… looking for ideas to get this working…

We might be looking into that soon as one of our customers want this feature.

A workaround is to configure your VMs via user data template script but you need to figure out network manager configuration (e.g. ifcfg configs) for each interface. MAC address is not available when template is being passed in, but others are: IP, netmask, dns and interface identifier. This would be a temporary solution. I can’t help much with doing the changes because this highly depends on the setup: RHEL7 has different network identifier for virt-io device than RHEL8 (eth0 vs ens1), it depends which driver you pick in RHV (virtio, e1000 etc).

Example (untested):

runcmd:
- |
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
DEVICE="eth0"
NM_CONTROLLED="no"
BOOTPROTO="none"
IPADDR="192.168.1.99"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
ONBOOT="yes"
EOF

Note since there is no MAC adress the DEVICE= identifier must match.

Foreman can assign a static IP to a VM created in VMware. To do this foreman creates a customization spec with the static IP address and then VMware tools running on the VM configures the static IP on the VM. VMware is able to log into a VM using VMware tools even if the VM is not on the network. I am able to use foreman to create a VM with a static IP address in VMware. This would be the ideal solution for oVirt but i’m not sure if oVirt allows this or plans to allow this option.

Keith

I was able to use foreman version 2.1 to create an oVirt CentOS 7.7 VM with a static IP. The foreman user_data template I was using is shown below.

Keith

<%#
kind: user_data
name: Cloud-init
-%>
#cloud-config
hostname: <%= @host %>
write_files:
 - path: /etc/sysconfig/network-scripts/ifcfg-eth0
   permissions: 0644
   owner: root
   content: |
      # Created by cloud-init from the foreman user-data template
      NAME=eth0
      GATEWAY=<%= @host.subnet.gateway %>
      DOMAIN=<%= @host.domain %>
      DEVICE=eth0
      ONBOOT=yes
      USERCTL=no
      BOOTPROTO=static
      NETMASK=<%= @host.subnet.mask %>
      IPADDR=<%= @host.ip %>
      PEERDNS=no
      IPV6INIT=yes
      
      check_link_down() {
        return 1;
      }
 - content: |
      network: {config: disabled}
   path: /etc/cloud/cloud.cfg.d/99_disable-network-config.cfg
runcmd: 
- [ sh, -xc, 'echo <%= @host.ip %> <%= @host %> <%= @host.shortname %> >>/etc/hosts']
- [ sh, -xc, 'systemctl restart network']
2 Likes