Chapter 10. Provisioning Virtual Machines on Red Hat Virtualization

Red Hat Virtualization is an enterprise-grade server and desktop virtualization platform. In Red Hat Satellite, you can manage virtualization functions through Red Hat Virtualization’s REST API. This includes creating virtual machines and controlling their power states.

You can use Red Hat Virtualization provisioning to create virtual machines over a network connection or from an existing image.

You can use cloud-init to configure the virtual machines that you provision. Using cloud-init avoids any special configuration on the network, such as a managed DHCP and TFTP, to finish the installation of the virtual machine. This method does not require Satellite to connect to the provisioned virtual machine using SSH to run the finish script.

Prerequisites

  • Synchronized content repositories for Red Hat Enterprise Linux. For more information, see Synchronizing Red Hat Repositories in the Content Management Guide.
  • An activation key for host registration. For more information, see Creating An Activation Key in the Content Management guide.
  • A Capsule Server managing a logical network on the Red Hat Virtualization environment. Ensure no other DHCP services run on this network to avoid conflicts with the Capsule Server. For more information, see Chapter 3, Configuring Networking.
  • An existing template, other than the blank template, if you want to use image-based provisioning. For more information about creating templates for virtual machines, see Templates in the Red Hat Virtualization Virtual Machine Management Guide.
  • An administration-like user on Red Hat Virtualization for communication with Satellite Server. Do not use the admin@internal user for this communication. Instead, create a new Red Hat Virtualization user with the following permissions:

    • System > Configure System > Login Permissions
    • Network > Configure vNIC Profile > Create
    • Network > Configure vNIC Profile > Edit Properties
    • Network > Configure vNIC Profile > Delete
    • Network > Configure vNIC Profile > Assign vNIC Profile to VM
    • Network > Configure vNIC Profile > Assign vNIC Profile to Template
    • Template > Provisioning Operations > Import/Export
    • VM > Provisioning Operations > Create
    • VM > Provisioning Operations > Delete
    • VM > Provisioning Operations > Import/Export
    • VM > Provisioning Operations > Edit Storage
    • Disk > Provisioning Operations > Create
    • Disk > Disk Profile > Attach Disk Profile

      For more information about how to create a user and add permissions in Red Hat Virtualization, see Administering User Tasks From the Administration Portal in the Red Hat Virtualization Administration Guide.

Procedure Overview

  1. Section 10.1, “Adding the Red Hat Virtualization Connection to Satellite Server”.
  2. Optional: Section 10.2, “Preparing Cloud-init Images in Red Hat Virtualization”. Use this procedure if you want to use cloud-init to configure an image-based virtual machine.
  3. Optional: Section 10.3, “Adding Red Hat Virtualization Images to Satellite Server”. Use this procedure if you want to use image-based provisioning.
  4. Optional: Section 10.4, “Preparing a Cloud-init Template”. Use this procedure if you want to use cloud-init to configure an image-based virtual machine.
  5. Section 10.5, “Adding Red Hat Virtualization Details to a Compute Profile”.
  6. Section 10.6, “Creating Hosts on Red Hat Virtualization”.

10.1. Adding the Red Hat Virtualization Connection to Satellite Server

Use this procedure to add Red Hat Virtualization as a compute resource in Satellite.

Procedure

  1. In the Satellite web UI, navigate to Infrastructure > Compute Resources and click Create Compute Resource.
  2. In the Name field, enter a name for the new compute resource.
  3. From the Provider list, select RHV.
  4. In the Description field, enter a description for the compute resource.
  5. In the URL field, enter the connection URL for the Red Hat Virtualization Manager’s API in the following form: https://rhv.example.com/ovirt-engine/api/v3.
  6. Optionally, select the Use APIv4 check box to evaluate the new Red Hat Virtualization Manager API.
  7. In the User field, enter the name of a user with permissions to access Red Hat Virtualization Manager’s resources.
  8. In the Password field, enter the password of the user.
  9. Click Load Datacenters to populate the Datacenter list with data centers from your Red Hat Virtualization environment.
  10. From the Datacenter list, select a data center.
  11. From the Quota ID list, select a quota to limit resources available to Satellite.
  12. In the X509 Certification Authorities field, enter the certificate authority for SSL/TLS access. Alternatively, if you leave the field blank, a self-signed certificate is generated on the first API request by the server.
  13. Click the Locations tab and select the location you want to use.
  14. Click the Organizations tab and select the organization you want to use.
  15. Click Submit to save the compute resource.

