Add some basic VM annotation

This commit is contained in:
Scott Schneider 2013-10-31 12:25:07 -07:00
parent bf0150de4b
commit e6e05b99ab

View file

@ -223,13 +223,20 @@ loop do
end end
if vm['template'].length == 0 if vm['template'].length == 0
raise "Unable to find template '#{h['template']}'!" raise "Unable to find template '#{vm['template']}'!"
end end
# Generate a randomized hostname # Generate a randomized hostname
o = [('a'..'z'),('0'..'9')].map{|r| r.to_a}.flatten o = [('a'..'z'),('0'..'9')].map{|r| r.to_a}.flatten
vm['hostname'] = o[rand(25)]+(0...14).map{o[rand(o.length)]}.join vm['hostname'] = o[rand(25)]+(0...14).map{o[rand(o.length)]}.join
# Annotate with creation time, origin template, etc.
configSpec = RbVmomi::VIM.VirtualMachineConfigSpec(
:annotation =>
'Base template: ' + vm['template'] + "\n" +
'Creation time: ' + Time.now.strftime("%Y-%m-%d %H:%M")
)
# Put the VM in the specified folder and resource pool # Put the VM in the specified folder and resource pool
relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec( relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec(
:datastore => vsphere_helper.find_datastore(pool['datastore']), :datastore => vsphere_helper.find_datastore(pool['datastore']),
@ -240,6 +247,7 @@ loop do
# Create a clone spec # Create a clone spec
spec = RbVmomi::VIM.VirtualMachineCloneSpec( spec = RbVmomi::VIM.VirtualMachineCloneSpec(
:location => relocateSpec, :location => relocateSpec,
:config => configSpec,
:powerOn => true, :powerOn => true,
:template => false :template => false
) )