Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick gist on getting vsphere and vcenter and fog/vsphere going
Quick gist on getting vsphere and vcenter and fog/vsphere going
# Things to download
- Download free evaluation version of window 2008
- Download free evaluation of esxi v5
- Download free evaluation of esxi vsphere (control center) iso
# Install esxi in vmware fusion
1)Install esxi in vmware (select vmware/esx as host)
create a user root/pipopopo
results in http://172.16.44.140/
# Install windows 2008
In a second fusion vm install win2008 in Vmware fusion (select Enterprise version)
win2008-enterprise-vsphere-v5
mount the vm-all...-iso
# On windows 2008 + Vcenter
- install vcenter server
- English,
will install visual C++ 5 , .NET framework
agree to license
username: some name, organization: some org, license key: blank
Install SQL Server 2008 Express
Use System Account
Warning on FQDN not resolvable
Stand alone Vcenter Server instance
Agree to ports
HTTPS port 10443, Smgt port 10109 Linked Communications Port 10111
Inventory size (small)
Don't need extra ephemeral ports
- install vsphere client
installs visual j, ....
Note the Ip address 172.16.44.141
# On win2008 install vsphere client
Login to the vsphere machine (windows machine IP-address) using vsphere client
ignore the SSL certificate mismatch
use windows session credentials
# Start vsphere client and import esxi (ip from first vm)
See http://blogs.vmware.com/kbtv/2011/08/getting-started-with-vsphere-5-adding-esx-hosts-into-vcenter-server.html
- login and select datacenters tab
right click -> new datacenter
rename it to Test Datacenter
now add a host (root/pipopopo, IP address)
trust the certificate
Continue the wizard
No license key
Don't enable lockdown
e) set a password for the user (under which you installed vcenter)
needs to be an administrator
Needs to be a complex password
pipo1234**
# On the ruby side
- Install rbvmomi (1.3.0 installed)
- get the latest fog from github (0.11)
# Login via the vsphere console + create vm
create a vm
clone it as a template (test template)
#Connect to the *vcenter* machine fog (windows vm)
Correct hash if needed
f=Fog::Compute.new(:provider => "vsphere", :vsphere_username => "patrick", :vsphere_password=> "pipo1234**", :vsphere_server => "172.16.44.141", :vsphere_expected_pubkey_hash => "74e6f3f9a9d50be352aa0fabcdc1df9977016af38da538cf76b3ba56a6363d11")
# FYI you can also connect to the vshere directly but no write/cloning possible)
>> Fog::Compute.new(:provider => "vsphere", :vsphere_username => "root", :vsphere_password=> "pipopopo", :vsphere_server => "172.16.44.140")
Fog::Vsphere::Errors::SecurityError: The remote system presented a public key with hash 39b9675b5e8ac71bae40a3fc22ee0a648a250c0997d69aedc181cccb4185f9f0 but we're expecting a hash of <unset>. If you are sure the remote system is authentic set vsphere_expected_pubkey_hash: <the hash printed in this message> in ~/.fog
# List the servers
>> f.servers
<Fog::Compute::Vsphere::Servers
[
<Fog::Compute::Vsphere::Server
id="501b12d9-18c1-e123-ceff-97292ef15bdf",
name="test template",
uuid="421bcca9-14b5-2a5f-a564-f3ec8f07ea4f",
instance_uuid="501b12d9-18c1-e123-ceff-97292ef15bdf",
hostname=nil,
operatingsystem=nil,
ipaddress=nil,
power_state="poweredOff",
tools_state="toolsNotInstalled",
tools_version="guestToolsNotInstalled",
mac_addresses={"Network adapter 1"=>"00:50:56:9b:67:33"},
hypervisor="172.16.44.140",
is_a_template=true,
connection_state="connected",
mo_ref="vm-13"
>,
<Fog::Compute::Vsphere::Server
id="52cc1f29-1015-577c-a2bb-ceb37a8b6675",
name="testvm",
uuid="564d7664-78ee-ae6b-cd0e-ce8754385c09",
instance_uuid="52cc1f29-1015-577c-a2bb-ceb37a8b6675",
hostname=nil,
operatingsystem=nil,
ipaddress=nil,
power_state="poweredOff",
tools_state="toolsNotInstalled",
tools_version="guestToolsNotInstalled",
mac_addresses={"Network adapter 1"=>"00:50:56:9b:67:32"},
hypervisor="172.16.44.140",
is_a_template=false,
connection_state="connected",
mo_ref="vm-12"
>
]
>
#Clone a template
new_vm=f.vm_clone('instance_uuid' => '501b12d9-18c1-e123-ceff-97292ef15bdf', 'name' => 'clonedvm'){"vm_ref"=>"vm-14", "task_ref"=>"task-5"}
>> f.servers.all
<Fog::Compute::Vsphere::Servers
[
<Fog::Compute::Vsphere::Server
id="501b928f-1935-7823-0600-459ff79cc783",
name="clonedvm",
uuid="421bf66f-cf21-0985-f604-2866ed1e59fd",
instance_uuid="501b928f-1935-7823-0600-459ff79cc783",
hostname=nil,
operatingsystem=nil,
ipaddress=nil,
power_state="poweredOn",
tools_state="toolsNotInstalled",
tools_version="guestToolsNotInstalled",
mac_addresses={"Network adapter 1"=>"00:50:56:9b:67:34"},
hypervisor="172.16.44.140",
is_a_template=false,
connection_state="connected",
mo_ref="vm-14"
>,
<Fog::Compute::Vsphere::Server
id="501b12d9-18c1-e123-ceff-97292ef15bdf",
name="test template",
uuid="421bcca9-14b5-2a5f-a564-f3ec8f07ea4f",
instance_uuid="501b12d9-18c1-e123-ceff-97292ef15bdf",
hostname=nil,
operatingsystem=nil,
ipaddress=nil,
power_state="poweredOff",
tools_state="toolsNotInstalled",
tools_version="guestToolsNotInstalled",
mac_addresses={"Network adapter 1"=>"00:50:56:9b:67:33"},
hypervisor="172.16.44.140",
is_a_template=true,
connection_state="connected",
mo_ref="vm-13"
>,
<Fog::Compute::Vsphere::Server
id="52cc1f29-1015-577c-a2bb-ceb37a8b6675",
name="testvm",
uuid="564d7664-78ee-ae6b-cd0e-ce8754385c09",
instance_uuid="52cc1f29-1015-577c-a2bb-ceb37a8b6675",
hostname=nil,
operatingsystem=nil,
ipaddress=nil,
power_state="poweredOff",
tools_state="toolsNotInstalled",
tools_version="guestToolsNotInstalled",
mac_addresses={"Network adapter 1"=>"00:50:56:9b:67:32"},
hypervisor="172.16.44.140",
is_a_template=false,
connection_state="connected",
mo_ref="vm-12"
>
]
>
@stonith
Copy link

