class Fog::Compute::Ecloud::Server
Public Instance Methods
add_disk(size)
click to toggle source
# File lib/fog/ecloud/models/compute/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 task = self.service.tasks.new(data) end
add_ip(options)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 205 def add_ip(options) 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 => options[:href], :name => options[: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 => options[:ip], :network_name => options[: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 task = self.service.tasks.new(data) end
add_nic(network)
click to toggle source
# File lib/fog/ecloud/models/compute/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 task = self.service.tasks.new(:href => data[:href])[0] end
attach_disk(detached_disk)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 178 def attach_disk(detached_disk) options = {} options[:name] = detached_disk.name options[:href] = detached_disk.href data = service.virtual_machine_attach_disk(href + "/hardwareconfiguration/disks/actions/attach", options).body task = self.service.tasks.new(data) end
compute_pool()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 289 def compute_pool reload if other_links.nil? @compute_pool = self.service.compute_pools.new(:href => other_links.find { |l| l[:type] == "application/vnd.tmrk.cloud.computePool" }[:href]) end
compute_pool_id()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 285 def compute_pool_id other_links.find { |l| l[:type] == "application/vnd.tmrk.cloud.computePool" }[:href].scan(/\d+/)[0] end
configuration()
click to toggle source
# File lib/fog/ecloud/models/compute/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 = {})
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 91 def copy(options = {}) options = {:type => :copy}.merge(options) options[:source] ||= href if options[:type] == :copy options[:cpus] ||= 1 options[:memory] ||= 512 options[:customization] ||= :linux options[:tags] ||= [] options[:powered_on] ||= false if options[:ips] options[:ips] = options[:ips].is_a?(String) ? [options[:ips]] : options[:ips] else options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri] options[:network_uri].each do |uri| index = options[:network_uri].index(uri) ip = Fog::Compute::Ecloud::IpAddresses.new(:service => service, :href => uri).find { |i| i.host == nil }.name options[:ips] ||= [] options[:ips][index] = ip end end data = service.virtual_machine_copy("#{service.base_path}/virtualMachines/computePools/#{compute_pool_id}/action/copyVirtualMachine", options).body elsif options[:type] == :identical data = service.virtual_machine_copy_identical("#{service.base_path}/virtualMachines/computePools/#{compute_pool_id}/action/copyIdenticalVirtualMachine", options).body end vm = collection.from_data(data) vm end
cpus()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 22 def cpus hardware_configuration.processor_count end
create_rnat(options)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 149 def create_rnat(options) options[:host_ip_href] ||= ips.first.href options[:uri] = "#{service.base_path}/rnats/environments/#{environment_id}/action/createAssociation" data = service.rnat_associations_create_device(options).body rnat = Fog::Compute::Ecloud::Associations.new(:service => service, :href => data[:href])[0] end
delete()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 86 def delete data = service.virtual_machine_delete(href).body self.service.tasks.new(data) end
Also aliased as: destroy
delete_disk(index)
click to toggle source
# File lib/fog/ecloud/models/compute/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 task = self.service.tasks.new(data) end
delete_ip(options)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 229 def delete_ip(options) 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, :network_name => i.network.name } }.delete_if { |ip| ip[:name] == options[: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 task = self.service.tasks.new(data) end
detach_disk(index)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 169 def detach_disk(index) options = {} options[:disk] = disks.find { |disk_hash| disk_hash[:Index] == index.to_s } options[:name] = self.name options[:description] = self.description data = service.virtual_machine_detach_disk(href + "/hardwareconfiguration/disks/actions/detach", options).body detached_disk = self.service.detached_disks.new(data) end
disks()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 156 def disks c = hardware_configuration.reload.storage c = c.is_a?(Hash) ? [c] : c @disks = c end
edit(options = {})
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 142 def edit(options = {}) data = service.virtual_machine_edit(href, options).body if data[:type] == "application/vnd.tmrk.cloud.task" task = Fog::Compute::Ecloud::Tasks.new(:service => service, :href => data[:href])[0] end end
environment_id()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 294 def environment_id other_links.find { |l| l[:type] == "application/vnd.tmrk.cloud.environment" }[:href].scan(/\d+/)[0] end
flavor_id()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 33 def flavor_id {:ram => hardware_configuration.memory.to_i, :cpus => hardware_configuration.processor_count} end
hardware_configuration()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 53 def hardware_configuration @hardware_configuration ||= self.service.hardware_configurations.new(:href => "#{service.base_path}/virtualMachines/#{id}/hardwareConfiguration") @hardware_configuration.reload end
hardware_configuration=(hardware_configuration)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 49 def hardware_configuration=(hardware_configuration) @hardware_configuration = self.service.hardware_configurations.new(hardware_configuration) end
id()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 298 def id href.scan(/\d+/)[0] end
ips()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 62 def ips @ips = self.service.virtual_machine_assigned_ips(:virtual_machine_id => self.id) end
location()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 30 def location end
memory()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 26 def memory # always in MB hardware_configuration.memory.to_i end
networks()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 66 def networks @networks ||= self.service.networks(:href => "#{service.base_path}/virtualMachines/#{id}/assignedIps") end
nics()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 192 def nics c = hardware_configuration.network_cards c = c.is_a?(Hash) ? [c] : c @nics = c end
off?()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 281 def off? powered_on == false end
on?()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 277 def on? powered_on == true end
power_off()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 74 def power_off power_operation( :power_off => :powerOff ) end
power_on()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 70 def power_on power_operation( :power_on => :powerOn ) end
power_reset()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 82 def power_reset power_operation( :power_reset => :reboot ) end
processes()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 45 def processes @processes ||= Fog::Compute::Ecloud::GuestProcesses.new(:service, service, :href => "#{service.base_path}/virtualMachines/#{id}/guest/processes") end
ready?()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 268 def ready? load_unless_loaded! unless status =~ /NotDeployed|Orphaned|TaskInProgress|CopyInProgress/ true else false end end
rnats()
click to toggle source
# File lib/fog/ecloud/models/compute/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()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 78 def shutdown power_operation( :power_shutdown => :shutdown ) end
storage()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 37 def storage hardware_configuration.storage[:Disk] end
storage_size()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 263 def storage_size vm_disks = disks disks.map! { |d| d[:Size][:Value].to_i }.reduce(0){|sum,item| sum + item} * 1024 * 1024 end
tasks()
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 41 def tasks @tasks ||= self.service.tasks(:href => "#{service.base_path}/tasks/virtualMachines/#{id}") end
upload_file(options)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 258 def upload_file(options) service.virtual_machine_upload_file(href + "/guest/action/files", options) true end
Private Instance Methods
_configuration_data(options = {})
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 304 def _configuration_data(options = {}) {:cpus => (options[:cpus] || hardware_configuration.processor_count), :memory => (options[:memory] || hardware_configuration.memory), :disks => (options[:disks] || disks), :nics => (options[:nics] || nics)} end
power_operation(op)
click to toggle source
# File lib/fog/ecloud/models/compute/server.rb, line 308 def power_operation(op) requires :href begin service.send(op.keys.first, href + "/action/#{op.values.first}" ) rescue Excon::Errors::Conflict => e #Frankly we shouldn't get here ... raise e unless e.to_s =~ /because it is already powered o(n|ff)/ end true end