View Source

The following example demonstrates how to use the API to delete a server and its associated policies and disk safes.

You can find the PHP file {{DeleteManaged_Agent_And_Its_Association.php}} at the following locations:
* for Windows: {{<installdir>\apisamples}}
* for Linux: {{<installdir>/apisamples}}

For more information about using the Server Backup Manager API, see [Access example API functions].

The PHP script finds and deletes objects in the system, and then displays the following information:
* "Successfully retrieved all the Agents" / "No Agent out with the specified ID" / "Failed to get the specified Agent"
* "Successfully retrieved all the Disk Safes" / "Failed to get all Disk Safes"
* "Successfully retrieved all the Policies" / "Failed to get all the Policies"
* "Failed to delete all policie(s)" / "All policie(s) deleted successfully"
* "Failed to delete all DiskSafe(s)" / All DiskSafe(s) deleted successfully"
* "Failed to delete Agent" / "Agent deleted successfully"

h4. Sequence of automated actions

This script allows you to:


# Find a Backup Agent containing the specified ID. If such Agent does not exist, then exit or save the Server ID.
# Find all disk safes associated with the specified Server ID. Save the found Disk Safe IDs.
# Find all policies associated with the found disk safes. Save the found Policy IDs.
# Delete found policies.
# Delete found disk safes.
# Delete found Backup Agent.

h4. How to fulfill the appropriate actions in the Server Backup Manager user interface

The following steps help you to perform the same actions as the script, along with screen-shots illustrating every step in scripts.

----
{toc:location=top|maxLevel=5|minLevel=5|type=flat|separator=pipe|style=border:1}
----
h5. First step

{code}
date_default_timezone_set('America/Chicago');


########====CDP Server Configuration Start====########
#set CDP server host name
$HOST="10.230.100.207";
#set CDP server to access API
$PORT="9443";
#set CDP user
$USER="admin";
#set CDP user password
$PASS="admin";
########====CDP Server Configuration End====########




########====SetAgent ID to be deleted Start====########
$ID = "a6215c5f-6827-4260-956c-5ea14e6a8296";
########====SetAgent ID to be deleted End====########


{code}


!Enterprise_login form_10.230.100.207_English.png!


h5. Retrieving the server and associated disk safes and policies

{code}
########====Get DiskSafes Start====########

try{

$diskSafeClient = new soapclient("https://$HOST:$PORT/DiskSafe?wsdl",
array('login'=>"$USER",
'password'=>"$PASS",
'trace'=>1,
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS)
);

// retrive all the ids
$allDiskSafes = $diskSafeClient->getDiskSafes();
echo "Successfully retrived all the diskSafes \n";
$selectedDiskSafeIDs = array();
foreach($allDiskSafes->return as $tmp) {
// check if the disksafe has a valid agent set and it's id == the agent to be deleted
if (isset($tmp->agentID) && $tmp->agentID == $selectedAgentID){
// if the condition is true store then store the ids
array_push($selectedDiskSafeIDs, $tmp->id);
}
}

}
catch (SoapFault $exception)
{
echo "Failed to get all diskSafes \n";
echo $exception;
exit(1);
}

########====Get DiskSafes End====########

########====Get policies Start====########

if (count($selectedDiskSafeIDs) > 0){
try{
$policyClient = new soapclient("https://$HOST:$PORT/Policy2?wsdl",
array(
'login'=>"$USER",
'password'=>"$PASS",
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace'=>1
)
);
// get all the policies
$allPolicies = $policyClient->getPolicies();

echo "Successfully retrived all the diskSafes \n";
$selectedPolicyIDs = array();
foreach($allPolicies->return as $tmp) {
// check to see if disksafe id of the policy belongs in the list selectedDiskSafeIDs
if (in_array($tmp->diskSafeID, $selectedDiskSafeIDs)){
// if the condition is true save the policy id
array_push($selectedPolicyIDs, $tmp->id);
}
}

}
catch (SoapFault $exception)
{
echo "Failed to get all the policies \n";
echo $exception;
exit(1);
}
}

