OVMCLI: Oracle VM Manager Command Line Interface

OVMCLI: Oracle VM Manager Command Line Interface

 

Oracle virtual machine manager (ovmm) is an excellent tool.  It's a GUI that can help you get your system up and running.
Since it's a GUI you can't use it to automate your environment.  The OVM command line interface is there to address that issue.
In a nutshell it's just shell that you use to communicate with the ovmm. You connect to it by ssh on port 10000 with the ovmm server.

There are many pages on the net that talks about it but none really shows you how to build a VM from scratch.
In this example I will try to mimic the virt-install  command that seems to be known by everyone.
 

Password less ssh to OVMCLI

The first step is to setup your passwordless ssh authentication with the ovmm server.
This is optional but if you don't set this up you will need to type a password everytime you connect to the ovmm server.

[root@oel75 ~]# ssh-keygen -t rsa -f ~/.ssh/admin
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/admin.
Your public key has been saved in /root/.ssh/admin.pub.
The key fingerprint is:
SHA256:ZnaU6Td7LIQ8iZMRBNZ4LKUpktAHhCLY0Xwwlgaea6Y root@oel75
The key's randomart image is:
+---[RSA 2048]----+
|o==*+ooB+        |
|=oo+*o+o+. o     |
|o =o..oo. +      |
|   o .   B o     |
|  +     S B +    |
| +     + o + +   |
|E           o o  |
|             o   |
|                 |
+----[SHA256]-----+

[root@oel75 ~]#  cat /root/.ssh/admin.pub > /home/oracle/.ssh/ovmcli_authorized_keys

[root@oel75 ~]# eval `ssh-agent`
Agent pid 4990

[root@oel75 ~]# ssh-add ~/.ssh/admin
Identity added: /root/.ssh/admin (/root/.ssh/admin)
[root@oel75 ~]# ssh admin@oel75 -p 10000
OVM> showversion
3.4.5.1919
OVM> exit
Connection to oel75 closed.

ovmcli script

This a simple script named ovmcli that we will use to connect to the ovmm server.
There is no error checking on this script.  

Look at the directory /u01/app/oracle/ovm-manager-3/ovm_cli/scripts/createdeletescripts/ for scripts with error checking.


#!/bin/bash

export ovmUser=admin
export adminServer=oel75
OVMCLI="ssh -o ServerAliveInterval=40 $ovmUser@$adminServer -p 10000"

$OVMCLI $@


VM creation
 

This is just a simple VM created and imaged using PXE.

# virt-install --hvm --connect qemu:///system \
--network=bridge:installation --pxe \
--name guest1 --ram=1024 --vcpus=2 \
--disk path=/var/lib/libvirt/images/guest1.img,size=10


In a nutshell these are the series of commands you need to run to mimic the virt-install above.
The assumptions here that you already created a repository, network and serverpool.
We will be create a VM named guest1.

ovmcli create virtualDisk name='guest1' size=10 sparse=yes  on repository name=repository1
ovmcli create VM name=guest1 domainType=XEN_HVM repository=repository1 cpuCount=2 memory=1024 memoryLimit=1024 on Serverpool name=serverpool1
ovmcli create vmDiskMapping name=diskMap1 slot=0 virtualDisk=guest1 on vm name=guest1
ovmcli create vnic name=guest1 network=network1 on vm name=guest1
ovmcli edit vm name='guest1' bootOrder='DISK,PXE'
ovmcli start vm name=guest1

 

[root@oel75 ~]# ovmcli create virtualDisk name='guest1' size=10 sparse=yes  on repository name=repository1
OVM> create virtualDisk name=guest1 size=10 sparse=yes on repository name=repository1
Command: create virtualDisk name=guest1 size=10 sparse=yes on repository name=repository1
Status: Success
Time: 2018-08-30 20:36:11,462 PDT
JobId: 1535686569373
Data:
  id:0004fb0000120000475ea096ccc2b434.img  name:guest1
OVM> Connection closed.

[root@oel75 ~]# ovmcli create VM name=guest1 domainType=XEN_HVM repository=repository1 cpuCount=2 memory=1024 memoryLimit=1024 on Serverpool name=serverpool1
OVM> create VM name=guest1 domainType=XEN_HVM repository=repository1 cpuCount=2 memory=1024 memoryLimit=1024 on Serverpool name=serverpool1
Command: create VM name=guest1 domainType=XEN_HVM repository=repository1 cpuCount=2 memory=1024 memoryLimit=1024 on Serverpool name=serverpool1
Status: Success
Time: 2018-08-30 20:36:28,247 PDT
JobId: 1535686587827
Data:
  id:0004fb000006000048a79b00bf34ce53  name:guest1
OVM> Connection closed.

