Declarative IaC for Automating VM Resources

Introduction

One of the advantages of OpenShift and Kubernetes is that its configuration is managed with declarative YAML manifests. The configuration of VMs running on OpenShift is the same. In other systems, automating the creation of new virtual machine instances or managing the configuration of existing virtual machines often requires an understanding of complex IaC languages.

In this module you will increase the CPU resources dedicated to a VM using techniques easily adopted by any IaC system.

Verifying Initial CPU Core Count

  1. To find the VM to change, click on the left bar, click Virtualization → VirtualMachines On the top bar, select the Project windowsnetworking-sample_username.

    Find winweb01 VM
    Figure 1. Identifying the winweb01 virtual machine
  2. Click on the winweb01 VM. Notice the CPU | Memory section on the Overview tab.

    winweb01 CPU and RAM
    Figure 2. CPU and Memory consumption of the VM
  3. Verify the number of cores via powershell in the winweb01 console.

    1. Click on the Console tab, and click into the black console box to activate input into the VM console.

    2. Start Powershell by entering 15 in the menu.

      SConfig
      Figure 3. Accessing MicroSoft SConfig
    3. Copy the following command into your clipboard.

      Get-CimInstance -ClassName win32_processor | Select NumberofCores
  4. Now paste it into the VM console with the Paste button.

    winweb01 numcores 1
    Figure 4. Accessing the console to view number of cores before IaC reconfiguration

Increasing CPU Core Count

  1. To increase the CPU core count via IaC, click the YAML tab and scroll down until you see cpu. On approximately line 190, modify cores to increase the core count from 1 to 2.

  2. Click Save

    winweb01 CPU 2 cores
    Figure 5. Changing the number of cores with a YAML edit
  3. To restart the winweb01 VM, click the circular arrow ↻.

  4. Wait for the winweb01 VM to restart.

  5. Verify the number of cores via Powershell in the winweb01 console.

    1. Click on the Console tab, and click into the black console box to activate input into the VM console.

    2. As before, start Powershell by entering 15 in the menu.

    3. To reveal the new number of cores, Copy/Paste the following command into the VM console with the Paste button.

      Get-CimInstance -ClassName win32_processor | Select NumberofCores
      winweb01 numcores 2
      Figure 6. Verifying actual change to number of CPUs
You can also use Infrastructure as Code to trigger the necessary restart. You could implement a pipeline that reconfigures the virtual machine, then uses a Job running virtctl to restart the virtual machine.

Congratulations

You have increased the resources available to a virtual machine via Infrastructure as Code. You can imagine from this example how you might automate the resource reconfiguration from a IaC tool, or from a pipeline.