X

A Bridge to the Cloud...

oVirt SDK: automate operations on Oracle Linux Virtualization Manager

Simon Coter, and Nirav Kamdar

Below a great article from our Oracle Linux / Virtualization experts, Nirav Kamdar - Principal Sales Consultant at Oracle, created a great technical article on how-to leverage oVirt SDK to automate operations on Oracle Linux Virtualization Manager; this one, obviously, is a quick introduction of capabilities we've with Oracle Linux Virtualization Manager.

In recent years, automation has been key operational requirement for most of the infrastructure projects. Industry is already familiar with DevOps and Infrastructure As Code (IaC). In today’s world, people need choices for various deployment types. While tools like Vagrant, Terraform, Puppet, Chef, Ansible etc. are very popular, sometimes Rest APIs and SDKs are also fit for purpose. At the end it depends on individual to select a black box highly opiniated solution or solution with Freedom of Choices.

Oracle has a new server virtualization management platform called Oracle Linux Virtualization Manager (OLVM). OLVM can be easily deployed to configure, monitor, and manage an Oracle Linux Kernel-based Virtual Machine (KVM) environment with enterprise-grade performance and support from Oracle. Oracle Linux Virtualization Manager (OLVM) is based on oVirt opensource project.

In this article, we are going to show how to leverage ovirt-engine sdk with OLVM to manage basic tasks. Please note those examples are only for testing and demonstration purpose. Oracle does provide OLVM professional services, with the engagement you can be assured the automation would be fully supported either using IaC or APIs.

Pre-requisites

  • Use Oracle Linux 7.7 or later for OLVM as well as KVM host.
  • Oracle Linux Virtualization Manager (OLVM) either hosted independent or as a Self-Host Engine (SHE).
  • Oracle Linux KVM host(s)
  • OLVM host to have internet connectivity to pull a git repository.
  • If OLVM host or the host with SDKs are behind proxy, please export dedicated ENV variables to access the desired proxy server:
    • export http_proxy=http://<proxy-host>:<proxy-port>
    • export https_proxy=http://<proxy-host>:<proxy-port>

Installation and Configuration

For this lab configuration we would be using OLVM version 4.3.6. You can use examples from the git repository https://github.com/oVirt/ovirt-engine-sdk.git as well.

Login to OLVM Host. Install required packages and clone the git repository for reference.

[sdkuser@olvm-mgr ~]$ sudo yum -y install gcc libxml2-devel python3-devel git

....

[sdkuser@olvm-mgr ~]$ git clone https://github.com/oVirt/ovirt-engine-sdk.git

Cloning into 'ovirt-engine-sdk'...

remote: Enumerating objects: 16, done.

remote: Counting objects: 100% (16/16), done.

remote: Compressing objects: 100% (15/15), done.

remote: Total 9135 (delta 5), reused 12 (delta 1), pack-reused 9119

Receiving objects: 100% (9135/9135), 6.22 MiB | 3.34 MiB/s, done.

Resolving deltas: 100% (5863/5863), done.

[sdkuser@olvm-mgr ~]$

Connection

Create a python script and import ovirtsdk4.

  • Specify the URL to OLVM api, based on your setup. url='https://<OLVM FQDN>/ovirt-engine/api'
    • Example: url='https://olvm-mgr.lab.com/ovirt-engine/api'
  • Update the password in the python script.
  • Certificate Path:
    • If you are using Self-Signed certificate, add variable “insecure=True” and hash out or remove “ca_file” variable.
    • If you are using CA certificates with OLVM, please specify the variable in the python script “ca_file='ca.pem'” and remove “insecure=True” variable.

import logging

import ovirtsdk4 as sdk

import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='olvmsdk.log')

connection = sdk.Connection(

    url='https://olvm-mgr.example.com/ovirt-engine/api',

    username='admin@internal',

    password='*********',

   #ca_file='ca.pem',

    insecure=True,

    debug=True,

    log=logging.getLogger(),

)

if connection.test(raise_exception=False):

    print("Test Connection Successful.")

else:

    print("Test Connection Unsuccessful.")

connection.close()

Test the script

[sdkuser@olvm-mgr ~]$ python test_connection.py 

Test Connection Successful.

[sdkuser@olvm-mgr ~]$

 

Operational use cases, example

We will be looking at few examples, to get an understanding on how the oVirt SDK can ve used with OLVM.

  • List VMs (list_vms.py)

Similar to test_connection.py, create a list_vms.py script. You can use the same connection block and script the functionality you want.

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import logging

import ovirtsdk4 as sdk

import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='olvmsdk.log')

connection = sdk.Connection(

    url='https://olvm-mgr.olsclab.net/ovirt-engine/api',

    username='admin@internal',

    password='*********',

   #ca_file='ca.pem',

    insecure=True,

    debug=True,

    log=logging.getLogger(),

)

vms_service = connection.system_service().vms_service()

vms = vms_service.list()

for vm in vms:

  print("%s: %s" % (vm.name, vm.id))

connection.close()

Test the script

[sdkuser@olvm-mgr ~]$ python list_vms.py 

Guest01: 663899fc-374c-42b0-8584-a02eee350df9

[sdkuser@olvm-mgr ~]$

  • Add VM (add_vm.py)

Similarly, you can add/create a VM using template. And by using python variables, you can even add multiple VMs. You can extend the script based on requirement.

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import logging

import ovirtsdk4 as sdk

import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='olvmsdk.log')

connection = sdk.Connection(

    url='https://olvm-mgr.olsclab.net/ovirt-engine/api',

    username='admin@internal',

    password='*********',

   #ca_file='ca.pem',

    insecure=True,

    debug=True,

    log=logging.getLogger(),

)

# Get the reference to the "vms" service:

vms_service = connection.system_service().vms_service()

# Use the "add" method to create a new virtual machine:

vms_service.add(

    types.Vm(

        name='ThisisnewVM',

        cluster=types.Cluster(

            name='Default',

        ),

        template=types.Template(

            name='Blank',

        ),

    ),

)

connection.close()

Test the script

[sdkuser@olvm-mgr ~]$ python add_vm.py 

[sdkuser@olvm-mgr ~]$ python list_vms.py 

Guest01: 663899fc-374c-42b0-8584-a02eee350df9

Guest02: 3b155982-2e9c-43fb-a08c-61e6994e1b0c

ThisisnewVM: a2424984-fc9b-4e1c-bbb8-04dd47aa1119

[sdkuser@olvm-mgr ~]$

Conclusion

This SDK is extensible and various other use cases can be implemented based on requirements. For example, taking snapshots, adding VM, adding various resources, generate inventory etc.

References

oVirt REST API documentation 
oVirt Engine API Python SDK

Join the discussion

Comments ( 2 )
  • Antoine Bonello Friday, September 18, 2020
    Hello Simon
    We have an two node Oracle RAC sitting on 2 vms in an OLVM. Do you recommend setting up SR-IOV on the vms where the RAC and databases reside ? And what are the cons and pros please?

    Best Regards
  • Simon Monday, September 21, 2020
    Hi Antoine,

    this is a question not related to the article above.
    I would suggest you to reach out Oracle Support through MyOracle Support website so you'll have the opportunity to get a feedback from both KVM as well as Oracle Database experts.
    Thanks

    Simon
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.