September 30, 2014


Server Locate

List specific physical location for virtual machines
require 'softlayer_api' # gem install softlayer_api
require 'table_print' # gem install table_print

# Credentials to the SoftLayer API are grabbed from the config file by default.
# See https://github.com/softlayer/softlayer-ruby/blob/master/lib/softlayer/Config.rb#L11-L44
SoftLayer::Client.default_client = SoftLayer::Client.new

servers = SoftLayer::VirtualServer.find_servers(object_mask: 'mask[location.pathString]')
location_info = servers.map do |server|
  datacenter, server_room, rack, slot = server['location']['pathString'].split('.')
  {
    server: server.fullyQualifiedDomainName,
    data_center: datacenter,
    server_room: server_room,
    rack: rack,
    slot: slot
  }
end


tp location_info