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

2.6 Deleting a Public IP

How to delete a public IP

Using Aruba's WsEndUser SetRemoveIpAddress method you can remove the IP address specified, if associated with the account with which you call the method. If the IP address you want to remove is associated with another account, an error message will be returned and the operation will not be completed. The operation of removing the IP address cannot be completed if at the time of calling the SetRemoveIpAddress method the specified address is associated with a network adapter of the Cloud Server. In the same way, the operation of removing the IP address cannot be completed if there is already an operation, relating to the IP address specified, queued with a status other than Error or Completed.
To retrieve the ID of the configuration we can use the GetPurchasedIpAddresses method.
Using this method you can get a list of IPAddress class objects that represent IP addresses purchased and then associated with the account that you specified during authentication. The IPAddress objects got in this way lets you view the main features of the IP addresses purchased: mainly the name of the resource, its identification code (ID) and the identification code of the server that the VLAN is associated with.
//IWsEndUser.GetPurchasedIpAddresses Method (c# .NET)
private static List<IPAddress> GetPurchasedIpAddress(WsEndUserClient client)
{
    List<IPAddress> listOfPurchasedIPAddress = new List<IPAddress>();

    try
    {
        //calls the GetPurchasedIpAddresses method, 
        //getting a WsResultOfArrayOfIPAddress object
        WsResultOfArrayOfIPAddress result = client.GetPurchasedIpAddresses();
        
        //checks that the call was successful 
        if (result.Success)
        {
            //stores the virtual IPs in the IPAddress list 
            //got from Aruba's WsEndUser method 
            listOfPurchasedIPAddress = result.Value.ToList<IPAddress>();
            foreach (var ipaddress in listOfPurchasedIPAddress)
            {
                Console.WriteLine(ipaddress.ResourceId);
            }
        }
    }
    catch (Exception ex)
    {
        //relaunches the error 
        throw new ApplicationException(ex.Message);
    }

    //returns the IPAddress got list 
    return listOfPurchasedIPAddress;
}
//IWsEndUser.getPurchasedIpAddresses Method (JAVA)
private static List<IPAddress> GetPurchasedIpAddress(IWsEndUser client)
{
    List<IPAddress> listOfPurchasedIPAddress = new ArrayList<IPAddress>();

    try
    {
        //calls the getPurchasedIpAddresses method, 
        //getting a WsResultOfArrayOfIPAddress object
        WsResultOfArrayOfIPAddress result = client.getPurchasedIpAddresses();
        
        //checks that the call was successful  
        if (result.isSuccess())
        {
            //stores the public IPs in the IPAddress list
            //got from Aruba's WsEndUser method 
            listOfPurchasedIPAddress = result.getValue().getIPAddress();
            for (IPAddress ipaddress : listOfPurchasedIPAddress)
            {
                System.out.println(ipaddress.getServerId());
                System.out.println(ipaddress.getResourceId());
                System.out.println(ipaddress.getValue());
                System.out.println(ipaddress.getSubNetMask());
                System.out.println(ipaddress.getGateway());                       
             }
        }
    }
    catch (Exception ex)
    {
        //prints the error 
        System.out.println(ex.getMessage());
    }

    //returns the IPAddress got list 
    return listOfPurchasedIPAddress;
}
Once our ID has been identified we move on to implementing the method to delete our public IP:
//IWsEndUser.SetRemoveIpAddress Method (c# .NET)
private static void RemoveIpAddress(WsEndUserClient client, int ipaddressId)
{
    try
    {
        //calls the SetPurchaseIpAddress method, 
        //getting a WsResult object 
        WsResult result = client.SetRemoveIpAddress(ipaddressId);

        //if the call fails; it relaunches the error indicating the message 
        if (!result.Success)
            throw new ApplicationException(result.ResultMessage);
    }
    catch (Exception ex)
    {
        //relaunches the generic error 
        throw new ApplicationException(ex.Message);

    }
}
//IWsEndUser.setRemoveIpAddress Method (JAVA)
private static void RemoveIpAddress(IWsEndUser client, int ipaddressId)
{
    try
    {
        //calls the setRemoveIpAddress method, 
        //getting a WsResult object 
        WsResult result = client.setRemoveIpAddress(ipaddressId);

        //if the call fails; it relaunches the error indicating the message 
        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