For CLI Users

  • Enter the hammer compute-resource create command with Ovirt for --provider and the name of the data center you want to use for --datacenter.

    # hammer compute-resource create \
    --name "My_RHV" --provider "Ovirt" \
    --description "RHV server at rhv.example.com" \
    --url "https://rhv.example.com/ovirt-engine/api" \
    --use-v4 "false" --user "Satellite_User" \
    --password "My_Password" \
    --locations "New York" --organizations "My_Organization" \
    --datacenter "My_Datacenter"

    Optionally, to evaluate the new Red Hat Virtualization Manager API, change false to true for the --use-v4 option.

10.2. Preparing Cloud-init Images in Red Hat Virtualization

To use cloud-init during provisioning, you must prepare an image with cloud-init installed in Red Hat Virtualization, and then import the image to Satellite to use for provisioning.

Procedure

  1. In Red Hat Virtualization, create a virtual machine to use for image-based provisioning in Satellite.
  2. On the virtual machine, install cloud-init:

    yum install cloud-init
  3. To the /etc/cloud/cloud.cfg file, add the following information:

    datasource_list: ["NoCloud", "ConfigDrive"]
  4. In Red Hat Virtualization, create an image from this virtual machine.

When you add this image to Satellite, ensure that you select the User Data check box.

10.3. Adding Red Hat Virtualization Images to Satellite Server

To create hosts using image-based provisioning, you must add information about the image, such as access details and the image location, to your Satellite Server.

Procedure

  1. In the Satellite web UI, navigate to Infrastructure > Compute Resources and click the name of the Red Hat Virtualization connection.
  2. Click Create Image.
  3. In the Name field, enter a name for the image.
  4. From the Operating System list, select the image’s base operating system.
  5. From the Architecture list, select the operating system architecture.
  6. In the Username field, enter the SSH user name for image access. This is normally the root user.
  7. In the Password field, enter the SSH password for image access.
  8. From the Image list, select an image from the Red Hat Virtualization compute resource.
  9. Optional: Select the User Data check box if the image supports user data input, such as cloud-init data.
  10. Click Submit to save the image details.

For CLI Users

  • Create the image with the hammer compute-resource image create command. Use the --uuid option to store the template UUID on the Red Hat Virtualization server.

    # hammer compute-resource image create \
    --name "RHV_Image" \
    --compute-resource "My_RHV"
    --operatingsystem "RedHat version" \
    --architecture "x86_64" \
    --username root \
    --uuid "9788910c-4030-4ae0-bad7-603375dd72b1" \

10.4. Preparing a Cloud-init Template

