Parent

Class/Module Index [+]

Quicksearch

Fog::Compute::Softlayer::Server

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 50
def initialize(attributes = {})
  # Forces every request inject bare_metal parameter
  raise Exception if attributes[:collection].nil? and attributes['bare_metal'].nil?
  super(attributes)
  set_defaults
end

Public Instance Methods

add_tags(tags) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 57
def add_tags(tags)
  requires :id
  raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
  tags.each do |tag|
    service.tags.new(:resource_id => self.id, :name => tag).save
  end
  self.reload
  true
end
bare_metal() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 71
def bare_metal
  @bare_metal
end
bare_metal?() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 67
def bare_metal?
  bare_metal
end
datacenter() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 80
def datacenter
  attributes[:datacenter][:name] unless attributes[:datacenter].nil?
end
datacenter=(name) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 75
def datacenter=(name)
  name = name['name'] if name.is_a?(Hash)
  attributes[:datacenter] = { :name => name }
end
delete_tags(tags) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 84
def delete_tags(tags)
  requires :id
  raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
  tags.each do |tag|
    service.tags.new(:resource_id => self.id, :name => tag).destroy
  end
  self.reload
  true
end
destroy() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 94
def destroy
  requires :id
  request = bare_metal? ? :delete_bare_metal_server : :delete_vm
  response = service.send(request, self.id)
  response.body
end
dns_name() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 101
def dns_name
  fqdn
end
image_id() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 109
def image_id
  attributes[:image_id][:globalIdentifier] unless attributes[:image_id].nil?
end
image_id=(uuid) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 105
def image_id=(uuid)
  attributes[:image_id] = {:globalIdentifier => uuid}
end
key_pairs() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 169
def key_pairs
  attributes[:key_pairs]
end
key_pairs=(keys) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 173
def key_pairs=(keys)
  raise ArgumentError, "Argument #{local_variables.first.to_s} for #{self.class.name}##{__method__} must be Array." unless keys.is_a?(Array)
  attributes[:key_pairs] = []
  keys.map do |key|
    key = self.symbolize_keys(key) if key.is_a?(Hash)
    unless key.is_a?(Fog::Compute::Softlayer::KeyPair) or (key.is_a?(Hash) and key[:id])
      raise ArgumentError, "Elements of keys array for #{self.class.name}##{__method__} must be a Hash with key 'id', or Fog::Compute::Softlayer::KeyPair"
    end
    key = service.key_pairs.get(key[:id]) unless key.is_a?(Fog::Compute::Softlayer::KeyPair)
    attributes[:key_pairs] << key
  end
end
name() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 117
def name
  attributes[:hostname]
end
name=(set) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 113
def name=(set)
  attributes[:hostname] = set
end
network_components() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 214
def network_components
  if id
    (public_network_components << private_network_components).flatten
  else
    attributes[:network_components]
  end
end
os_code() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 153
def os_code
  attributes['operatingSystem']['softwareLicense']['softwareDescription']['referenceCode'] if attributes['operatingSystem']
end
pre_save() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 121
def pre_save
  extract_flavor
  validate_attributes
  if self.vlan
    attributes[:vlan] = { :networkVlan => { :id => self.vlan.id } }
  end
  if self.private_vlan
    attributes[:private_vlan] = { :networkVlan => { :id => self.private_vlan.id } }
  end
  if self.key_pairs
    attributes[:key_pairs].map! { |key| { :id => key.id } }
  end
  if self.network_components
    self.network_components = self.network_components.map do |component|
      component[:maxSpeed] = component.delete(:speed) if component[:speed]
      component[:maxSpeed] = component.delete(:max_speed) if component[:max_speed]
      component
    end
  end

  remap_attributes(attributes, attributes_mapping)
  clean_attributes
end
private_ip() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 145
def private_ip # maintain backward compatibility with <0.3.13
  private_ip_address
end
private_network_components() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 230
def private_network_components
  if attributes['backendNetworkComponents']
    attributes['backendNetworkComponents'].map { |n| Fog::Compute::Softlayer::NetworkComponent.new(n) }
  else
    []
  end
