Class: Fog::Compute::Ecloud::Server
- Inherits:
-
Ecloud::Model
- Object
- Model
- Ecloud::Model
- Fog::Compute::Ecloud::Server
- Extended by:
- Forwardable
- Defined in:
- lib/fog/compute/ecloud/models/server.rb
Instance Attribute Summary
Attributes inherited from Ecloud::Model
Instance Method Summary collapse
- #add_disk(size) ⇒ Object
- #add_ip(options) ⇒ Object
- #add_nic(network) ⇒ Object
- #attach_disk(detached_disk) ⇒ Object
- #compute_pool ⇒ Object
- #compute_pool_id ⇒ Object
- #configuration ⇒ Object
- #copy(options = {}) ⇒ Object
- #cpus ⇒ Object
- #create_rnat(options) ⇒ Object
- #delete ⇒ Object (also: #destroy)
- #delete_disk(index) ⇒ Object
- #delete_ip(options) ⇒ Object
- #detach_disk(index) ⇒ Object
- #disks ⇒ Object
- #edit(options = {}) ⇒ Object
- #environment_id ⇒ Object
- #flavor_id ⇒ Object
- #hardware_configuration ⇒ Object
- #hardware_configuration=(hardware_configuration) ⇒ Object
- #id ⇒ Object
- #ips ⇒ Object
- #location ⇒ Object
-
#memory ⇒ Object
always in MB.
- #networks ⇒ Object
- #nics ⇒ Object
- #off? ⇒ Boolean
- #on? ⇒ Boolean
- #power_off ⇒ Object
- #power_on ⇒ Object
- #power_reset ⇒ Object
- #processes ⇒ Object
- #ready? ⇒ Boolean
- #rnats ⇒ Object
- #shutdown ⇒ Object
- #storage ⇒ Object
- #storage_size ⇒ Object
- #tasks ⇒ Object
- #upload_file(options) ⇒ Object
Methods inherited from Ecloud::Model
Instance Method Details
#add_disk(size) ⇒ Object
162 163 164 165 166 167 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 162 def add_disk(size) index = disks.map { |d| d[:Index].to_i }.sort[-1] + 1 vm_disks = disks << { :Index => index.to_s, :Size => { :Unit => "GB", :Value => size.to_s }, :Name => "Hard Disk #{index + 1}" } data = service.virtual_machine_edit_hardware_configuration(href + "/hardwareConfiguration", _configuration_data(:disks => vm_disks)).body service.tasks.new(data) end |
#add_ip(options) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 205 def add_ip() slice_ips = begin ips rescue [] end slice_networks = if slice_ips.empty? [] else ips.map { |ip| { :href => ip.network.href, :name => ip.network.name.split(" ")[0], :type => ip.network.type } }.push(:href => [:href], :name => [:network_name], :type => "application/vnd.tmrk.cloud.network").uniq end slice_ips = slice_ips.map { |i| { :name => i.address.name, :network_name => i.network.name } }.push(:name => [:ip], :network_name => [:network_name]).uniq slice_ips.each do |ip| slice_networks.each do |network| if network[:name] == ip[:network_name] network[:ips] ||= [] network[:ips].push(ip[:name]) end end end data = service.virtual_machine_edit_assigned_ips(href + "/assignedIps", slice_networks).body service.tasks.new(data) end |
#add_nic(network) ⇒ Object
198 199 200 201 202 203 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 198 def add_nic(network) unit_number = nics.map { |n| n[:UnitNumber].to_i }.sort[-1] + 1 vm_nics = nics << { :UnitNumber => unit_number, :Network => { :href => network.href, :name => network.name, :type => "application/vnd.tmrk.cloud.network" } } data = service.virtual_machine_edit_hardware_configuration(href + "/hardwareConfiguration", _configuration_data(:nics => vm_nics)).body service.tasks.new(:href => data[:href])[0] end |
#attach_disk(detached_disk) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 178 def attach_disk(detached_disk) = {} [:name] = detached_disk.name [:href] = detached_disk.href data = service.virtual_machine_attach_disk(href + "/hardwareconfiguration/disks/actions/attach", ).body service.tasks.new(data) end |
#compute_pool ⇒ Object
288 289 290 291 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 288 def compute_pool reload if other_links.nil? @compute_pool = service.compute_pools.new(:href => other_links.detect { |l| l[:type] == "application/vnd.tmrk.cloud.computePool" }[:href]) end |
#compute_pool_id ⇒ Object
284 285 286 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 284 def compute_pool_id other_links.detect { |l| l[:type] == "application/vnd.tmrk.cloud.computePool" }[:href].scan(/\d+/)[0] end |
#configuration ⇒ Object
58 59 60 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 58 def configuration @configuration ||= Fog::Compute::Ecloud::ServerConfigurationOptions.new(:service => service, :href => "#{service.base_path}/virtualMachines/#{id}/configurationOptions")[0] end |
#copy(options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 91 def copy( = {}) = { :type => :copy }.merge() [:source] ||= href if [:type] == :copy [:cpus] ||= 1 [:memory] ||= 512 [:customization] ||= :linux [:tags] ||= [] [:powered_on] ||= false if [:ips] [:ips] = [:ips].is_a?(String) ? [[:ips]] : [:ips] else [:network_uri] = [:network_uri].is_a?(String) ? [[:network_uri]] : [:network_uri] [:network_uri].each do |uri| index = [:network_uri].index(uri) ip = Fog::Compute::Ecloud::IpAddresses.new(:service => service, :href => uri).detect { |i| i.host == nil }.name [:ips] ||= [] [:ips][index] = ip end end data = service.virtual_machine_copy("#{service.base_path}/virtualMachines/computePools/#{compute_pool_id}/action/copyVirtualMachine", ).body elsif [:type] == :identical data = service.virtual_machine_copy_identical("#{service.base_path}/virtualMachines/computePools/#{compute_pool_id}/action/copyIdenticalVirtualMachine", ).body end vm = collection.from_data(data) vm end |
#cpus ⇒ Object
22 23 24 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 22 def cpus hardware_configuration.processor_count end |
#create_rnat(options) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 149 def create_rnat() [:host_ip_href] ||= ips.first.href [:uri] = "#{service.base_path}/rnats/environments/#{environment_id}/action/createAssociation" data = service.rnat_associations_create_device().body Fog::Compute::Ecloud::Associations.new(:service => service, :href => data[:href])[0] end |
#delete ⇒ Object Also known as: destroy
86 87 88 89 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 86 def delete data = service.virtual_machine_delete(href).body service.tasks.new(data) end |
#delete_disk(index) ⇒ Object
186 187 188 189 190 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 186 def delete_disk(index) vm_disks = disks.delete_if { |h| h[:Index] == index.to_s } data = service.virtual_machine_edit_hardware_configuration(href + "/hardwareconfiguration", _configuration_data(:disks => vm_disks)).body service.tasks.new(data) end |
#delete_ip(options) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 229 def delete_ip() slice_ips = begin ips rescue [] end slice_networks = if slice_ips.empty? [] else ips.map do |ip| { :href => ip.network.href, :name => ip.network.name.split(" ")[0], :type => ip.network.type, } end # .delete_if { |ip| ip[:href] == options[:href] && ip[:name] == options[:network_name] } end slice_ips.map! { |i| { :name => i.address.name, :network_name => i.network.name } }.delete_if { |ip| ip[:name] == [:ip] } slice_ips.each do |ip| slice_networks.each do |network| if network[:name] == ip[:network_name] network[:ips].delete(ip[:name]) end end end data = service.virtual_machine_edit_assigned_ips(href + "/assignedips", slice_networks).body service.tasks.new(data) end |
#detach_disk(index) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 169 def detach_disk(index) = {} [:disk] = disks.detect { |disk_hash| disk_hash[:Index] == index.to_s } [:name] = name [:description] = description data = service.virtual_machine_detach_disk(href + "/hardwareconfiguration/disks/actions/detach", ).body service.detached_disks.new(data) end |
#disks ⇒ Object
156 157 158 159 160 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 156 def disks c = hardware_configuration.reload.storage c = c.is_a?(Hash) ? [c] : c @disks = c end |
#edit(options = {}) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 142 def edit( = {}) data = service.virtual_machine_edit(href, ).body if data[:type] == "application/vnd.tmrk.cloud.task" Fog::Compute::Ecloud::Tasks.new(:service => service, :href => data[:href])[0] end end |
#environment_id ⇒ Object
293 294 295 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 293 def environment_id other_links.detect { |l| l[:type] == "application/vnd.tmrk.cloud.environment" }[:href].scan(/\d+/)[0] end |
#flavor_id ⇒ Object
33 34 35 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 33 def flavor_id { :ram => hardware_configuration.memory.to_i, :cpus => hardware_configuration.processor_count } end |
#hardware_configuration ⇒ Object
53 54 55 56 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 53 def hardware_configuration @hardware_configuration ||= service.hardware_configurations.new(:href => "#{service.base_path}/virtualMachines/#{id}/hardwareConfiguration") @hardware_configuration.reload end |
#hardware_configuration=(hardware_configuration) ⇒ Object
49 50 51 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 49 def hardware_configuration=(hardware_configuration) @hardware_configuration = service.hardware_configurations.new(hardware_configuration) end |
#id ⇒ Object
297 298 299 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 297 def id href.scan(/\d+/)[0] end |
#ips ⇒ Object
62 63 64 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 62 def ips @ips = service.virtual_machine_assigned_ips(:virtual_machine_id => id) end |
#location ⇒ Object
30 31 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 30 def location end |
#memory ⇒ Object
always in MB
26 27 28 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 26 def memory # always in MB hardware_configuration.memory.to_i end |
#networks ⇒ Object
66 67 68 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 66 def networks @networks ||= service.networks(:href => "#{service.base_path}/virtualMachines/#{id}/assignedIps") end |
#nics ⇒ Object
192 193 194 195 196 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 192 def nics c = hardware_configuration.network_cards c = c.is_a?(Hash) ? [c] : c @nics = c end |
#off? ⇒ Boolean
280 281 282 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 280 def off? powered_on == false end |
#on? ⇒ Boolean
276 277 278 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 276 def on? powered_on == true end |
#power_off ⇒ Object
74 75 76 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 74 def power_off power_operation(:power_off => :powerOff) end |
#power_on ⇒ Object
70 71 72 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 70 def power_on power_operation(:power_on => :powerOn) end |
#power_reset ⇒ Object
82 83 84 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 82 def power_reset power_operation(:power_reset => :reboot) end |
#processes ⇒ Object
45 46 47 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 45 def processes @processes ||= Fog::Compute::Ecloud::GuestProcesses.new(:service, service, :href => "#{service.base_path}/virtualMachines/#{id}/guest/processes") end |
#ready? ⇒ Boolean
267 268 269 270 271 272 273 274 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 267 def ready? load_unless_loaded! if status =~ /NotDeployed|Orphaned|TaskInProgress|CopyInProgress/ false else true end end |
#rnats ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 119 def rnats rnats = Fog::Compute::Ecloud::Rnats.new(:service => service, :href => "#{service.base_path}/rnats/environments/#{environment_id}") associations = nil rnats.each do |rnat| if rnats.index(rnat) == 0 associations = rnat.associations.select do |association| ips.any? do |ip| association.name == ip.name end end else rnat.associations.select do |association| ips.each do |ip| if ip.name == association.name associations << association end end end end end associations end |
#shutdown ⇒ Object
78 79 80 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 78 def shutdown power_operation(:power_shutdown => :shutdown) end |
#storage ⇒ Object
37 38 39 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 37 def storage hardware_configuration.storage[:Disk] end |
#storage_size ⇒ Object
263 264 265 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 263 def storage_size disks.map! { |d| d[:Size][:Value].to_i }.inject(0) { |sum, item| sum + item } * 1024 * 1024 end |
#tasks ⇒ Object
41 42 43 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 41 def tasks @tasks ||= service.tasks(:href => "#{service.base_path}/tasks/virtualMachines/#{id}") end |
#upload_file(options) ⇒ Object
258 259 260 261 |
# File 'lib/fog/compute/ecloud/models/server.rb', line 258 def upload_file() service.virtual_machine_upload_file(href + "/guest/action/files", ) true end |