Procedure

  1. In the Satellite web UI, navigate to Hosts > Provisioning Templates, and click Create Template.
  2. In the Name field, enter a name for the template.
  3. In the Editor field, enter the following template details:

    <%#
    kind: user_data
    name: Cloud-init
    -%>
    #cloud-config
    hostname: <%= @host.shortname %>
    
    <%# Allow user to specify additional SSH key as host paramter -%>
    <% if @host.params['sshkey'].present? || @host.params['remote_execution_ssh_keys'].present? -%>
    ssh_authorized_keys:
    <% if @host.params['sshkey'].present? -%>
      - <%= @host.params['sshkey'] %>
    <% end -%>
    <% if @host.params['remote_execution_ssh_keys'].present? -%>
    <% @host.params['remote_execution_ssh_keys'].each do |key| -%>
      - <%= key %>
    <% end -%>
    <% end -%>
    <% end -%>
    runcmd:
      - |
        #!/bin/bash
    <%= indent 4 do
        snippet 'subscription_manager_registration'
    end %>
    <% if @host.info['parameters']['realm'] && @host.realm && @host.realm.realm_type == 'Red Hat Identity Management' -%>
      <%= indent 4 do
        snippet 'idm_register'
      end %>
    <% end -%>
    <% unless @host.operatingsystem.atomic? -%>
        # update all the base packages from the updates repository
        yum -t -y -e 0 update
    <% end -%>
    <%
        # safemode renderer does not support unary negation
        non_atomic = @host.operatingsystem.atomic? ? false : true
        pm_set = @host.puppetmaster.empty? ? false : true
        puppet_enabled = non_atomic && (pm_set || @host.params['force-puppet'])
    %>
    <% if puppet_enabled %>
        yum install -y puppet
        cat > /etc/puppet/puppet.conf << EOF
      <%= indent 4 do
        snippet 'puppet.conf'
      end %>
        EOF
        # Setup puppet to run on system reboot
        /sbin/chkconfig --level 345 puppet on
    
        /usr/bin/puppet agent --config /etc/puppet/puppet.conf --onetime --tags no_such_tag <%= @host.puppetmaster.blank? ? '' : "--server #{@host.puppetmaster}" %> --no-daemonize
        /sbin/service puppet start
    <% end -%>
    phone_home:
     url: <%= foreman_url('built') %>
     post: []
     tries: 10pp
  4. Click the Type tab and from the Type list, select User data template.
  5. Click the Association tab, and from the Applicable Operating Systems list, select the operating system that you want associate with the template.
  6. Click the Locations tab, and from the Locations list, select the location that you want to associate with the template.
  7. Click the Organizations tab, and from the Organization list, select the organization that you want to associate with the template.
  8. Click Submit.
  9. Navigate to Hosts > Operating Systems, and select the operating system you want to associate with the template.
  10. Click the Templates tab, and from the User data template list, select the name of the new template.
  11. Click Submit.

10.5. Adding Red Hat Virtualization Details to a Compute Profile

Use this procedure to add Red Hat Virtualization hardware settings to a compute profile. When you create a host on KVM using this compute profile, these settings are automatically populated.

Procedure

  1. In the Satellite web UI, navigate to Infrastructure > Compute Profiles.
  2. In the Compute Profiles window, click the name of an existing compute profile, or click Create Compute Profile, enter a Name, and click Submit.
  3. Click the name of the Red Hat Virtualization compute resource.
  4. From the Cluster list, select the target host cluster in the Red Hat Virtualization environment.
  5. From the Template list, select the RHV template to use for the Cores and Memory settings.
  6. In the Cores field, enter the number of CPU cores to allocate to the new host.
  7. In the Memory field, enter the amount of memory to allocate to the new host.
  8. From the Image list, select image to use for image-based provisioning.
  9. In the Network Interfaces area, enter the network parameters for the host’s network interface. You can create multiple network interfaces. However, at least one interface must point to a Capsule-managed network. For each network interface, enter the following details:

    1. In the Name field, enter the name of the network interface.
    2. From the Network list, select The logical network that you want to use.
  10. In the Storage area, enter the storage parameters for the host. You can create multiple volumes for the host. For each volume, enter the following details:

    1. In the Size (GB) enter the size, in GB, for the new volume.
    2. From the Storage domain list, select the storage domain for the volume.
    3. From the Preallocate disk, select either thin provisioning or preallocation of the full disk.
    4. From the Bootable list, select whether you want a bootable or non-bootable volume.
  11. Click Submit to save the compute profile.

For CLI Users

  1. To create a compute profile, enter the following command:

    # hammer compute-profile create --name "Red Hat Virtualization CP"
  2. To set the values for the compute profile, enter the following command:

    # hammer compute-profile values create --compute-profile "Red Hat Virtualization CP" \
    --compute-resource "My_RHV" \
    --interface "compute_interface=Interface_Type,compute_name=eth0,compute_network=satnetwork" \
    --volume "size_gb=20G,storage_domain=Data,bootable=true" \
    --compute-attributes "cluster=Default,cores=1,memory=1073741824,start=true""

