Class: Fog::Compute::Softlayer::Servers

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/softlayer/models/compute/servers.rb

Instance Method Summary collapse

Instance Method Details

#allObject



18
19
20
21
# File 'lib/fog/softlayer/models/compute/servers.rb', line 18

def all
  data = service.list_servers
  load(data)
end

#bootstrap(options = {}) ⇒ Object



58
59
60
61
62
# File 'lib/fog/softlayer/models/compute/servers.rb', line 58

def bootstrap(options={})
  server = service.create(options)
  server.wait_for { ready? }
  server
end

#get(identifier) ⇒ Object

Get a SoftLayer server.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/softlayer/models/compute/servers.rb', line 26

def get(identifier)
  return nil if identifier.nil? || identifier == ""
  response = service.get_vm(identifier)
  bare_metal = false
  if response.status == 404 # we didn't find it as a VM, look for a BMC server
    response = service.get_bare_metal_server(identifier)
    bare_metal = true
  end
  data = response.body
  data['bare_metal'] = bare_metal
  new.merge_attributes(data)
rescue Excon::Errors::NotFound
  nil
end

#get_available_preset_codesObject



82
83
84
# File 'lib/fog/softlayer/models/compute/servers.rb', line 82

def get_available_preset_codes
  service.get_available_preset_codes.body['fixedConfigurationPresets'].map { |item| { :desc => item['preset']['description'], :key => item['preset']['keyName'] } }
end

#get_bm_create_optionsObject



74
75
76
# File 'lib/fog/softlayer/models/compute/servers.rb', line 74

def get_bm_create_options
  service.get_bare_metal_create_options.body
end

#get_by_ip(ip) ⇒ Object

Get a SoftLayer server by ip.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/softlayer/models/compute/servers.rb', line 43

def get_by_ip(ip)
  return nil if ip.blank?
  response = service.get_virtual_guest_by_ip(ip)
  bare_metal = false
  if response.status == 404 # we didn't find it as a VM, look for a BMC server
    response = service.get_bare_metal_server_by_ip(ip)
    bare_metal = true
  end
  data = response.body
  data['bare_metal'] = bare_metal
  new.merge_attributes(data)
rescue Excon::Errors::NotFound
  nil
end

#get_vm_create_optionsObject



78
79
80
# File 'lib/fog/softlayer/models/compute/servers.rb', line 78

def get_vm_create_options
  service.get_virtual_guest_create_options.body
end

#tagged_with(tags) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
# File 'lib/fog/softlayer/models/compute/servers.rb', line 64

def tagged_with(tags)
  raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
  ids = service.get_references_by_tag_name(tags.join(',')).body.map do |tag|
    tag['references'].map do |ref|
      ref['resourceTableId']
    end
  end.flatten.uniq
  ids.map { |id| get(id) }
end