Class: SoftLayer::Datacenter

Inherits:
ModelBase show all
Defined in:
lib/softlayer/Datacenter.rb

Overview

A Data Center in the SoftLayer network

This class corresponds to the SoftLayer_Location++ data type:

sldn.softlayer.com/reference/datatypes/SoftLayer_Location

Although in this context it is used to represent a data center and not the more general class of locations that that data type can represent.

Constant Summary collapse

@@data_centers =

Return a list of all the datacenters

If the client parameter is not provided, the routine will try to use Client::defult_client. If no client can be found, the routine will raise an exception

This routine will only retrieve the list of datacenters from the network once and keep it in memory unless you pass in force_reload as true.

nil

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Class Method Summary collapse

Methods inherited from ModelBase

#[], #has_sl_property?, #initialize, #refresh_details, #service, sl_attr, #to_ary

Constructor Details

This class inherits a constructor from SoftLayer::ModelBase

Class Method Details

.datacenter_named(name, client = nil) ⇒ Object

Return the datacenter with the given name ('sng01' or 'dal05')



25
26
27
# File 'lib/softlayer/Datacenter.rb', line 25

def self.datacenter_named(name, client = nil)
  datacenters(client).find{ | datacenter | datacenter.name == name.to_s.downcase }
end

.datacenters(client = nil, force_reload = false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/softlayer/Datacenter.rb', line 41

def self.datacenters(client = nil, force_reload = false)
  softlayer_client = client || Client.default_client
  raise "Datacenter.datacenters requires a client to call the network API" if !softlayer_client

  if(!@@data_centers || force_reload)
    datacenters_data = softlayer_client[:Location].getDatacenters
    @@data_centers = datacenters_data.collect { | datacenter_data | self.new(softlayer_client, datacenter_data) }
  end

  @@data_centers
end