[root@oel75 ~]# ovmcli create vmDiskMapping name=diskMap1 slot=0 virtualDisk=guest1 on vm name=guest1
OVM> create vmDiskMapping name=diskMap1 slot=0 virtualDisk=guest1 on vm name=guest1
Command: create vmDiskMapping name=diskMap1 slot=0 virtualDisk=guest1 on vm name=guest1
Status: Success
Time: 2018-08-30 20:37:33,383 PDT
JobId: 1535686653222
Data:
  id:0004fb00001300009b89dc4c7cf5bfdb  name:diskMap1
OVM> Connection closed.

[root@oel75 ~]# ovmcli create vnic name=guest1 macAddress=00:21:f6:03:3b:fb network=network1 on vm name=guest1
OVM> create vnic name=guest1 macAddress=00:21:f6:03:3b:fb network=network1 on vm name=guest1
Command: create vnic name=guest1 macAddress=00:21:f6:03:3b:fb network=network1 on vm name=guest1
Status: Success
Time: 2018-08-30 20:38:23,225 PDT
JobId: 1535686702803
Data:
  id:0004fb000007000012cb5dfb1db00182  name:guest1
OVM> Connection closed.

[root@oel75 ~]# ovmcli edit vm name='guest1' bootOrder='DISK,PXE'
OVM> edit vm name=guest1 bootOrder=DISK,PXE
Command: edit vm name=guest1 bootOrder=DISK,PXE
Status: Success
Time: 2018-08-30 20:38:33,563 PDT
JobId: 1535686713402
OVM> Connection closed.

[root@oel75 ~]# ovmcli start vm name=guest1
OVM> start vm name=guest1
Command: start vm name=guest1
Status: Success
Time: 2018-08-30 20:39:14,682 PDT
JobId: 1535686751739
OVM> Connection closed.


[root@oel75 ~]# ovmcli show vm name=guest1
OVM> show vm name=guest1
Command: show vm name=guest1
Status: Success
Time: 2018-08-30 20:39:33,732 PDT
Data:
  Status = Running
  Memory (MB) = 1024
  Max. Memory (MB) = 1024
  Processors = 2
  Max. Processors = 2
  Priority = 50
  Processor Cap = 100
  High Availability = No
  Viridian = No
  Operating System = None
  Mouse Type = OS Default
  Domain Type = Xen HVM
  Keymap = en-us
  Start Policy = Use Pool Policy
  Boot Order 1 = Disk
  Boot Order 2 = PXE
  Disk Limit = 4
  Huge Pages Enabled = No
  Config File Absolute Path = /dev/mapper/350014ee25fa49ce8/VirtualMachines/0004fb000006000048a79b00bf34ce53/vm.cfg
  Config File Mounted Path = /OVS/Repositories/0004fb0000030000a3fa037d6ba7e5cf/VirtualMachines/0004fb000006000048a79b00bf34ce53/vm.cfg
  Server = 00:00:00:00:00:00:00:00:00:00:6c:62:6d:3d:19:78  [ovs345]
  Server Pool = 0004fb0000020000b437a1c1d2c2d87b  [serverpool1]
  Repository = 0004fb0000030000a3fa037d6ba7e5cf  [repository1]
  Vnic 1 = 0004fb000007000012cb5dfb1db00182  [guest1]
  VmDiskMapping 1 = 0004fb00001300009b89dc4c7cf5bfdb  [diskMap1]
  Restart Action On Crash = Restart
  Id = 0004fb000006000048a79b00bf34ce53  [guest1]
  Name = guest1
  Locked = false
  DeprecatedAttrs = [Huge Pages Enabled (Deprecated for PV guest)]
OVM> Connection closed.

This is VM configuration that was created on the virtual server.
 

[root@ovs345 ~]# cat /OVS/Repositories/0004fb0000030000a3fa037d6ba7e5cf/VirtualMachines/0004fb000006000048a79b00bf34ce53/vm.cfg
vif = ['mac=00:21:f6:03:3b:fb,bridge=xenbr0']
OVM_simple_name = 'guest1'
vnclisten = '127.0.0.1'
serial = 'pty'
disk = ['file:/OVS/Repositories/0004fb0000030000a3fa037d6ba7e5cf/VirtualDisks/0004fb0000120000475ea096ccc2b434.img,xvda,w']
vncunused = 1
uuid = '0004fb00-0006-0000-48a7-9b00bf34ce53'
on_reboot = 'restart'
boot = 'cn'
cpu_weight = 27500
memory = 1024
cpu_cap = 0
maxvcpus = 2
OVM_high_availability = False
vnc = 1
OVM_description = ''
on_poweroff = 'destroy'
on_crash = 'restart'
guest_os_type = 'default'
name = '0004fb000006000048a79b00bf34ce53'
builder = 'hvm'
vcpus = 2
keymap = 'en-us'
OVM_os_type = 'None'
OVM_cpu_compat_group = ''
OVM_domain_type = 'xen_hvm'