-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathonevcenterirb
executable file
·49 lines (36 loc) · 1.42 KB
/
onevcenterirb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
require 'vcenter_driver'
def vclient_host(id)
vi_client = VCenterDriver::VIClient.new_from_host(id)
end
def vm(vmid)
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vmid)
did = one_vm["DEPLOY_ID"]
hid = one_vm.retrieve_xmlelements("HISTORY_RECORDS/HISTORY/HID").last.text.to_i
VCenterDriver::VirtualMachine.new_one(vclient_host(hid), did, one_vm)
end
def ds(dsid)
one_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, dsid)
ref = one_ds["TEMPLATE/VCENTER_DS_REF"]
vc = one_ds["TEMPLATE/VCENTER_HOST"]
pool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool)
hid =pool.retrieve_xmlelements("HOST[TEMPLATE/VCENTER_HOST = '#{vc}']").first["ID"]
vi_client = vclient_host(hid)
VCenterDriver::Datastore.new_from_ref(ref, vi_client)
end
def host(hid)
vi_client = vclient_host(hid)
one_h = VCenterDriver::VIHelper.one_item(OpenNebula::Host, hid)
VCenterDriver::ClusterComputeResource.new_from_ref(one_h['TEMPLATE/VCENTER_CCR_REF'], vi_client)
end
version = ">= 0"
gem 'pry', version
load Gem.bin_path('pry', 'pry', version)