Rubrik : Automate Nutanix Cluster Configuration



Background

I would like to automate the Nutanix AHV cluster addition on my Rubrik appliances. Either for testing purpose or for more general deployments. In order to achieve this, you need to perform couple of actions and clicks in the UI. But since the Rubrik UI is API-First, of course, that should be doable via API call ? Isn't it ? But why limiting this to only adding new Cluster ? Let's see...

Let's API !

I digged a little bit on the Rubrik CDM UI code using the Rubrik API Code Capture and I've found all the relevant queries. Let's put them all into music !

Here are the functions I came up with : 

rkAddNutanix($clusterConnect,$nutanixCluster);
rkNutanixAddStatus($clusterConnect,$result);
rkGetNutanixClusters($clusterConnect);
rkGetNutanixCluster($clusterConnect,$clusterID);
kDelNutanix($clusterConnect,$clusterDetails->id);
rkNutanixDelStatus($clusterConnect,$result);

Let's have a look one by one to better understand the usage

rkAddNutanix

rkAddNutanix is adding a Nutanix cluster in the Rubrik configuration. You need 2 parameters : the famous $clusterConnect who contains the Rubrik cluster credentials and IP and the $nutanixCluster who contains all the relevant details to add the Nutanix AHV cluster.

Here is a sample for $nutanixCluster :

$nutanixCluster=array(
    "hostname" => "192.168.1.2",
    "nutanixClusterUuid" => "000512b5-0000-0000-0000-000000000000",
    "username" => "username",
    "password" => "supersecretpassword",
    "caCerts" => $rawCert
);

$caCerts is the Nutanix AHV cluster certificate that can be obtained following this article.

You need to enter it the same way it is displayed on the screen when you run the Python command described in the article : 

$rawCert="-----BEGIN CERTIFICATE-----
MIIDvzCCAqegAwIBAgIJAO4jof8scPpJMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNV
BAYTAlVTMQswCQYDVQQIDAJDQTERMA8GA1UEBwwIU2FuIEpvc2UxFTATBgNVBAoM
DE51dGFuaXggSW5jLjEWMBQGA1UECwwNTWFuYWdlYWJpbGl0eTEYMBYGA1UEAwwP
Ki5udXRhbml4LmxvY2FsMB4XDTE1MDQwMjAzNTIxMloXDTI1MDMzMDAzNTIxMlow
djELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMREwDwYDVQQHDAhTYW4gSm9zZTEV
MBMGA1UECgwMTnV0YW5peCBJbmMuMRYwFAYDVQQLDA1NYW5hZ2VhYmlsaXR5MRgw
FgYDVQQDDA8qLm51dGFuaXgubG9jYWwwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQCRECynQq/wGWOO4Y1a/pZu2Hbh0WT2mWZCgczaJ7PSnsHhIMsQAgdR
Eoj85ZEMg86VTPBFFPHq6dOkoz6tnlY7423BWvFQh1UYrEmkoD6n+2C6Huea7B0r
7rBebYTTqM8sIiFB4hFs8aQxaw+h7UGtljJahVCO1IbfEnsQXLqixEqg9TRNSt7M
TjQWkQdin6782PlvFuKo/8icynIOEfzem/DfsYBMQi+DlFAoXoQ2prcsEnmNcDOX
pym+Ycu/Wc59xdfrWmWSmBNngGRgTGImYXryWSvWctWPKkR/F4kOWb3Qg8qCE01e
uGh+QIT/mYU0lgw6sJnas6gjUU5LVyn7AgMBAAGjUDBOMB0GA1UdDgQWBBSR9agN
AlWWTfQw0P50SM7ftWhTETAfBgNVHSMEGDAWgBSR9agNAlWWTfQw0P50SM7ftWhT
ETAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBJF38QZVHoPrRUr4ra
CUgmXOgZ4rXxXxXxXxXxXxXxX37tOIcEbQXuBPvn50aFybWghlF+YT3pNcBN4r7y
zQfkU042tPEVPi80wqyo+TTaPkvsObvpyvYqcFjZizOdCYgWODhA3xESC7yVJXiy
G4Gos4DorX4UEqiCLrQpVPPfhP1U9876543234zeoRRSNReIOA6jXWXrE4dMxbG1
n/xXS7jWtMk58MnzLGcnlnXZlS4xLUSRtBRB6CC7His/PQVe+HrjcvwYn+DhPiDE
SITehvlhX1H6iYXdxzRIhiLC6fLST5Q+Lq4ZxkP9/KiIlIuOVTj/DH+fdmDDUkWj
z5J4
-----END CERTIFICATE-----";

