org.paulneve.wlab.virtualisation
Class VirtualisationAccessHyperVImpl

java.lang.Object
  extended by org.paulneve.wlab.virtualisation.VirtualisationAccessHyperVImpl
All Implemented Interfaces:
VirtualisationAccess

public class VirtualisationAccessHyperVImpl
extends java.lang.Object
implements VirtualisationAccess

Implements VirtualisationAccess for the Microsoft HyperV virtualisation backend. Undocumented public getters/setters have values injected via Spring - consult the comments in application-properties.xml for details of what they do.

Author:
Paul Neve

Field Summary
(package private)  java.lang.String diskPath
           
(package private)  int octet1
           
(package private)  int octet2
           
(package private)  int octet3
           
(package private)  java.lang.String password
           
(package private)  java.lang.String serverName
           
(package private)  java.lang.String username
           
 
Constructor Summary
VirtualisationAccessHyperVImpl()
          Constructor - turns off ridiculously verbose logging on J-Interop library that comes with JWBEM.
 
Method Summary
 void addNetworkAdapter(com.h9labs.jwbem.msvm.virtualsystemmanagement.MsvmVirtualSystemManagementService vsMgt, com.h9labs.jwbem.msvm.virtualsystem.MsvmComputerSystem realVm, boolean legacy)
          Adds a network adapter to a VM.
 java.lang.String cloneVM(java.lang.String nameOfParent, java.lang.String nameOfClone)
          Sends a request to clone a VM.
 boolean createNewVM(java.lang.String nameOfNewVm)
          Creates a new VM.
 void deleteFile(java.lang.String filename)
          Deletes a file off of the backend (i.e.
 void deleteSnapshot(java.lang.String name, int index)
          Delete snapshot from VM
 void deleteVM(java.lang.String name)
          Sends a request to delete a VM.
 java.lang.String getDiskPath()
           
 int getNumberOfCurrentlyRunningVMs()
          Does precisely what it says.
 int getOctet1()
           
 int getOctet2()
           
 int getOctet3()
           
 java.lang.String getPassword()
           
 java.lang.String getServerName()
           
 java.lang.String getUsername()
           
 java.lang.String getVMIP(java.lang.String name)
          Gets the IP address(es) of a VM.
 java.lang.String getVMStatus(java.lang.String name)
          Gets a VM status.
 boolean isAlive(java.lang.String name)
          Determines whether a VM is "alive" or not.
 java.util.ArrayList<java.lang.String> listVMs()
          Does precisely what it says.
 int numberOfSnapshots(java.lang.String name)
          Returns number of snapshots that VM /name/ has.
 void revertToSnapshot(java.lang.String nameOfVm, int index)
          Reverts VM /name/ to snapshot /index/, where the first snapshot (usually the start point of the stage) is 0
 void setDiskPath(java.lang.String diskPath)
           
 void setOctet1(int r1)
           
 void setOctet2(int r2)
           
 void setOctet3(int r3)
           
 void setParameters(Parameters p)
           
 void setPassword(java.lang.String password)
           
 void setServerName(java.lang.String serverName)
           
 void setStrings(Strings s)
           
 void setUsername(java.lang.String username)
           
 void snapshotVm(java.lang.String nameOfVm)
          Takes a snapshot of VM
 void startVM(java.lang.String name)
          Sends a request to start a VM from either a stopped or suspended state.
 void suspendVM(java.lang.String name)
          Sends a request to suspend a VM that is currently running.
 void turnOffVM(java.lang.String name)
          "Hard" power down a VM, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverName

java.lang.String serverName

username

java.lang.String username

password

java.lang.String password

diskPath

java.lang.String diskPath

octet1

int octet1

octet2

int octet2

octet3

int octet3
Constructor Detail

VirtualisationAccessHyperVImpl

public VirtualisationAccessHyperVImpl()
Constructor - turns off ridiculously verbose logging on J-Interop library that comes with JWBEM.

Method Detail

cloneVM

public java.lang.String cloneVM(java.lang.String nameOfParent,
                                java.lang.String nameOfClone)
Description copied from interface: VirtualisationAccess
Sends a request to clone a VM.

Specified by:
cloneVM in interface VirtualisationAccess
Parameters:
nameOfParent - string, name of parent VM to clone
nameOfClone - string, name of the new clone
Returns:
return nameOfClone, unless unsuccesful, in which case null

isAlive

public boolean isAlive(java.lang.String name)
Description copied from interface: VirtualisationAccess
Determines whether a VM is "alive" or not. This is different to it's status at the virtualisation back end. A VM that is alive should (in theory) be ready to connect to via VNC. A VM that merely has a status of "started" might still be in the boot process.

Specified by:
isAlive in interface VirtualisationAccess
Parameters:
name - name of VM to check.
Returns:
true or false, i.e. true if it's "alive"

deleteVM

public void deleteVM(java.lang.String name)
Description copied from interface: VirtualisationAccess
Sends a request to delete a VM.

Specified by:
deleteVM in interface VirtualisationAccess
Parameters:
name - Name of the VM to delete

snapshotVm

public void snapshotVm(java.lang.String nameOfVm)
Description copied from interface: VirtualisationAccess
Takes a snapshot of VM

Specified by:
snapshotVm in interface VirtualisationAccess
Parameters:
nameOfVm - string, i.e. name of VM to create a snapshot for

revertToSnapshot

public void revertToSnapshot(java.lang.String nameOfVm,
                             int index)
Description copied from interface: VirtualisationAccess
Reverts VM /name/ to snapshot /index/, where the first snapshot (usually the start point of the stage) is 0

Specified by:
revertToSnapshot in interface VirtualisationAccess
Parameters:
nameOfVm - name of VM
index - integer, snapshot number to rever to

numberOfSnapshots

public int numberOfSnapshots(java.lang.String name)
Description copied from interface: VirtualisationAccess
Returns number of snapshots that VM /name/ has.

Specified by:
numberOfSnapshots in interface VirtualisationAccess
Parameters:
name - string, name of VM to get data for

deleteSnapshot

public void deleteSnapshot(java.lang.String name,
                           int index)
Description copied from interface: VirtualisationAccess
Delete snapshot from VM

Specified by:
deleteSnapshot in interface VirtualisationAccess
Parameters:
name - name of VM to delete snapshot on
index - index of snapshot to delete - 0 is first, usually the base snapshot for start of stage

getVMIP

public java.lang.String getVMIP(java.lang.String name)
Description copied from interface: VirtualisationAccess
Gets the IP address(es) of a VM. Depending on your virtualisation layer, you might want to make use of org.paulneve.wlab.utilitiesMacToIP to derive the IP from the virtual network card's MAC address, if the virtualisation layer cannot get you an IP via a more direct route.

The IP addresses returned should be relative to the WLab server, i.e. ones which can be routed to from the WLab server. External access will use Jumpgate to route through via a single exposed external port/IP.

Specified by:
getVMIP in interface VirtualisationAccess
Parameters:
name - Name of VM
Returns:
a string, containing IP addresses in form XXX.XXX.XXX.XXX, separated with commas, no spaces.

getVMStatus

public java.lang.String getVMStatus(java.lang.String name)
Description copied from interface: VirtualisationAccess
Gets a VM status. Returned statuses should be one of "Started" "Stopped" "Suspended" "Changing state" "Unknown"

Specified by:
getVMStatus in interface VirtualisationAccess
Parameters:
name - Name of VM to return status of
Returns:
One of the specified status strings.

listVMs

public java.util.ArrayList<java.lang.String> listVMs()
Description copied from interface: VirtualisationAccess
Does precisely what it says.

Specified by:
listVMs in interface VirtualisationAccess
Returns:
An arraylist of strings, with the names of the VMs available on the backend.

startVM

public void startVM(java.lang.String name)
Description copied from interface: VirtualisationAccess
Sends a request to start a VM from either a stopped or suspended state.

Specified by:
startVM in interface VirtualisationAccess
Parameters:
name - Name of the VM to start.

turnOffVM

public void turnOffVM(java.lang.String name)
Description copied from interface: VirtualisationAccess
"Hard" power down a VM, i.e. turns it off immediately

Specified by:
turnOffVM in interface VirtualisationAccess
Parameters:
name - Name of the VM to turn off.

suspendVM

public void suspendVM(java.lang.String name)
Description copied from interface: VirtualisationAccess
Sends a request to suspend a VM that is currently running.

Specified by:
suspendVM in interface VirtualisationAccess
Parameters:
name - Name of the VM to suspend.

getNumberOfCurrentlyRunningVMs

public int getNumberOfCurrentlyRunningVMs()
Description copied from interface: VirtualisationAccess
Does precisely what it says.

Specified by:
getNumberOfCurrentlyRunningVMs in interface VirtualisationAccess
Returns:
The answer to life the universe, and everything. Oh, no, actually this just returns the number of currently running VMs. You'd never have guessed that really.

createNewVM

public boolean createNewVM(java.lang.String nameOfNewVm)
Creates a new VM. Heavily cribbed from the source of the JASMINE project - specifically, org.ow2.jasmine.vmm.agent.driver.hyperv - being one of the only resources on the internet that gives a decent howto of manipulating HyperV with JWBEM/JInterop.

Parameters:
nameOfNewVm - name of VM to create
Returns:
boolean true if successful, false if not.

deleteFile

public void deleteFile(java.lang.String filename)
Deletes a file off of the backend (i.e. for unwanted VHD files). This has to use DCOM as there is no direct way of deleting hard disk files in Hyper-V's own WMI namespace. Again, heavily cribbed from JASMINe.

Parameters:
filename - file to delete

addNetworkAdapter

public void addNetworkAdapter(com.h9labs.jwbem.msvm.virtualsystemmanagement.MsvmVirtualSystemManagementService vsMgt,
                              com.h9labs.jwbem.msvm.virtualsystem.MsvmComputerSystem realVm,
                              boolean legacy)
Adds a network adapter to a VM. This is almost identical to addNetworkAdapter in org.ow2.jasmine.vmm.agent.driver.hyperv.

Parameters:
vsMgt - a MsvmVirtualSystemManagementService object
realVm - a virtual machine, in the form of a MsvmComputerSystem object
legacy - true if we're adding a legacy network adapter, false if not

getServerName

public java.lang.String getServerName()

setServerName

public void setServerName(java.lang.String serverName)

getUsername

public java.lang.String getUsername()

setUsername

public void setUsername(java.lang.String username)

getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)

getOctet1

public int getOctet1()

setOctet1

public void setOctet1(int r1)

getOctet2

public int getOctet2()

setOctet2

public void setOctet2(int r2)

getOctet3

public int getOctet3()

setOctet3

public void setOctet3(int r3)

getDiskPath

public java.lang.String getDiskPath()

setDiskPath

public void setDiskPath(java.lang.String diskPath)

setParameters

public void setParameters(Parameters p)

setStrings

public void setStrings(Strings s)