Class: VirtualMachineDevice::Device

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

Overview

Device Classes

Device base class

Direct Known Subclasses

Disk, Nic

Instance Method Summary collapse

Constructor Details

#initialize(id, one_res, vc_res) ⇒ Device

Returns a new instance of Device.



14
15
16
17
18
# File 'lib/vm_device.rb', line 14

def initialize(id, one_res, vc_res)
    @id      = id
    @one_res = one_res
    @vc_res  = vc_res
end

Instance Method Details

#detached?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/vm_device.rb', line 65

def detached?
    !one?
end

#exists?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/vm_device.rb', line 39

def exists?
    !@vc_res.nil?
end

#idObject



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

def id
    raise_if_no_exists_in_one
    @id
end

#managed?Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
# File 'lib/vm_device.rb', line 69

def managed?
    raise_if_no_exists_in_one

    return unless @one_res

    !(@one_res['OPENNEBULA_MANAGED'] &&
      @one_res['OPENNEBULA_MANAGED'].downcase == 'no')
end

#no_exists?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/vm_device.rb', line 53

def no_exists?
    !exists?
end

#one?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/vm_device.rb', line 35

def one?
    !@one_res.nil?
end

#one_itemObject



25
26
27
28
# File 'lib/vm_device.rb', line 25

def one_item
    raise_if_no_exists_in_one
    @one_res
end

#raise_if_no_exists_in_oneObject

Fails if the device is not present in OpenNebula



44
45
46
# File 'lib/vm_device.rb', line 44

def raise_if_no_exists_in_one
    raise 'OpenNebula device does not exist at the moment' unless one?
end

#raise_if_no_exists_in_vcenterObject

Fails if the device is not present in vCenter



49
50
51
# File 'lib/vm_device.rb', line 49

def raise_if_no_exists_in_vcenter
    raise 'vCenter device does not exist at the moment' unless exists?
end

#synced?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/vm_device.rb', line 57

def synced?
    one? && exists?
end

#unsynced?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/vm_device.rb', line 61

def unsynced?
    !synced?
end

#vc_itemObject



30
31
32
33
# File 'lib/vm_device.rb', line 30

def vc_item
    raise_if_no_exists_in_vcenter
    @vc_res
end