Of course, this certificate is a dummy one, this is just to give you an idea.

When the function is called, it is returning the job ID of the Nutanix cluster addition.

rkNutanixAddStatus

This function is checking the progress of the cluster addition. You need to pass the Rubrik cluster $clusterConnect array in addition to the jobID provided by the above function.

An easy way to wait for the cluster to be successfully created is a loop similar to this : 

$result=rkAddNutanix($clusterConnect,$nutanixCluster);
print("Adding Nutanix cluster...");

$done='';

while ($done!="Success")
{
    $status=rkNutanixAddStatus($clusterConnect,$result);
    $done=$status->status;
}

print("\nNutanix Cluster added !\n\n");

As you can see, we are aiming at a "Success" status returned Rubrik API stack.

Now that we have our cluster added, we can query it to get the details. First, let's get all configured clusters with rkGetNutanixClusters.

rkGetNutanixClusters

This function will return all Nutanix AHV cluster configured on the Rubrik side.

$nutanixClusters=rkGetNutanixClusters($clusterConnect);

It will return a list of cluster ID :

array(1) {
  [0]=>
  string(53) "NutanixCluster:::9ff4d91d-d4f8-448b-88c3-ec281831fe21"
}

With the cluster ID we can use the next function to get all details of that cluster.

rkGetNutanixCluster

This function return all possible details related to the cluster ID we are providing to it.

rkGetNutanixCluster($clusterConnect,$id));

Returned details are similar to this :  

object(stdClass)#9 (12) {
  ["id"]=>
  string(53) "NutanixCluster:::9ff4d91d-d4f8-448b-88c3-ec281831fe21"
  ["name"]=>
  string(7) "MY-NTNX"
  ["configuredSlaDomainId"]=>
  string(7) "INHERIT"
  ["configuredSlaDomainName"]=>
  string(7) "Inherit"
  ["configuredSlaDomainType"]=>
  string(13) "ProtectionSla"
  ["primaryClusterId"]=>
  string(36) "aff943b2-aabf-4cae-97c2-f376e5493e70"
  ["isConfiguredSlaDomainRetentionLocked"]=>
  bool(false)
  ["naturalId"]=>
string(36) "000512b5-0000-0000-0000-000000000000"
  ["hostname"]=>
  string(13) "192.168.1.2"
  ["username"]=>
  string(7) "username"
  ["connectionStatus"]=>
  object(stdClass)#1 (1) {
    ["status"]=>
    string(9) "Connected"
  }
  ["caCerts"]=>
  string(1358) "-----BEGIN CERTIFICATE-----
MIIDvzCCAqegAwIBAgIJAO4jof8scPpJMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNV
BAYTAlVTMQswCQYDVQQIDAJD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/xXS7jWtMk58MnzLGcnlnXZlS4xLUSRtBRB6CC7His/PQVe+HrjcvwYn+DhPiDE
SITehvlhX1H6iYXdxzRIhiLC6fLST5Q+Lq4ZxkP9/KiIlIuOVTj/DH+fdmDDUkWj
z5J4
-----END CERTIFICATE-----"
}

Useful details is the username. Sometimes this could be an issue if you cluster is seen as disconnected.

Now, let's see how to remove a Nutanix AHV cluster.

rkDelNutanix

Adding is nice, removing can be interesting to. Of course, there is all the relevant API calls to manage this task.

$result=rkDelNutanix($clusterConnect,$clusterDetails->id);

Similar to the addition task, the removal task will give you the job id to check what is the status of the deletion.

Once you have the job id, you can check the status with the last function : rkNutanixDelStatus.

rkNutanixDelStatus

Again, this function is checking the progress of the cluster addition. You need to pass the Rubrik cluster $clusterConnect array in addition to the jobID provided by the above function.

rkNutanixDelStatus($clusterConnect,$result);

Sample usage (of course similar to add status...)

$result=rkDelNutanix($clusterConnect,$clusterDetails->id);

$done='';

while ($done!="Success")
{
$status=rkNutanixDelStatus($clusterConnect,$result);
$done=$status->status;
}

print("\nNutanix Cluster removed !\n\n");

If you want to see it in action, there is a full sample code on my GitHub repo.

I hope this help !
more coming soon ...





Comments

What's hot ?

ShredOS : HDD degaussing with style

ThingSpeak : Create some useful formulas