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

2.8 Deleting a Virtual Switch

How to delete a Virtual Switch

Using Aruba's WsEndUser SetRemoveVLan method you can remove the VLAN specified, if associated with the account with which you call the method. If the VLAN you want to remove does not exist an error message will be returned and the operation will not be completed. The operation of removing the Virtual Switch cannot be completed if at the time of calling the SetRemoveVLan method the specified address is associated with a network adapter. In the same way, the operation of removing the Virtual Switch cannot be completed if there is already an operation relating to the VLAN specified, queued with a status other than Error or Completed. To retrieve the ID of the configuration we can use the GetPurchasedVLans method. Using this method you can get a list of VLAN class objects that represent the virtual VLANs purchased and then associated with the account specified during authentication. The VLAN objects got in this way lets you view the main features of the VLANs 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.GetPurchasedVLans Method (c# .NET)
private List<VLan> GetPurchasedVLans(WsEndUserClient client)
{
    List<VLan> listOfPurchasedVlan = new List<VLan>();

    try
    {
        //calls the GetPurchasedVLans method, 
        //getting a WsResultOfArrayOfVLan object 
        WsResultOfArrayOfVLan result = client.GetPurchasedVLans();

        //checks that the call was successful 
        if (result.Success)
        {
            //stores the VLANs returned in the VLAN list 
            //from Aruba's WsEndUser method 
            listOfPurchasedVlan = result.Value.ToList<VLan>();
            foreach (var vlan in listOfPurchasedVlan)
            {
                Console.WriteLine(vlan.ResourceId);
            }
        }
    }
    catch (Exception ex)
    {
        //relaunches the error 
        throw new ApplicationException(ex.Message);
    }

    //returns the VLANs got list 
    return listOfPurchasedVlan;
}
//IWsEndUser.GetPurchasedVLans Method (JAVA)
private static List<VLan> GetPurchasedVLans(IWsEndUser client)
{
    List<VLan> listOfPurchasedVlan = new ArrayList<VLan>();

    try
    {
        //calls the GetPurchasedVLans method, 
        //getting a WsResult object 
        WsResultOfArrayOfVLan result = client.getPurchasedVLans();

        //checks that the call was successful 
        if (result.isSuccess())
        {
            //stores the VLANs returned in the VLAN list 
            //from Aruba's WsEndUser method 
            listOfPurchasedVlan = result.getValue().getVLan();
            for (VLan vlan : listOfPurchasedVlan)
            {
                System.out.println(vlan.getResourceId());
                System.out.println(vlan.getName());
                System.out.println(vlan.getVlanCode());
                for (int serverId : vlan.getServerIds().getInt())
                {
                    System.out.println(serverId);
                }
            }
        }
    }
    catch (Exception ex)
    {
        //prints the error 
        System.out.println(ex);
    }

    //returns the VLANs got list 
    return listOfPurchasedVlan;
}
Once our ID has been identified we move on to implementing the method to delete our virtual switch:
//IWsEndUser.SetRemoveVLan Method (c# .NET)
private static void RemoveVLan(WsEndUserClient client, int vlanId)
{
    try
    {
        //calls the SetRemoveVLan method, 
        //getting a WsResult object 
        WsResult result = client.SetRemoveVLan(vlanId);

        //if the call fails, the error is relaunched 
        //indicating the message 
        if (!result.Success)
            throw new ApplicationException(result.ResultMessage);
    }
    catch (Exception ex)
    {
        //relaunches the generic error 
        throw new ApplicationException(ex.Message);
    }
}
//IWsEndUser.setRemoveVLan Method (JAVA)
private static void RemoveVLan(IWsEndUser client, int vlanId)
{
    try
    {
        //calls the setRemoveVLan method, 
        //getting a WsResult object 
        WsResult result = client.setRemoveVLan(vlanId);

        //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

Bookmark and Share