Class: BoxGrinder::ESXDelivery

Inherits:
BasePlugin
  • Object
show all
Defined in:
lib/esx-delivery-plugin.rb

Instance Method Summary collapse

Instance Method Details

#create_vm(disk_file) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/esx-delivery-plugin.rb', line 34

def create_vm(disk_file)
  host = ESX::Host.connect @plugin_config['esx_host'], @plugin_config['esx_user'], @plugin_config['esx_password']
  datastore = @plugin_config['datastore']
  memory = @plugin_config['memory']
  name = @appliance_config.name
  guest_id = @plugin_config['otherGuest']
  @log.info "Creating VM using #{File.basename(disk_file)}..."

  @log.info "Uploading and converting disk..."
  @log.debug "Creating remote dir /vmfs/volumes/#{datastore}/#{name}"
  host.remote_command "mkdir /vmfs/volumes/#{datastore}/#{name}"
  host.import_disk disk_file, "/vmfs/volumes/#{datastore}/#{name}/#{name}.vmdk"
  vm = host.create_vm :vm_name => name,
                      :disk_file => "#{name}/#{name}.vmdk",
                      :datastore => datastore, :disk_type => :flat, :memory => memory,
                      :guest_id => guest_id
  vm.power_on
end

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/esx-delivery-plugin.rb', line 21

def execute
  @log.info "Uploading #{@appliance_config.name} to ESX host #{@plugin_config['esx_host']}..."

  begin
    #TODO move to a block
    create_vm(@previous_deliverables[:disk])
    @log.info "Appliance #{@appliance_config.name} uploaded."
  rescue => e
    @log.error e
    @log.error "An error occurred while uploading files."
  end
end

#validateObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/esx-delivery-plugin.rb', line 9

def validate
  set_default_config_value('datastore', 'datastore1')
  set_default_config_value('name', @appliance_config.name)
  set_default_config_value('esx_user', 'root')
  set_default_config_value('esx_password', '')
  set_default_config_value('esx_host', '127.0.0.1')
  set_default_config_value('cpu', '1')
  set_default_config_value('guest_id', 'otherGuest')
  set_default_config_value('memory', '512')
  set_default_config_value('power_on', 'yes')
end