-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSatellite5_GetSystemID.rb
69 lines (55 loc) · 2.07 KB
/
Satellite5_GetSystemID.rb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
###################################
#
# CFME Automate Method: Satellite5_GetSystemID
#
#
# Notes: This method gets a VM system id from Satellite v5
#
###################################
begin
# Method for logging
def log(level, message)
@method = 'getsystemid'
$evm.log(level, "#{@method}: #{message}")
end
log(:info, "CFME Automate Method Started")
# Dump all root attributes
log(:info, "Listing Root Object Attributes:")
$evm.root.attributes.sort.each { |k, v| log(:info, "\t#{k}: #{v}") }
log(:info, "===========================================")
# Get vm object from the VM class versus the VmOrTemplate class for vm.remove_from_service to work
vm = $evm.vmdb("vm", $evm.root['vm_id'])
raise "$evm.root['vm'] not found" if vm.nil?
log(:info, "Found VM:<#{vm.name}>")
# Get Satellite server from model else set it here
satellite = 'satellite.phx.salab.redhat.com'
satellite ||= $evm.object['servername']
# Get Satellite url from model else set it here
satellite_url = "/rpc/api"
satellite_url ||= $evm.object['serverurl']
# Get Satellite username from model else set it here
username = 'satadmin'
username ||= $evm.object['username']
# Get Satellite password from model else set it here
password = 'Redhat1!'
password ||= $evm.object.decrypt('password')
# Require CFME rubygems and xmlrpc/client
require "rubygems"
require "xmlrpc/client"
xmlrpc_client = XMLRPC::Client.new(satellite, satellite_url)
log(:info, "xmlrpc_client: #{xmlrpc_client.inspect}")
xmlrpc_key = xmlrpc_client.call('auth.login', username, password)
log(:info, "xmlrpc_key: #{xmlrpc_key.inspect}")
#get the system id
satellite_getsysid = xmlrpc_client.call('system.getId', xmlrpc_key, vm.name)
log(:info, "satellite_getsysid: #{satellite_getsysid.inspect}")
satellite_systemid = satellite_getsysid[0]["id"]
log(:info, "satellite_getsysid: #{satellite_systemid.inspect}")
# Exit method
log(:info, "CFME Automate Method Ended")
exit MIQ_OK
# Ruby rescue
rescue => err
log(:error, "[#{err}]\n#{err.backtrace.join("\n")}")
exit MIQ_STOP
end