########====Get Policies End====########


########====Get Agent Start====########

try{
$agentClient = new soapclient("https://$HOST:$PORT/Agent?wsdl",
array('login'=>"$USER",
'password'=>"$PASS",
'trace'=>1,
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS)
);
# get all the agents
$allAgents=$agentClient->getAgents();
echo "Successfully retrived all the agents \n";

foreach($allAgents->return as $tmp) {
// check to see if the specified agent id matches the any of the retrived ids
if ($tmp->id == $ID){
// if it matches store the id
$selectedAgentID = $tmp->id;
break;
}
}

// if nothing matches then exit the program
if (!isset($selectedAgentID)){
echo " No Agent out with the specified ID $ID" ;
exit(1);
}
}
catch (SoapFault $exception)
{
echo "Failed to get the specified agent \n";
echo $exception;
exit(1);
}

########====Get Agent End====########
{code}


1. Click on "Servers" in the Main Menu to access the Servers page.


!Main menu_Servers_English.png!


2. Then click "Basic List Filter" in the Servers menu located in the top left area of the interface.


!Servers menu_Basic List Filter_English.png!


3. Specify the Server name and click "Filter" to apply the search filter.

{info:title=Note}While the script searches by Server ID, we search by Server name in the Backup Manager interface. {info}
&nbsp; !Servers menu_Basic List Filter_Server Name selected_English.png!

4. The found Server will be displayed in the list.

!Servers list_server found_English.png!

5. The Server's Disk Safes and Policies can be found via the Details pane once the Server is selected in the list.

!Server Detail for Multi-Level Reseller_2 tabs outlined_English.png!

h5. Deleting Policies, Disk Safes, and the Server
{code}
########====Delete DiskSafes Start====########
// check to see if there are any disksafes to be deleted
if (count($selectedDiskSafeIDs) > 0){
try {
// iterate over the list of disksafe IDs and delete them
foreach($selectedDiskSafeIDs as $tmp) {
$diskSafeClient->deleteDiskSafeByID(array('diskSafeID'=>$tmp));
}
}
catch (SoapFault $exception)
{
echo "Failed to delete all DiskSafe(s) \n";
echo $exception;
exit(1);
}
echo "All DiskSafe(s) deleted successfully \n";
}

########====Delete DiskSafe End====########

########====Delete Agent Start====########
try {
# finally delete the specified agent
$agentClient->deleteAgentByID(array('id'=>$selectedAgentID));
}
catch (SoapFault $exception)
{
echo "Failed to delete agent\n";
echo $exception;
exit(1);
}
echo "Agent deleted Successfully \n";

########====Delete Agent End====########
########====Delete Policies Start====########
// check to see if there are any policies to be deleted
if (count($selectedPolicyIDs) > 0){
try {
// iterate over the list of policy IDs and delete them
foreach($selectedPolicyIDs as $tmp) {
$policyClient->deletePolicyByID(array('policyID'=>$tmp));
}
}
catch (SoapFault $exception)
{
echo "Failed to delete all policie(s) \n";
echo $exception;
exit(1);
}
echo "All policie(s) deleted successfully \n";
}

########====Delete Policies End====########
{code}


1. Click on the "Delete" (red X) icon under "Actions" for the corresponding Server in the list.


!Servers list_server found_Delete icon_English.png!

Alternatively, select the check-box(es) in front of the Server(s) and click on the "Delete Selected" button.

!Servers list_server found_Delete Selected button_English.png!

2. Familiarize yourself with the information displayed on the pop-up. Check the "Delete disk safes from disk" option. Click "Delete".

!Delete Server window_Delete disk safe checkbox selected_English.png!

3. The Server and its associated Disk Safes and Policies will disappear from the system.