Class: Fog::Compute::Ecloud::Server

Inherits:
Ecloud::Model show all
Defined in:
lib/fog/compute/models/ecloud/server.rb

Instance Attribute Summary

Attributes inherited from Ecloud::Model

#loaded

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Ecloud::Model

#load_unless_loaded!

Methods inherited from Model

#initialize, #inspect, #to_json, #wait_for

Methods included from Attributes::ClassMethods

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

Methods included from Attributes::InstanceMethods

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

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#add_disk(size) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fog/compute/models/ecloud/server.rb', line 111

def add_disk(size)
  if @disk_change == :deleted
    raise RuntimeError, "Can't add a disk w/o saving changes or reloading"
  else
    @disk_change = :added
    load_unless_loaded!
    virtual_hardware[:Item] << { :ResourceType => '17',
                                 :AddressOnParent => (disk_mess.map { |dm| dm[:AddressOnParent] }.sort.last.to_i + 1).to_s,
                                 :VirtualQuantity => size.to_s }
  end
  true
end

#cpusObject



81
82
83
84
85
86
# File 'lib/fog/compute/models/ecloud/server.rb', line 81

def cpus
  if cpu_mess
    { :count => cpu_mess[:VirtualQuantity].to_i,
      :units => cpu_mess[:AllocationUnits] }
  end
end

#cpus=(qty) ⇒ Object



88
89
90
91
# File 'lib/fog/compute/models/ecloud/server.rb', line 88

def cpus=(qty)
  @changed = true
  cpu_mess[:VirtualQuantity] = qty.to_s
end

#deleteObject



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

def delete
  requires :href
  connection.delete_vapp( href)
end

#delete_disk(number) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/fog/compute/models/ecloud/server.rb', line 124

def delete_disk(number)
  if @disk_change == :added
    raise RuntimeError, "Can't delete a disk w/o saving changes or reloading"
  else
    @disk_change = :deleted
    load_unless_loaded!
    unless number == 0
      virtual_hardware[:Item].delete_if { |vh| vh[:ResourceType] == '17' && vh[:AddressOnParent].to_i == number }
    end
  end
  true
end

#disksObject



105
106
107
108
109
# File 'lib/fog/compute/models/ecloud/server.rb', line 105

def disks
  disk_mess.map do |dm|
    { :number => dm[:AddressOnParent], :size => dm[:VirtualQuantity].to_i, :resource => dm[:HostResource] }
  end
end

#friendly_statusObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/compute/models/ecloud/server.rb', line 19

def friendly_status
  load_unless_loaded!
  case status
  when '0'
    'creating'
  when '2'
    'off'
  when '4'
    'on'
  else
    'unkown'
  end
end

#graceful_restartObject



64
65
66
67
68
69
# File 'lib/fog/compute/models/ecloud/server.rb', line 64

def graceful_restart
  requires :href
  shutdown
  wait_for { off? }
  power_on
end

#memoryObject



93
94
95
96
97
98
# File 'lib/fog/compute/models/ecloud/server.rb', line 93

def memory
  if memory_mess
    { :amount => memory_mess[:VirtualQuantity].to_i,
      :units => memory_mess[:AllocationUnits] }
  end
end

#memory=(amount) ⇒ Object



100
101
102
103
# File 'lib/fog/compute/models/ecloud/server.rb', line 100

def memory=(amount)
  @changed = true
  memory_mess[:VirtualQuantity] = amount.to_s
end

#name=(new_name) ⇒ Object



76
77
78
79
# File 'lib/fog/compute/models/ecloud/server.rb', line 76

def name=(new_name)
  attributes[:name] = new_name
  @changed = true
end

#off?Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/fog/compute/models/ecloud/server.rb', line 43

def off?
  load_unless_loaded!
  status == '2'
end

#on?Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/fog/compute/models/ecloud/server.rb', line 38

def on?
  load_unless_loaded!
  status == '4'
end

#power_offObject



52
53
54
# File 'lib/fog/compute/models/ecloud/server.rb', line 52

def power_off
  power_operation( :power_off => :powerOff )
end

#power_onObject



48
49
50
# File 'lib/fog/compute/models/ecloud/server.rb', line 48

def power_on
  power_operation( :power_on => :powerOn )
end

#power_resetObject



60
61
62
# File 'lib/fog/compute/models/ecloud/server.rb', line 60

def power_reset
  power_operation( :power_reset => :reset )
end

#ready?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/fog/compute/models/ecloud/server.rb', line 33

def ready?
  load_unless_loaded!
  status == '2'
end

#reloadObject



137
138
139
140
# File 'lib/fog/compute/models/ecloud/server.rb', line 137

def reload
  reset_tracking
  super
end

#saveObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/fog/compute/models/ecloud/server.rb', line 142

def save
  if new_record?
    #Lame ...
    raise RuntimeError, "Should not be here"
  else
    if on?
      if @changed
        raise RuntimeError, "Can't save cpu, name or memory changes while the VM is on."
      end
    end
    connection.configure_vapp( href, _compose_vapp_data )
  end
  reset_tracking
end

#shutdownObject



56
57
58
# File 'lib/fog/compute/models/ecloud/server.rb', line 56

def shutdown
  power_operation( :power_shutdown => :shutdown )
end