end
private_vlan() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 157
def private_vlan
  attributes[:private_vlan] ||= _get_private_vlan
end
private_vlan=(value) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 161
def private_vlan=(value)
  unless value.is_a?(Integer) or value.is_a?(Fog::Network::Softlayer::Network)
    raise ArgumentError, "vlan argument for #{self.class.name}##{__method__} must be Integer or Fog::Network::Softlayer::Network."
  end
  value = Fog::Network[:softlayer].networks.get(value) if value.is_a?(Integer)
  attributes[:private_vlan] = value
end
public_ip() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 149
def public_ip # maintain backward compatibility with <0.3.13
  public_ip_address
end
public_network_components() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 222
def public_network_components
  if attributes['frontendNetworkComponents']
    attributes['frontendNetworkComponents'].map { |n| Fog::Compute::Softlayer::NetworkComponent.new(n) }
  else
    []
  end
end
ram=(set) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 198
def ram=(set)
  if set.is_a?(Array) and set.first['hardwareComponentModel']
    set = 1024 * set.first['hardwareComponentModel']['capacity'].to_i
  end
  attributes[:ram] = set
end
ready?() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 238
def ready?
  if bare_metal?
    state == "on"
  else
    state == "Running"
  end
end
reboot(use_hard_reboot = true) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 246
def reboot(use_hard_reboot = true)
  # TODO: implement
end
save() click to toggle source

Creates server

  • requires attributes: :name, :domain, and :flavor_id OR (:cpu_count && :ram && :disks)

@note You should use servers.create to create servers instead calling this method directly

  • State Transitions

    • BUILD -> ACTIVE

    • BUILD -> ERROR (on error)

# File lib/fog/softlayer/models/compute/server.rb, line 293
def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  copy = self.dup
  copy.pre_save

  data = if bare_metal?
    service.create_bare_metal_server(copy.attributes).body
  else
    service.create_vm(copy.attributes).body.first
  end

  data.delete("bare_metal")
  merge_attributes(data)
  true
end
shutdown() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 273
def shutdown
  # TODO: implement
end
snapshot() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 257
def snapshot
  # TODO: implement
end
ssh_password() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 250
def ssh_password
  requires :id
  service_path = bare_metal? ? :hardware_server : :virtual_guest
  @sshpass ||= service.request(service_path, id, :query => 'objectMask=mask[id,operatingSystem.passwords[password]]').body
  @sshpass['operatingSystem']['passwords'][0]['password'] unless @sshpass['operatingSystem'].nil? or @sshpass['operatingSystem']['passwords'].empty?
end
start() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 261
def start
  # TODO: implement

  #requires :identity
  #service.start_server(identity)
  true
end
state() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 277
def state
  if bare_metal?
    service.request(:hardware_server, "#{id}/getServerPowerState").body
  else
    service.request(:virtual_guest, "#{id}/getPowerState").body['name']
  end
end
stop() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 269
def stop
  # TODO: implement
end
tags() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 309
def tags
  attributes[:tags].map { |i| i['tag']['name'] } if attributes[:tags]
end
user_data() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 210
def user_data
  attributes[:user_data]
end
user_data=(value) click to toggle source

@params value [String]

# File lib/fog/softlayer/models/compute/server.rb, line 206
def user_data=(value)
  attributes[:user_data] = [{'value' => value}]
end
vlan() click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 186
def vlan
  attributes[:vlan] ||= _get_vlan
end
vlan=(value) click to toggle source
# File lib/fog/softlayer/models/compute/server.rb, line 190
def vlan=(value)
  unless value.is_a?(Integer) or value.is_a?(Fog::Network::Softlayer::Network)
    raise ArgumentError, "vlan argument for #{self.class.name}##{__method__} must be Integer or Fog::Network::Softlayer::Network."
  end
  value = Fog::Network[:softlayer].networks.get(value) if value.is_a?(Integer)
  attributes[:vlan] = value
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.