Class: VMWizard::MagicWand

Inherits:
Object
  • Object
show all
Defined in:
lib/esxmagicwand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(esx_host, dhcp_host) ⇒ MagicWand

Returns a new instance of MagicWand.



22
23
24
25
# File 'lib/esxmagicwand.rb', line 22

def initialize(esx_host, dhcp_host)
    @esx_host = esx_host
    @dhcp_host = dhcp_host
end

Instance Attribute Details

#dhcp_hostObject (readonly)

Returns the value of attribute dhcp_host.



20
21
22
# File 'lib/esxmagicwand.rb', line 20

def dhcp_host
  @dhcp_host
end

#esx_hostObject (readonly)

Returns the value of attribute esx_host.



20
21
22
# File 'lib/esxmagicwand.rb', line 20

def esx_host
  @esx_host
end

Instance Method Details

#deploy(vm, datastore) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/esxmagicwand.rb', line 27

def deploy(vm, datastore)
    vm = @esx_host.create_vm(
                :vm_name => vm.name, 
                :datastore => datastore,
                :disk_type => :thin,
                :disk_size => vm.disk_size,
                :memory => vm.ram,
                :cpus => vm.cpus,
                :guest_id => vm.guest,
                :nics => vm.nics
            )

    return vm
end

#undeploy(vm_name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/esxmagicwand.rb', line 42

def undeploy(vm_name)
    vm = nil
    esx_host.virtual_machines.each do |x|
        if x.name == vm_name
            vm = x
            break
        end
    end

    if not vm
        raise "VM with name #{vm_name} not found"
    end

    if vm.power_state == "poweredOn"
        vm.power_off
    end

    vm.destroy

end