Rubrik : User Addition/Deletion with API

Background

When you have multiple cluster, you may want to create or revoke access easily to your platform. If your clusters are not connected to a central directory, you need to go one by one and pray for not forgetting one. Hopefully, API comes to the rescue!

Adding/Removing Users to a single Rubrik Cluster

There are a few useful functions in my Php Framework that can help with this.

  • rkCreateUser
  • rkDeleteUser
  • rkMakeAdminUser
  • rkGetUserID

Adding users

First, we need to provide user details :

$bulkUsers=array(
0 => array(
"username" => "user1",
"password" => "P@ss_0rd123!",
"firstName" => "First",
"lastName" => "Last",
"emailAddress" => "me@local.com"
),
1 => array(
"username" => "user2",
"password" => "P@ss_0rd123!",
"firstName" => "First",
"lastName" => "Last",
"emailAddress" => "me@local.com"
)
  );

Note : pay attention when specifying the passwords, they must comply with the password complexity on the Rubrik side.

Next, we loop through this array and add each users and give the admin rights

print("Creating ".count($bulkUsers)." user(s)...\n");

for($i=0;$i<count($bulkUsers);$i++)
{
$return=rkCreateUser($clusterConnect,$bulkUsers[$i]["username"],$bulkUsers[$i]["password"]);
$id=rkGetUserID($clusterConnect,$bulkUsers[$i]["username"]);
rkMakeAdminUser($clusterConnect,$id);
if(isset($return->message)) print("-> ".rkColorOutput($return->message)."\n");
else print("-> ".rkColorOutput($return->username)." created.\n");
}

Deleting the users is very similar

print("\nDeleting ".count($bulkUsers)." user(s)...\n");

for($i=0;$i<count($bulkUsers);$i++)
{
$id=rkGetUserID($clusterConnect,$bulkUsers[$i]["username"]);
print("Deleting ".rkColorOutput($bulkUsers[$i]["username"])." : ");
$result=rkDeleteUser($clusterConnect,$id);
print(rkColorOutput($result)."\n");
}

Adding/Removing users to many Rubrik Clusters

In this case, we need to define all clusters we need to add/remove users and loop through them. We then require to create another array :

$clusterConnect=array(
0 => array(
"username" => "username",
"password" => "password",
"ip" => "ip_of_rubrik"
),
1 => array(
"username" => "username",
"password" => "password",
"ip" => "ip_of_rubrik"
)
               );

Then, in a double loop, we go through the 2 arrays pushing user details into the array of Rubrik clusters.

First, for creating users :

print("\nCreating ".rkColorOutput(count($bulkUsers))." user(s) on ".rkColorOutput(count($clusterConnect))." cluster(s) ...\n");


for($i=0;$i<count($clusterConnect);$i++)
{
print("Creating users in ".rkColorOutput($clusterConnect[$i]["ip"])."\n");
for($j=0;$j<count($bulkUsers);$j++)
{
$return=rkCreateUser($clusterConnect[$i],$bulkUsers[$j]["username"],$bulkUsers[$j]["password"]);
$id=rkGetUserID($clusterConnect[$i],$bulkUsers[$j]["username"]);
rkMakeAdminUser($clusterConnect[$i],$id);
if(isset($return->message)) print("-> ".rkColorOutput($return->message)."\n");
else print("-> ".rkColorOutput($return->username)." created.\n");
}
}

Then, to remove them : 

print("\nDeleting ".rkColorOutput(count($bulkUsers))." user(s) on ".rkColorOutput(count($clusterConnect))." cluster(s) ...\n");

for($i=0;$i<count($clusterConnect);$i++)
{
print("Deleting users in ".rkColorOutput($clusterConnect[$i]["ip"])."\n");
for($j=0;$j<count($bulkUsers);$j++)
{
$id=rkGetUserID($clusterConnect[$i],$bulkUsers[$j]["username"]);
print("Deleting ".rkColorOutput($bulkUsers[$j]["username"])." : ");
$result=rkDeleteUser($clusterConnect[$i],$id);
print(rkColorOutput($result)."\n");
}
}

Here is the script output (with 3 users and 2 clusters)



This can be handy for massive cluster environment when user(s) has/have to be added on 20 or 50 clusters at once.

You can find the source code on my GitHub Repository.


Comments

What's hot ?

Wallbox : Get The Most Of It (with API)

Mac OS X : Display images in-line with terminal

ShredOS : HDD degaussing with style