Skip to content

Instantly share code, notes, and snippets.

@aussielunix
Created May 8, 2012 13:38
Show Gist options
  • Save aussielunix/2635083 to your computer and use it in GitHub Desktop.
Save aussielunix/2635083 to your computer and use it in GitHub Desktop.
create blank vsphere VM
#!/usr/bin/env ruby
require 'rubygems'
require 'pp'
require 'fog'
credentials = {
:provider => "vsphere",
:vsphere_username => "foo",
:vsphere_password=> "bar",
:vsphere_server => "vsphere.vmware",
:vsphere_ssl => true,
:vsphere_expected_pubkey_hash => "4762840587whjck49hxkdl39shjxl490"
}
compute = Fog::Compute.new(credentials)
vms = compute.servers.all('folder' => '/Datacenters/Australia/syd07/')
puts "creating new VM"
new_vm = compute.vm_create(
'name' => 'mp-pxe-tst-01',
'memory' => '1024',
'path' => '/Datacenters/Australia/syd07/',
'datastore' => 'dcau-playpen-t2',
'guest_id' => 'ubuntu64Guest',
'cluster' => 'DCAU 07',
'device_array' => [{
:operation => :add,
:device => RbVmomi::VIM.VirtualLsiLogicController(
:key => 1000,
:busNumber => 0,
:sharedBus => :noSharing
)
},{
:operation => :add,
:fileOperation => :create,
:device => RbVmomi::VIM.VirtualDisk(
:key => 0,
:backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
:fileName => '[dcau-playpen-t2]',
:diskMode => :persistent,
:thinProvisioned => false
),
:controllerKey => 1000,
:unitNumber => 0,
:capacityInKB => 9000000
)
},{
:operation => :add,
:device => RbVmomi::VIM.VirtualE1000(
:key => 10,
:deviceInfo => {
:label => 'Network Adapter 1',
:summary => 'Network'
},
:backing => RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
:deviceName => 'Network Adapter 1'
),
:macAddress => '00:32:32:32:32:32',
:addressType => 'manual'
)
}]
)
pp new_vm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment