Created
November 15, 2011 12:31
-
-
Save lundvall/1366970 to your computer and use it in GitHub Desktop.
Example usage of Groovy HTTPBuilder with Cisco UCS API
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
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