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

2.3 Switching a Cloud Server off

How to shut-down a Cloud Server

There are two ways to turn off a computer: setEnqueueServerPowerOff and SetEnqueueServerStop. The difference is that setEnqueueServerPowerOff turn off the server as if take off the power supply, instead setEnqueueServerStop turn it off using the operating system and therefore is recommended.
Using Aruba's WsEndUser SetEnqueueServerStop method you can queue a virtual server shut-down operation (Job) indicated by the parameter serverId. 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 GetServersList(IWsEndUser client)
{
    //a StringBuilder class object is created 
    List sb = new ArrayList();
    
    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 will move on to implement the method to start-up our server:
//IWsEndUser.SetEnqueueServerStop Method (c# .NET)
private static void StopVirtualServer(WsEndUserClient client, int serverId)
{
    try
    {
        //calls the SetEnqueueServerStop method,
        //getting a WsResult object 
        WsResult result = client.SetEnqueueServerStop(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.setEnqueueServerStop Method (JAVA)
private static void StopVirtualServer(IWsEndUser client, int serverId)
{
    try
    {
        //calls the setEnqueueServerStop method, 
        //getting a WsResult object 
        WsResult result = client.setEnqueueServerStop(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);
    }
}
//IWsEndUser.SetEnqueueServerPowerOff Method (c# .NET)
private static void SetEnqueueServerPowerOff(WsEndUserClient client, int serverId)
{
    try
    {
        // call method setEnqueueServerPowerOff 
        // obtaining a WsResult item
        WsResult result = client.SetEnqueueServerPowerOff(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.setEnqueueServerPowerOff Method (JAVA)
private static void setEnqueueServerPowerOff(IWsEndUser client, int serverId)
{
    try
    {
        // call method setEnqueueServerPowerOff 
        // obtaining a WsResult item
        WsResult result = client.setEnqueueServerPowerOff(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().getValue());
        }
    }
    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