10.6. Creating Hosts on Red Hat Virtualization

In Satellite, you can use Red Hat Virtualization provisioning to create hosts over a network connection or from an existing image:

  • If you want to create a host over a network connection, the new host must be able to access either the Satellite Server’s integrated Capsule or an external Capsule Server on a Red Hat Virtualization virtual network, so that the host has access to PXE provisioning services. This new host entry triggers the Red Hat Virtualization server to create and start a virtual machine. If the virtual machine detects the defined Capsule Server through the virtual network, the virtual machine boots to PXE and begins to install the chosen operating system.
  • If you want to create a host with an existing image, the new host entry triggers the Red Hat Virtualization server to create the virtual machine using a pre-existing image as a basis for the new volume.

DHCP Conflicts

For network-based provisioning, if you use a virtual network on the Red Hat Virtualization server for provisioning, select a network that does not provide DHCP assignments. This causes DHCP conflicts with Satellite Server when booting new hosts.

Procedure

  1. In the Satellite web UI, navigate to Hosts > Create Host.
  2. In the Name field, enter a name for the host.
  3. Click the Organization and Location tabs to ensure that the provisioning context is automatically set to the current context.
  4. From the Host Group list, select the host group that you want to use to populate the form.
  5. From the Deploy on list, select the Red Hat Virtualization connection.
  6. From the Compute Profile list, select a profile to use to automatically populate virtual machine settings.
  7. Click the Interface tab and click Edit on the host’s interface.
  8. Verify that the fields are automatically populated, particularly the following items:

    • The Name from the Host tab becomes the DNS name.
    • Satellite Server automatically assigns an IP address for the new host.
    • The MAC address field is blank. The Red Hat Virtualization server assigns a MAC address to the host.
    • The Managed, Primary, and Provision options are automatically selected for the first interface on the host. If not, select them.
    • The Red Hat Virtualization-specific fields are populated with settings from your compute profile. Modify these settings if required.
  9. Click the Operating System tab, and confirm that all fields automatically contain values.
  10. Select the Provisioning Method that you want to use:

    • For network-based provisioning, click Network Based.
    • For image-based provisioning, click Image Based.
  11. Click Resolve in Provisioning templates to check the new host can identify the right provisioning templates to use.
  12. Click the Virtual Machine tab and confirm that these settings are populated with details from the host group and compute profile. Modify these settings to suit your needs.
  13. Click the Parameters tab, and ensure that a parameter exists that provides an activation key. If not, add an activation key.
  14. Click Submit to save the host entry.

For CLI Users

  • To use network-based provisioning, create the host with the hammer host create command and include --provision-method build. Replace the values in the following example with the appropriate values for your environment.

    # hammer host create \
    --name "RHV-vm1" \
    --organization "My_Organization" \
    --location "New York" \
    --hostgroup "Base" \
    --compute-resource "My_RHV" \
    --provision-method build \
    --build true \
    --enabled true \
    --managed true \
    --interface "managed=true,primary=true,provision=true,compute_name=eth0,compute_network=satnetwork" \
    --compute-attributes="cluster=Default,cores=1,memory=1073741824,start=true" \
    --volume="size_gb=20G,storage_domain=Data,bootable=true"
  • To use image-based provisioning, create the host with the hammer host create command and include --provision-method image. Replace the values in the following example with the appropriate values for your environment.

    # hammer host create \
    --name "RHV-vm2" \
    --organization "My_Organization" \
    --location "New York" \
    --hostgroup "Base" \
    --compute-resource "My_RHV" \
    --provision-method image \
    --image "RHV_Image" \
    --enabled true \
    --managed true \
    --interface "managed=true,primary=true,provision=true,compute_name=eth0,compute_network=satnetwork" \
    --compute-attributes="cluster=Default,cores=1,memory=1073741824,start=true" \
    --volume="size_gb=20G,storage_domain=Data,bootable=true"

For more information about additional host creation parameters for this compute resource, enter the hammer host create --help command.