Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am grier on github.
* I am grier (https://keybase.io/grier) on keybase.
* I have a public key whose fingerprint is AF58 9598 C074 1AFE FD2F AEDA 30EA 25BF 7546 63ED
To claim this, I am signing this object:
@grier
grier / snapshot.java
Created February 13, 2012 07:11
vSphere API - Snapshot.java
public static void doSnapshot(String url, String username, String password, String vmname, String snapshotname) throws Exception
{
ServiceInstance si = new ServiceInstance(new URL(url), username, password, true);
Folder rootFolder = si.getRootFolder();
VirtualMachine vm = null;
vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname);
if(vm==null)
{
@grier
grier / changevnc.java
Created February 13, 2012 07:10
vSphere API - Change VNC settings
public static void doChangeVnc(String url, String username, String password, String vmname, String vncport) throws Exception
{
ServiceInstance si = new ServiceInstance(new URL(url), username, password, true);
Folder rootFolder = si.getRootFolder();
VirtualMachine vm = null;
vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname);
if(vm==null)
{
@grier
grier / editnic.java
Created February 13, 2012 07:07
vSphere API - Edit VM network interface
public static void doChangeNic(String url, String username, String password, String hostname, String vmname, String portGroup)
{
ServiceInstance si = new ServiceInstance(new URL(url), username, password, true);
Folder rootFolder = si.getRootFolder();
VirtualMachine vm = null;
HostSystem host = null;
vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname);
host = (HostSystem) new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem", hostname);
@grier
grier / linkedclone.java
Created February 8, 2012 23:41
vSphere API - Create Linked Clone
public static void doClone(String url, String username, String password, String vmname, String clonename) throws Exception
{
ServiceInstance si = new ServiceInstance(new URL(url), username, password, true);
Folder rootFolder = si.getRootFolder();
VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname);
if(vm==null)
{
System.out.println("VM " + vmname + " not found");