Finding a Vsphere guest's id...

116 views
Skip to first unread message

Matthew Barr

unread,
May 21, 2013, 6:53:27 PM5/21/13
to ruby...@googlegroups.com
The below code was one of the ways I found to get the ID of a guest system in Vsphere. It doesn't seem to work if ARGV[0] has a dash in it.

Ideally, this would find the ID of a guest, then shut it off.

(Other methods seems to fail to find the ID, or set the instance_uuid. )

This code has been around for a few months so the bugs behind the initial attempt might have been fixed in Fog…

(Once it's fixed & vetted, I'm happy to contribute this to the docs for Vsphere. )

----

include fog
host_name=ARGV[0]

f=Fog::Compute.new(:provider => "Vsphere" )
vm=f.get_virtual_machine(host_name)
vm["instance_uuid"] = vm["id"]
vm["force"] = true
f.vm_power_off(vm)
f.vm_destroy(vm)
----

Matthew Barr
Technical Architect
E: mb...@snap-interactive.com
AIM: matthewbarr1
c: (646) 727-0535

Bruce

unread,
Nov 15, 2013, 5:14:59 PM11/15/13
to ruby...@googlegroups.com, mb...@snap-interactive.com

This isn't working for me in fog 1.18.0, connecting a vsphere 5.1.

irb(main):011:0> vm = f.get_virtual_machine(host)
Fog::Compute::Vsphere::NotFound: XXX.XXX.com was not found
from /opt/boxen/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/fog-1.18.0/lib/fog/vsphere/requests/compute/get_virtual_machine.rb:27:in `get_vm_ref'
from /opt/boxen/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/fog-1.18.0/lib/fog/vsphere/requests/compute/get_virtual_machine.rb:6:in `get_virtual_machine'
from (irb):11
from /opt/boxen/rbenv/versions/2.0.0-p247/bin/irb:12:in `<main>'
irb(main):012:0>

host contains just the hostname string.

Any ideas?

Kevin Menard

unread,
Nov 15, 2013, 5:50:35 PM11/15/13
to ruby...@googlegroups.com
Hi Bruce,
 
Do you have multiple datacenters?  If so, you probably need to pass the one you want to search through as the second argument to that call.
 
--
Kevin
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+u...@googlegroups.com.
 
Reply all
Reply to author
Forward
0 new messages