Skip to content

Instantly share code, notes, and snippets.

@lundvall
Created November 15, 2011 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lundvall/1366970 to your computer and use it in GitHub Desktop.
Save lundvall/1366970 to your computer and use it in GitHub Desktop.
Example usage of Groovy HTTPBuilder with Cisco UCS API
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.XML
def login(ip, username, password) {
String cookie = ""
def ucs = new RESTClient("http://${ip}/nuova")
def response = ucs.post(
contentType: XML,
requestContentType: XML,
body: {
aaaLogin inName:"${username}", inPassword:"${password}"
})
if(response.status == 200)
cookie = response.data.@outCookie
return cookie
}
def logout(ip, cookie) {
def ucs = new RESTClient("http://${ip}/nuova")
def response = ucs.post(
contentType: XML,
requestContentType: XML,
body: {
aaaLogout inCookie:"${cookie}"
})
if(response.status == 200)
println "Logged out"
}
def getBlade(ip, cookie) {
def blades = []
def ucs = new RESTClient("http://${ip}/nuova")
def response = ucs.post(
contentType: XML,
requestContentType: XML,
body: {
configResolveClass cookie:"${cookie}", classId:'computeBlade', inHierarchical:'false'
})
response.data.outConfigs.computeBlade.each { blade ->
def bladeProperties = [chassis: blade.@chassisId, slot: blade.@slotId,
model: blade.@model, numcpu: blade.@numOfCpus,
numcore: blade.@numOfCores, memsize: blade.@totalMemory,
connpath: blade.@connPath, connstatus: blade.@connStatus,
numadaptors: blade.@numOfAdaptors, uuid: blade.@originalUuid,
association: blade.@association]
blades.add(bladeProperties)
}
return blades
}
def printVlan(ip, cookie) {
def ucs = new RESTClient("http://${ip}/nuova")
def response = ucs.post(
contentType: XML,
requestContentType: XML,
body: {
configResolveClass cookie:"${cookie}", classId:'fabricVlan', inHierarchical:'false'
})
response.data.outConfigs.fabricVlan.each { vlan ->
println "${vlan.@name} \t ${vlan.@id} \t ${vlan.@switchId}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment