Last active
August 29, 2015 14:02
-
-
Save chechuironman/4a73f7eca1bf67046f84 to your computer and use it in GitHub Desktop.
List servers provisioned for a specific user
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/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