-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSatellite5_AddSystem.rb
68 lines (54 loc) · 1.8 KB
/
Satellite5_AddSystem.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
###################################
#
# CFME Automate Method: Satellite5_AddSystem
#
#
# Notes: This method adds a VM to 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.ipaddresses}>")
# Get Satellite server from model else set it here
satellite = 'satellite.rdu.salab.redhat.com'
satellite ||= $evm.object['servername']
# Satellite activation key from model else set it here
satellite_key ='2-demo'
satellite_key ||= $evm.object['activationkey']
#vm root user
vmroot = 'root'
vmroot ||= $evm.object['vmuser']
#vm root password
vmpassword = 'Redhat1!'
vmpassword ||= $evm.object['vmpassword']
# Require CFME rubygems and xmlrpc/client
require "rubygems"
require "net/ssh"
#use net/ssh to login to the new VM and activate with satellite
Net::SSH.start(vm.ip, vmroot, :password => vmpassword) do|ssh|
runcommand = ssh.exec('ls -l /var/log')
#runcommand = ssh.exec('bash < <(curl -s http://#{satellite}/pub/cfme/demo.sh)')
log(:info, "ran command:#{runcommand}")
end
# 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