Class: Fog::Compute::VcloudDirector::Vm

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/vcloud_director/models/compute/vm.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #lazy_load_attrs, #make_attr_loaded_method, #make_lazy_load_method

Methods inherited from Model

#initialize, #inspect, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Compute::VcloudDirector::Model

Instance Method Details

#cpu=(new_cpu) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 86

def cpu=(new_cpu)
  has_changed = ( cpu != new_cpu.to_i )
  not_first_set = !cpu.nil?
  attributes[:cpu] = new_cpu.to_i
  if not_first_set && has_changed
    response = service.put_vm_cpu(id, cpu)
    service.process_task(response.body)
  end
end

#customizationObject



61
62
63
64
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 61

def customization
  data = service.get_vm_customization(id).body
  service.vm_customizations.new(data)
end

#disksObject



71
72
73
74
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 71

def disks
  requires :id
  service.disks(:vm => self)
end

#memory=(new_memory) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 76

def memory=(new_memory)
  has_changed = ( memory != new_memory.to_i )
  not_first_set = !memory.nil?
  attributes[:memory] = new_memory.to_i
  if not_first_set && has_changed
    response = service.put_vm_memory(id, memory)
    service.process_task(response.body)
  end
end

#networkObject



66
67
68
69
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 66

def network
  data = service.get_vm_network(id).body
  service.vm_networks.new(data)
end

#power_offObject



51
52
53
54
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 51

def power_off
  response = service.post_vm_poweroff(id)
  service.process_task(response.body)
end

#power_onObject



46
47
48
49
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 46

def power_on
  response = service.post_vm_poweron(id)
  service.process_task(response.body)
end

#reloadObject



23
24
25
26
27
28
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 23

def reload
  # when collection.vapp is nil, it means it's fatherless,
  # vms from different vapps are loaded in the same collection.
  # This situation comes from a "query" result
  collection.vapp.nil? ? reload_single_vm : super
end

#reload_single_vmObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 30

def reload_single_vm
  return unless data = begin
    collection.get_single_vm(identity)
  rescue Excon::Errors::SocketError
    nil
  end
  # these two attributes don't exists in the get_single_vm response
  # that's why i use the old attributes
  data.attributes[:vapp_id] = attributes[:vapp_id]
  data.attributes[:vapp_name] = attributes[:vapp_name]
  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#tagsObject



56
57
58
59
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 56

def tags
  requires :id
  service.tags(:vm => self)
end