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 You can use synchronized content repositories for Red Hat Enterprise Linux. For more information, see Syncing Repositories in the Content Management Guide . Provide 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 Capsule Server. For more information, see Configuring Networking in the Provisioning guide. 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 . 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. To use the CLI instead of the Satellite web UI, see the CLI procedure . Procedure In the Satellite web UI, navigate to Infrastructure > Compute Resources and click Create Compute Resource . In the Name field, enter a name for the new compute resource. From the Provider list, select RHV . In the Description field, enter a description for the compute resource. 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/v4 . In the User field, enter the name of a user with permissions to access Red Hat Virtualization Manager's resources. In the Password field, enter the password of the user. Click Load Datacenters to populate the Datacenter list with data centers from your Red Hat Virtualization environment. From the Datacenter list, select a data center. From the Quota ID list, select a quota to limit resources available to Satellite. 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. Click the Locations tab and select the location you want to use. Click the Organizations tab and select the organization you want to use. Click Submit to save the compute resource. CLI procedure Enter the hammer compute-resource create command with Ovirt for --provider and the name of the data center you want to use for --datacenter . 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 In Red Hat Virtualization, create a virtual machine to use for image-based provisioning in Satellite. On the virtual machine, install cloud-init : To the /etc/cloud/cloud.cfg file, add the following information: 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 checkbox. 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. To use the CLI instead of the Satellite web UI, see the CLI procedure . Procedure In the Satellite web UI, navigate to Infrastructure > Compute Resources and click the name of the Red Hat Virtualization connection. Click Create Image . In the Name field, enter a name for the image. From the Operating System list, select the base operating system of the image. From the Architecture list, select the operating system architecture. In the Username field, enter the SSH user name for image access. This is normally the root user. In the Password field, enter the SSH password for image access. From the Image list, select an image from the Red Hat Virtualization compute resource. Optional: Select the User Data checkbox if the image supports user data input, such as cloud-init data. Click Submit to save the image details. CLI procedure 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. 10.4. Preparing a Cloud-init Template Procedure In the Satellite web UI, navigate to Hosts > Provisioning Templates , and click Create Template . In the Name field, enter a name for the template. In the Editor field, enter the following template details: Click the Type tab and from the Type list, select User data template . Click the Association tab, and from the Applicable Operating Systems list, select the operating system that you want associate with the template. Click the Locations tab, and from the Locations list, select the location that you want to associate with the template. Click the Organizations tab, and from the Organization list, select the organization that you want to associate with the template. Click Submit . In the Satellite web UI, navigate to Hosts > Operating Systems , and select the operating system you want to associate with the template. Click the Templates tab, and from the User data template list, select the name of the new template. 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. To use the CLI instead of the Satellite web UI, see the CLI procedure . Procedure In the Satellite web UI, navigate to Infrastructure > Compute Profiles . In the Compute Profiles window, click the name of an existing compute profile, or click Create Compute Profile , enter a Name , and click Submit . Click the name of the Red Hat Virtualization compute resource. From the Cluster list, select the target host cluster in the Red Hat Virtualization environment. From the Template list, select the RHV template to use for the Cores and Memory settings. In the Cores field, enter the number of CPU cores to allocate to the new host. In the Memory field, enter the amount of memory to allocate to the new host. From the Image list, select image to use for image-based provisioning. 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: In the Name field, enter the name of the network interface. From the Network list, select The logical network that you want to use. 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: In the Size (GB) enter the size, in GB, for the new volume. From the Storage domain list, select the storage domain for the volume. From the Preallocate disk , select either thin provisioning or preallocation of the full disk. From the Bootable list, select whether you want a bootable or non-bootable volume. Click Submit to save the compute profile. CLI procedure To create a compute profile, enter the following command: To set the values for the compute profile, enter the following command: 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 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. To use the CLI instead of the Satellite web UI, see the CLI procedure . 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 In the Satellite web UI, navigate to Hosts > Create Host . In the Name field, enter a name for the host. Click the Organization and Location tabs to ensure that the provisioning context is automatically set to the current context. From the Host Group list, select the host group that you want to use to populate the form. From the Deploy on list, select the Red Hat Virtualization connection. From the Compute Profile list, select a profile to use to automatically populate virtual machine settings. Click the Interface tab and click Edit on the host's interface. 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. Click the Operating System tab, and confirm that all fields automatically contain values. Select the Provisioning Method that you want to use: For network-based provisioning, click Network Based . For image-based provisioning, click Image Based . Click Resolve in Provisioning templates to check the new host can identify the right provisioning templates to use. 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. Click the Parameters tab, and ensure that a parameter exists that provides an activation key. If not, add an activation key. Click Submit to save the host entry. CLI procedure 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. 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. For more information about additional host creation parameters for this compute resource, enter the hammer host create --help command.

Commands:
hammer compute-resource create --name " My_RHV " --provider "Ovirt" --description "RHV server at rhv.example.com " --url " https://rhv.example.com/ovirt-engine/api " --user " Satellite_User " --password " My_Password " --locations "New York" --organizations " My_Organization " --datacenter " My_Datacenter "
install cloud-init
datasource_list: ["NoCloud", "ConfigDrive"]
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" \
<%# kind: user_data name: Cloud-init -%> #cloud-config hostname: <%= @host.shortname %> <%# Allow user to specify additional SSH key as host parameter -%> <% 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 'freeipa_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
hammer compute-profile create --name "Red Hat Virtualization CP"
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""
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"
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"