Last active
August 29, 2015 13:57
-
-
Save stefancocora/9803779 to your computer and use it in GitHub Desktop.
prototyping creation of blank VM via fog in vsphere 4.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
### | |
### DISCLAIMER - this example is not working yet | |
### more info on this fog github issue - https://github.com/fog/fog/issues/2798 | |
### | |
require 'fog' | |
require 'pp' | |
$user = 'foo' | |
$pass= 'foo' | |
$server = '10.210.9.20' | |
credentials = { | |
:provider => "vsphere", | |
:vsphere_username => $user, | |
:vsphere_password=> $pass, | |
:vsphere_server => $server, | |
:vsphere_ssl => true, | |
:vsphere_expected_pubkey_hash => "f2a6a2f86562d94fcbfcaa41dd132bc120c996344e1bb357a018d19190d37633" | |
} | |
$connection = Fog::Compute.new(credentials) | |
$grwmgm_datacenter='DC-GRW-CLUSTER' | |
$grwmgm_cluster = 'DC-CLUSTER' | |
$grwmgm_datastore = 'GRW_VMCP_MGMT_DATA_003' | |
$grwmgm_folder = 'GRW-CP-FOLDER' | |
puts "creating new VM" | |
volume_attributes = { | |
"id" => "5303693f-eae09bc7-2dc5-0017a4772800", | |
"datastore" => $grwmgm_datastore, | |
"mode" => "persistent", | |
"size" => 8388608, | |
"thin" => true, | |
"name" => "fogtest01", | |
"size_gb" => 8 | |
} | |
volume_details = $connection.volumes.new(volume_attributes) | |
interface_attributes = { | |
"network" => "GRW-CP-MGMT-INFRA-923", | |
"name" => "GRW-CP-MGMT-INFRA-923", | |
"status" => "ok", | |
"summary" => "VM Network", | |
} | |
interface_details = $connection.interfaces.new(interface_attributes) | |
attributes = { | |
:name => 'fogtest01', | |
:memory => '1024', | |
:path => 'datastores/GRW_VMCP_MGMT_DATA_003', | |
:datacenter => $grwmgm_datacenter, | |
:datastore => $grwmgm_datastore, | |
:resource_pool => "MGMT", | |
:volumes => [volume_details], | |
:interfaces => [interface_details], | |
:guest_id => 'centos64Guest', | |
:cluster => $grwmgm_cluster | |
} | |
new_vm = $connection.create_vm(attributes) | |
pp new_vm | |
Error that I get when running it is: | |
/home/stefan/.rvm/gems/ruby-1.9.3-p392@fog/gems/fog-1.16.0/lib/fog/vsphere/requests/compute/create_vm.rb:27:in `rescue in create_vm': failed to create vm: Could not descend into datastores. Please check your path. datastores/GRW_VMCP_MGMT_DATA_003 (ArgumentError) | |
from /home/stefan/.rvm/gems/ruby-1.9.3-p392@fog/gems/fog-1.16.0/lib/fog/vsphere/requests/compute/create_vm.rb:9:in `create_vm' | |
from ./vsphere-grw_mgm-create_vm-prototype.rb:63:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussion moved to fog/fog#2798