stonith commented May 22, 2014

Have you tried vSphere 5.5? I'm trying this gist and running into an error with vSphere 5.5:

?> f.servers
RuntimeError: unknown VMODL type AnyType

UPDATE: Looks like rbmomi > 1.6.0 breaks vSphere. Installing 1.6.0 got me past this error.

@Karunamon
Copy link

Karunamon commented Aug 7, 2014

Specifically, Nokogiri > 1.5.5. Newer revs of RbVmomi works with that one dependency forced.

@obazoud
Copy link

obazoud commented Nov 5, 2014

Got this error, any idea ?

gems/nokogiri-1.6.4/lib/nokogiri/xml/node.rb:159:in `evaluate': Undefined namespace prefix: //soapenv:Body/* (Nokogiri::XML::XPath::SyntaxError)
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/nokogiri-1.6.4/lib/nokogiri/xml/node.rb:159:in `block in xpath'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/nokogiri-1.6.4/lib/nokogiri/xml/node.rb:150:in `map'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/nokogiri-1.6.4/lib/nokogiri/xml/node.rb:150:in `xpath'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/rbvmomi-1.8.2/lib/rbvmomi/trivial_soap.rb:112:in `request'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/rbvmomi-1.8.2/lib/rbvmomi/connection.rb:87:in `call'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/rbvmomi-1.8.2/lib/rbvmomi/basic_types.rb:205:in `_call'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/rbvmomi-1.8.2/lib/rbvmomi/basic_types.rb:74:in `block (2 levels) in init'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/rbvmomi-1.8.2/lib/rbvmomi/vim.rb:68:in `serviceContent'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/fog-1.24.0/lib/fog/vsphere/compute.rb:370:in `negotiate_revision'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/fog-1.24.0/lib/fog/vsphere/compute.rb:349:in `initialize'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/fog-core-1.24.0/lib/fog/core/service.rb:115:in `new'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/fog-core-1.24.0/lib/fog/core/service.rb:115:in `new'
    from /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/fog-core-1.24.0/lib/fog/compute.rb:58:in `new'
    from test.rb:6:in `<main>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment