Skip to content

Instantly share code, notes, and snippets.

@jpboyce
Created March 28, 2019 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpboyce/56c54a32637645d2fbece61ac1cd3d91 to your computer and use it in GitHub Desktop.
Save jpboyce/56c54a32637645d2fbece61ac1cd3d91 to your computer and use it in GitHub Desktop.
Set the state of a F5 Pool Member
/*
This snippet expects the following inputs:
- memberName (string)
- memberPort (number)
- poolName (string)
- restOperation (REST:RESTOperation)
- state (string)
restOperation will be a RESTOperation object that uses the URL for setting a Pool Member's state
*/
// Construct payload based on the state value
switch(state) {
case "enable":
//
payload = '{"state": "user-up", "session": "user-enabled"}';
break;
case "disable":
//
payload = '{"state": "user-up", "session": "user-disabled"}';
break;
case "forceoffline":
//
payload = '{"state": "user-down", "session": "user-disabled"}';
break;
default:
// throw an error
throw "An invalid value (" + state + ") was submitted for the input parameter state";
}
System.log("Payload value has been set to: " + payload);
// Set inputs for the REST call
var inputs = [poolName,memberName,memberPort];
// Create request
var request = restOperation.createRequest(inputs,payload);
// Execute request
var response = request.execute();
// Parse and output response
var jsonObject = JSON.parse(response.contentAsString);
System.log(response.contentAsString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment