Phone sales support +39 0575 05077
  Phone technical support +39 0575 0508
 
Computing > 2 - Manipulating the items > Deleting a Cloud Server

2.4 Deleting a Cloud Server

How to delete a Cloud Server

Using Aruba's WsEndUser SetEnqueueServerDeletion method you can queue a virtual deletion server operation (Job) indicated by the parameter serverId. This operation will let you remove the virtual server from the virtual datacenter associated with the specified account. The GetServers method helps us to retrieve the serverId that concerns us which returns the list of servers associated with the account specified during login.
//IWsEndUser.GetServersList Method (c# .NET)
private static String GetServersList(WsEndUserClient client)
{
    //a StringBuilder class object is created 
    StringBuilder sb = new StringBuilder();
    try
    {
        //calls the GetServers method, 
        //getting a WsResultOfArrayOfServer object 
        WsResultOfArrayOfServer result = client.GetServers(null);

        //if the call fails; it relaunches the error indicating the message 
        if (result.Success)
        {
            b.AppendLine("LIST OF AVAILABLE SERVER:");
            
            //the list of servers is stored in a list 
            List listOfServer = result.Value.ToList();
            foreach (Server s in listOfServer)
            {
                sb.AppendLine(String.Format("Server: {0} Id: {1}", s.Name, s.ServerId));
                sb.AppendLine(String.Format("\t Status: {0}", s.ServerStatus));
                sb.AppendLine(String.Format("\t Number of CPU: {0}", s.CPUQuantity));
                sb.AppendLine(String.Format("\t Number of disks: {0}", s.HDQuantity));
                sb.AppendLine(String.Format("\t Disk size: {0}", s.HDTotalSize));
                sb.AppendLine(String.Format("\t Ram quantity: {0}", s.RAMQuantity));
            }
        }
        else
        {
            throw new ApplicationException(result.ResultMessage);
        }
    }
    catch (Exception ex)
    {
        //relaunches the generic error 
        throw new ApplicationException(ex.Message);
    }

    return sb.ToString();
}
//IWsEndUser.GetServersList Method (JAVA)
private static List<String> GetServersList(IWsEndUser client)
{
    //a StringBuilder class object is created 
    List<String> sb = new ArrayList<String>();
    
    try
    {
        //calls the GetServers method, 
        //getting a WsResultOfArrayOfServer object 
        WsResultOfArrayOfServer result = client.getServers(null);

        //if the call fails; it relaunches the error indicating the message 
        if (result.isSuccess())
        {
            sb.add("LIST OF AVAILABLE SERVER:");
            
            //the list of servers is stored in a list 
            for (Server s : result.getValue().getServer())
            {
                sb.add("Id: " + s.getServerId());
                sb.add("Server: " + s.getName());
                sb.add("... Status: " + s.getServerStatus());
                sb.add("... Number of CPU: " + s.getCPUQuantity());
                sb.add("... Number of disks: " + s.getHDQuantity());
                sb.add("... Disk size: " + s.getHDTotalSize());
                sb.add("... Ram quantity: " + s.getRAMQuantity());
            }
        }
        else
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (Exception ex)
    {
        //prints the error 
        System.out.println(ex);
    }

    return sb;
}
Once the serverId has been identified we move on to implement the method to delete our server:
//IWsEndUser.SetEnqueueServerDeletion Method (c# .NET)
private static void DeleteVirtualServer(WsEndUserClient client, int serverId)
{
    try
    {
        //calls the SetEnqueueServerDeletion method,
        //getting a WsResult object 
        WsResult result = client.SetEnqueueServerDeletion(serverId);

        //if the call fails, the exception is relaunched 
        //with the indication of the type of error 
        if (!result.Success)
            throw new ApplicationException(result.ResultMessage);
    }
    catch (Exception ex)
    {
        //relaunches the generic error 
        throw new ApplicationException(ex.Message);
    }
}
//IWsEndUser.setEnqueueServerDeletion Method (JAVA)
private static void DeleteVirtualServer(IWsEndUser client, int serverId)
{
    try
    {
        //calls the setEnqueueServerDeletion method, 
        //getting a WsResult object 
        WsResult result = client.setEnqueueServerDeletion(serverId);

        //if the call fails, the exception is relaunched 
        //with the indication of the type of error 
        if (!result.isSuccess())
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (Exception ex)
    {
        //prints the error 
        System.out.println(ex);
    }
}

Version
API: v2.8 URL: https://api.dc1.computing.cloud.it/WsEndUser/v2.8/WsEndUser.svc?wsdl
See also

API: v2.8 URL: https://api.dc1.computing.cloud.it/WsEndUser/v2.8/WsEndUser.svc?wsdl

Bookmark and Share