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

2.2 Switching a Cloud Server on

How to start up a Cloud Server

Using Aruba's WsEndUser SetEnqueueServerStart method you can queue a virtual server start-up 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<Server> 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 implementing the method to start-up our server:
//IWsEndUser.SetEnqueueServerStart Method (c# .NET)
private static void StartupVirtualServer(WsEndUserClient client, int serverId)
{
    try
    {
        //calls the SetEnqueueServerStart method, 
        //getting a WsResult object 
        WsResult result = client.SetEnqueueServerStart(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.setEnqueueServerStart Method (JAVA)
private static void StartupVirtualServer(IWsEndUser client, int serverId)
{
    try
    {
        //calls the setEnqueueServerStart method, 
        //getting a WsResult object 
        WsResult result = client.setEnqueueServerStart(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