class Fog::ArubaCloud::Compute::Server
noinspection RubyTooManyMethodsInspection
Constants
- ARCHIVED
- CREATING
- DELETED
- RUNNING
- STATE_DES
- STOPPED
Public Class Methods
new(attributes = {})
click to toggle source
Calls superclass method
# File lib/fog/arubacloud/compute/models/server.rb, line 59 def initialize(attributes = {}) @service = attributes[:service] if attributes[:vm_type].nil? self.vm_type = 'smart' if attributes['HypervisorType'].eql? '4' else 'pro' end super end
Public Instance Methods
action_hook(method, expected_state, message)
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 71 def action_hook(method, expected_state, message) unless state.eql? expected_state raise Fog::ArubaCloud::Errors::VmStatus.new(message) end @service.send method, id end
apply_snapshot()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 219 def apply_snapshot requires :id self.action_hook(method=:apply_snapshot, expected_state=STOPPED, message="Cannot restore vm in current state: #{state}" ) end
archive()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 193 def archive requires :id, :state, :vm_type if state == STOPPED and vm_type.eql?('pro') service.archive_vm(id) else raise(Fog::ArubaCloud::Errors::VmStatus.new( "Cannot archive VM in current state #{state} or VM type #{vm_type}")) end end
create()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 107 def create requires :name, :cpu, :memory, :admin_passwd, :vm_type data = attributes if vm_type.eql? 'pro' # Automatically purchase a public ip address data[:ipv4_id] = service.purchase_ip['Value']['ResourceId'] service.create_vm_pro(data) elsif vm_type.eql? 'smart' service.create_vm_smart(data) else raise Fog::ArubaCloud::Errors::BadParameters.new('VM Type can be smart or pro.') end # Retrieve new server list and filter the current virtual machine # in order to retrieve the ID server = nil while server.nil? servers = service.get_servers servers['Value'].each do |s| server = s if s['Name'].to_s.include? data[:name].to_s end end Fog::Logger.debug("Fog::ArubaCloud::Compute::Server.create, #{data[:name]} server: #{server.inspect}") if server merge_attributes(server) else message = 'error during attribute merge, `server` object is not ready.' Fog::Logger.warning("Fog::ArubaCloud::Compute::Server.create, #{message}") sleep(1) end end
create_snapshot()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 214 def create_snapshot requires :id id != nil ? service.create_snapshot(id) : raise(Fog::ArubaCloud::Errors::VmStatus.new('Cannot create snapshot without vm id')) end
creating?(creating_state=CREATING)
click to toggle source
Is server in creating state @param [String] creating_state By default creating state is CREATING
@return [Boolean] return true if server is in creating state
# File lib/fog/arubacloud/compute/models/server.rb, line 95 def creating?(creating_state=CREATING) state == creating_state end
delete()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 179 def delete requires :id self.action_hook(method=:delete_vm, expected_state=STOPPED, message="Cannot delete vm in current state: #{state}" ) end
delete_snapshot()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 224 def delete_snapshot requires :id service.delete_snapshot(id) end
get_public_ip()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 147 def get_public_ip requires :id if self.vm_type.eql? 'smart' self.smart_ipv4 else self.get_server_details unless self.attributes['NetworkAdapters'] self.attributes['NetworkAdapters'].each do |na| na['IPAddresses'].each do |ipa| if ipa['ProductId'].eql? 20 self.ipv4_addr = ipa['Value'].to_s return self.ipv4_addr end end end end end
get_server_details()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 140 def get_server_details requires :id response = service.get_server_details(id) new_attributes = response['Value'] merge_attributes(new_attributes) end
list_snapshot()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 209 def list_snapshot requires :id id != nil ? service.list_snapshot(id) : raise(Fog::ArubaCloud::Errors::VmStatus.new('Cannot list snapshot without vm id')) end
power_off()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 165 def power_off requires :id, :state self.action_hook(method=:power_off_vm, expected_state=RUNNING, message="Cannot poweroff vm in current state: #{state}" ) end
power_on()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 172 def power_on requires :id, :state self.action_hook(method=:power_on_vm, expected_state=STOPPED, message="Cannot poweron vm in current state: #{state}" ) end
ready?(ready_state=RUNNING)
click to toggle source
Is server in ready state @param [String] ready_state By default state is RUNNING
@return [Boolean] return true if server is in ready state
# File lib/fog/arubacloud/compute/models/server.rb, line 81 def ready?(ready_state=RUNNING) state == ready_state end
reinitialize()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 186 def reinitialize requires :id, :hypervisor self.action_hook(method=:reinitialize_vm, expected_state=STOPPED, message="Cannot reinitialize vm in current state: #{state}" ) end
restore()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 203 def restore requires :id, :memory, :cpu state == ARCHIVED and memory != nil and cpu != nil ? service.restore_vm(id) : raise( Fog::ArubaCloud::Errors::VmStatus.new("Cannot restore VM without specifying #{cpu} and #{memory}")) end
save()
click to toggle source
# File lib/fog/arubacloud/compute/models/server.rb, line 99 def save if persisted? update else create end end
stopped?(stopped_state=STOPPED)
click to toggle source
Is server in stopped state @param [String] stopped_state By default stopped state is STOPPED
@return [Boolean] return true if server is in stopped state
# File lib/fog/arubacloud/compute/models/server.rb, line 88 def stopped?(stopped_state=STOPPED) state == stopped_state end