1.2.3 Resources in use

The VirtualDatacenter class contains information on the virtual datacenter associated with the account specified.

A VirtualDatacenter class object specifically exposes the following elements:
  • IPAddress class objects list
  • VLAN class objects list
  • ServerDetail list
In the following example a method called GetVirtualDataCenterDetails is described which gets a list of VirtualDataCenter class objects by making a call to Aruba's WsEndUser GetVirtualDatacenter method.

By analysing this object you can get the IpAddress list, the ServerDetails list and the VLAN list that the datacenter linked to your email account comprises. In the specific example the list of active servers is searched. For each of these servers the amount of RAM and number of CPUs available is extracted.
//IWsEndUser.GetVirtualDatacenter Method (c# .NET)
public static String GetVirtualDataCenterDetails(WsEndUserClient client)
{
    StringBuilder sb = new StringBuilder();

    try
    {
        //calls the GetVirtualDatacentermethod,
        //getting a WsResultOfVirtualDatacenter object 
        WsResultOfVirtualDatacenter result = client.GetVirtualDatacenter();

        if (result.Success)
        {
            //get running server list
            IEnumerable serverAttivi = result.Value.Servers
                .Where(p => p.ServerStatus == ServerStatus.Running);

            foreach (ServerDetails serverDtl in serverAttivi)
            {

                sb.AppendLine(String.Format("{0}: {1} GB RAM - {2} CPU",
                    serverDtl.Name,
                    serverDtl.RAMQuantity.Quantity,
                    serverDtl.CPUQuantity.Quantity));
            }
        }
        else
        {
            throw new ApplicationException(result.ResultMessage);
        }
    }
    catch (Exception ex)
    {
        //relaunches the generic error 
        throw new ApplicationException(ex.Message);
    }

    return sb.ToString();
}
//IWsEndUser.getVirtualDatacenter Method (JAVA)
public static String GetVirtualDataCenterDetails(IWsEndUser client)
{

    StringBuilder sb = new StringBuilder();

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

        if (result.isSuccess())
        {                       
            //show server information
            for (ServerDetails serverDtl : 
                    result.getValue().getServers().getServerDetails())
            {
                if (serverDtl.getServerStatus() == ServerStatus.RUNNING)
                {

                    Formatter formatter = new Formatter ();    
                    formatter.format("{%s}: {%d} GB RAM - {%d} CPU", 
                            serverDtl.getName(), 
                            serverDtl.getRAMQuantity().getQuantity(),
                            serverDtl.getCPUQuantity().getQuantity());


                    sb.append(formatter.toString());
                }
            }
        }
        else
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (Exception ex)
    {
        //print the error
        System.out.println(ex);
    }

    return sb.toString();
}
Through the call to the GetVirtualDatacenterCost method you can find out the details of the costs for every single component of the virtual datacenter.
//IWsEndUser.GetVirtualDatacenterCost Method (c# .NET)
private String GetDataCenterCost(WsEndUserClient client)
{
    //a StringBuilder class object is created 
    StringBuilder sb = new StringBuilder();

    try
    {
        //calls the virtualDataCenterCost method, 
        //getting a WsResultOfCredit object 
        WsResultOfVirtualDatacenterCost result = client.GetVirtualDatacenterCost();

        //checks that the call to the method was successful  
        if (result.Success)
        {
            //gets the costs of the server's components 
            foreach (ServerCost serverCosts in result.Value.ServerCost)
            {
                sb.AppendLine("Resources hourly cost for ServerId " + serverCosts.ServerId);
                sb.AppendLine("- RAM: " + serverCosts.RamCost.TotalHourlyCost);
                sb.AppendLine("- OS Template: " + serverCosts.OSTemplateCost.TotalHourlyCost);
                sb.AppendLine("- Disks: " + serverCosts.VirtualDiskCost.TotalHourlyCost);
                sb.AppendLine("- CPU: " + serverCosts.CpuCost.TotalHourlyCost);
                sb.AppendLine("-------------------------------");
                sb.AppendLine("TOTAL (per hour): " + serverCosts.TotalHourlyCost);
            }
        }
        else
        {
            throw new ApplicationException(result.ResultMessage);
        }
    }
    catch (Exception ex)
    {
        //relaunches the generic error 
        throw new ApplicationException(ex.Message);
    }
    return sb.ToString();
}
//IWsEndUser.getVirtualDatacenterCost Method (JAVA)
private static String GetDataCenterCost(IWsEndUser client)
{
    //a StringBuilder class object is created  
    StringBuilder sb = new StringBuilder();

    try
    {
        //calls the getVirtualDatacenterCost method, 
        //getting a WsResultOfCredit object  
        WsResultOfVirtualDatacenterCost result = client.getVirtualDatacenterCost();

        //checks that the call to the method was successful  
        if (result.isSuccess())
        {
            //retrieves the list of costs associated with the virtual servers
            //and gets the costs of the server's components  
            for (ServerCost serverCosts : 
                    result.getValue().getServerCost().getServerCost())
            {
                sb.append("Resources hourly cost for ServerId ")
                        .append(serverCosts.getServerId());
                sb.append("- RAM: ").append(serverCosts.getRamCost()
                        .getTotalHourlyCost());
                sb.append("- OS Template: ").append(serverCosts
                        .getOSTemplateCost().getTotalHourlyCost());
                sb.append("- Disks: " ).append(serverCosts
                        .getVirtualDiskCost().getTotalHourlyCost());
                sb.append("- CPU: ").append(serverCosts
                        .getCpuCost().getTotalHourlyCost());
                sb.append("-------------------------------");
                sb.append("TOTAL (per hour): ")
                        .append(serverCosts.getTotalHourlyCost());
            }
        }
        else
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (Exception ex)
    {
        //prints the generic error 
        System.out.println(ex);
    }
    return sb.toString();
}

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