One benefit of working in a hardware company is that you actually have hardware. I have worked in software for a long time, and I have learned to appreciate when new servers are not such a scarce resource as to impact productivity. However, hardware in our group needs to be shared amongst a large group of developers, and constantly reserved, assigned, and reprovisioned. We use an install of the booked scheduler to reserve servers. As with many tools, I am most interested in using it in a scripted fashion. Booked comes with an API. Here’s some of the things I can do with it.
For these examples, I will first set my host name in en environment variable. This should allow you to use the examples on your server without much modification. This server does not really exist, so don’t be surprised at the errors.
export BOOKED_SERVER=booked.younglogic.com/lab
First, authentication. User ID and password. Create a json file that looks like this:
{
"username":"ayoung",
"password":"redacted"
}
Now grab a token to use for additional commands:
export SESSION_TOKEN=$( curl -s -H "Content-type: application/json" -d @/home/ayoung/devel/booked/auth.json https://$BOOKED_SERVER/Web/Services/index.php/Authentication/Authenticate | jq -r '.| .sessionToken' )
ayoung@ayoung-Latitude-7420:~/devel/booked$ echo $BOOKED_SESSION_TOKEN
f182f05856e934464748e608c14207d347540e4f68aa30887e
And to find my user ID
curl -s -H “Content-type: application/json” -d @/home/ayoung/devel/booked/auth.json https://bookedserver/scc-lab/Web/Services/index.php/Authentication/Authenticate | jq ‘.userId’
“208”
Lets look up reservations:
curl -s -H "Content-type: application/json" -H "X-Booked-SessionToken:$SESSION_TOKEN" -H "X-Booked-UserId:$BOOKED_USER_ID" https://$BOOKED_SERVER/Web/Services/index.php/Reservations/?userId=$BOOKED_USER_ID | jq '.reservations | .[] | .resourceName, .resourceId'
This will give a list of the resources associate with each reservation. Here is a fictionalized list.
"LAB1_FLOOR2_RACK18_DELL_123"
"302"
"LAB1_FLOOR2_RACK19_COMPAQ_123"
"656"
"LAB1_FLOOR2_RACK31_WANG_123"
"657"
"LAB1_FLOOR2_RACK8_COMMODORE_64"
"184"
I still have my C64.
To get information about a resource, grab its ID. I want the custom attribute SYSIP for a specific server:
curl -s -H "Content-type: application/json" -H "X-Booked-SessionToken:$SESSION_TOKEN" -H "X-Booked-UserId:$BOOKED_USER_ID" https://$BOOKED_SERVER/Web/Services/index.php/Resources/184 | jq '.customAttributes | .[] | select (.label == "SYSIP") | .value'
"10.76.242.63"
Or to get all information and do some simple formatting:
curl -s -H "Content-type: application/json" -H "X-Booked-SessionToken:$SESSION_TOKEN" -H "X-Booked-UserId:$BOOKED_USER_ID" https://$BOOKED_SERVER/Web/Services/index.php/Resources/184 | jq -r -j ' .customAttributes | .[] | .label, " ", .value, "\n"'
BMCIP 10.76.242.83
SYSIP 10.76.242.63
APCIP 10.76.242.10
APCport 9
...
Exercise for the reader: how would you confirm that a given user has a given server reserved, if all you have is the BMCIP of the server and the user name?