Class: KnifeESX::DeployJob
- Inherits:
-
Object
- Object
- KnifeESX::DeployJob
- Defined in:
- lib/chef/knife/esx_vm_create.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(options) ⇒ DeployJob
constructor
A new instance of DeployJob.
-
#run ⇒ Object
returns [status, stdout, stderr].
- #validate ⇒ Object
Constructor Details
#initialize(options) ⇒ DeployJob
Returns a new instance of DeployJob.
63 64 65 66 |
# File 'lib/chef/knife/esx_vm_create.rb', line 63 def initialize() @name, @options = validate end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
61 62 63 |
# File 'lib/chef/knife/esx_vm_create.rb', line 61 def name @name end |
Instance Method Details
#run ⇒ Object
returns [status, stdout, stderr]
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/chef/knife/esx_vm_create.rb', line 78 def run args = "" extra_args = "" @options.each do |k, v| if k == 'extra-args' extra_args << v else args << "--#{k} #{v} " unless k == 'extra-args' end end @out = "" @err = "" optstring = [] @options.each do |k,v| optstring << " - #{k}:".ljust(25) + "#{v}\n" unless k =~ /password/ end log_file = "/tmp/knife_esx_vm_create_#{@name.to_s.strip.chomp.gsub(/\s/,'_')}.log" Chef::Log.info "Bootstrapping VM #{@name} \n#{optstring.join}" Chef::Log.info "VM #{@name} bootstrap log: #{log_file}" @status = Open4.popen4("knife esx vm create --vm-name #{@name} #{args} #{extra_args} > #{log_file} 2>&1") do |pid, stdin, stdout, stderr| @out << stdout.read.strip @err << stderr.read.strip end if @status == 0 Chef::Log.info "[#{@name}] deployment finished OK" else Chef::Log.error "[#{@name}] deployment FAILED" @err.each_line do |l| Chef::Log.error "[#{@name}] #{l.chomp}" end end return @status, @out, @err end |
#validate ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/chef/knife/esx_vm_create.rb', line 68 def validate if @name.nil? or @name.empty? raise Exception.new("Invalid job name") end if not @options['vm-disk'] or !File.exist?(@options['vm-disk']) raise Exception.new("Invalid VM disk for job #{@name}.") end end |