Skip to content

Instantly share code, notes, and snippets.

@chechuironman
Last active August 29, 2015 14:02
Show Gist options
  • Save chechuironman/4a73f7eca1bf67046f84 to your computer and use it in GitHub Desktop.
Save chechuironman/4a73f7eca1bf67046f84 to your computer and use it in GitHub Desktop.
List servers provisioned for a specific user
#!/usr/bin/ruby
##################################################################################
# list servers for a specific user
# ©Copyright IBM Corporation 2014.
# LICENSE: MIT (http://opensource.org/licenses/MIT)
# gems used:
# rubygems, softlayer-api
##################################################################################
def list_cci(user,api)
### INPUT: SL user, user API key
### OUTPUT: JSON array with all the CCIs running on SL for that user
begin
account_service = SoftLayer::Service.new("SoftLayer_Account",:username => user,:api_key => api)
object_mask = {
"id" => "",
"fullyQualifiedDomainName" => "",
"hostname"=>"",
"billingItem" => {"orderItem.order.userRecord.username"=> ""}
}
list = @account_service.object_mask(@object_mask).getVirtualGuests()
test_2 = []
$j=0
$i=0
length = list.length
while i < length
if list[$i]['billingItem'] != nil then
if list[i]['billingItem']['orderItem']['order']['userRecord']['username'] == user then
test_2[$j] = list[$i]
$j +=1
end
end
$i +=1
end
rescue Exception => exception
puts "An error occured while listing the servers Message: #{exception}"
return false
end
# servers are returned in JSON format by SL
return test_2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment