Created
July 3, 2015 05:07
-
-
Save sio4/2a83939da1d6ef3ed95f to your computer and use it in GitHub Desktop.
SoftLayer API Test (Ruby)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'softlayer_api' | |
USER = "@@USERNAME@@" | |
API_KEY = "@@API_KEY@@" | |
client = SoftLayer::Client.new(username: USER, api_key: API_KEY) | |
puts client.to_json | |
puts "Account -------------------------------------------------------------" | |
service = client[:Account] | |
object = service.getObject | |
account = SoftLayer::Account.new(client, object) | |
puts "Service: #{service} (#{service.class})" | |
puts "Account: #{account.companyName}, #{object['email']}" | |
puts "Tickets -------------------------------------------------------------" | |
# All tickets from Service object. | |
last_id = 0 | |
service.getTickets.each do |item| | |
if item['statusId'] == 1002 | |
next | |
end | |
puts "TicketEach: #{item['id']} #{item['statusId']} #{item['title']}" | |
last_id = item['id'] | |
end | |
# Ticket from TicketService object. | |
ticket_service = client[:Ticket] | |
ticket_ref = ticket_service.object_with_id(last_id) | |
ticket = ticket_ref.object_mask("mask[id, statusId, title]").getObject | |
puts "Ticket Masked: #{ticket['id']} #{ticket['statusId']} #{ticket['title']}" | |
# Open tickets from Account object. | |
account.open_tickets.each do |ticket| | |
puts "Open Ticket: #{ticket.id} #{ticket.title}" | |
end | |
puts "Hardware --------------------------------------------------------------" | |
service.getHardware.each do |item| | |
puts "Hardware: #{item['id']} #{item['fullyQualifiedDomainName']}" | |
end | |
puts "Virtual Machine -------------------------------------------------------" | |
# VMs from Service object. (returns list of Hash) | |
service.getVirtualGuests(limit: 10, offset: 0).each do |item| | |
puts "VM: #{item['id']} #{item['hostname']} #{item['maxCpu']}Cores/#{item['maxMemory']}MB, #{item['primaryIpAddress']}" | |
end | |
# Servers from Account object. (returns list of Server) | |
account.servers.each do |s| | |
puts " Server: #{s.hostname} at #{s.datacenter['longName']} (#{s.notes})" | |
end | |
puts "Bare Meta Servers from Account" | |
account.bare_metal_servers.each do |s| | |
puts " mServer: #{s.hostname} at #{s.datacenter['longName']} (#{s.notes})" | |
end | |
puts "Virtual Servers from Account" | |
account.virtual_servers.each do |s| | |
puts " vServer: #{s.hostname} (#{s.blockDevices.count}Disk #{s.cores}Core)" | |
end | |
puts "Image Templates from Account" | |
account.image_templates.each do |s| | |
puts " Template: #{s.name}:#{s.note} (#{s.notes})" | |
end | |
puts "Virtual Disk Images from Account" | |
account.virtual_disk_images.each do |s| | |
puts " Disk Image: #{s.name}: #{s.capacity}GB (#{s.description})" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment