Skip to content

The basics

nacx edited this page May 25, 2012 · 5 revisions

The jclouds-abiquo API uses high-level domain objects to perform the operations against the Abiquo API. This domain objects provide all necessary functionaliry to avoid consuming directly the REST api, although it can be used if needed.

Creating the context

The first thing to do to use the jclouds-abiquo API is to create the context that will point to the API endpoint. This can be done using the ContextBuilder:

AbiquoContext context = ContextBuilder.newBuilder(new AbiquoApiMetadata())
    .endpoint("http://localhost/api")
    .credentials("user", "password")
    .build(AbiquoContext.class);

Using the domain objects to perform operations

Once the context has been created, you can use the Builders to build the domain objects. Then, those domain objects can be used to perform the desired operations:

Datacenter datacenter = Datacenter.builder(context.getApiContext())
    .name("Datacenter")
    .location("Honolulu")
    .build();

// Create the datacenter
datacenter.save()

// Modify the name of the datacenter
datacenter.setName("Updated Datacenter");
datacenter.update();

// Delete the datacenter        
datacenter.delete();

Using the services to list and filter information

Some operations are not directly mapped to domain objects. In that case, a high level service is provided to perform them. Services can be obtained from the context and used as shown in the following example:

AdministrationService administration = context.getAdministrationService();

// Get the list of all datacenters
administration.listDatacenters();

// Get the list of all datacenters with the given name
administration.listDatacenters(DatacenterPredicates.name("Updated Datacenter"));

// Get the first datacenter that has the given name        
administration.findDatacenter(DatacenterPredicates.name("Updated Datacenter"));

A more complete example

This more complete example shows how regular operations can be done using jclouds-abiquo. It is important to note that the context must be closed when finishing, so the used resources can be released.

AbiquoContext context = ContextBuilder.newBuilder(new AbiquoApiMetadata())
    .endpoint("http://localhost/api")
    .credentials("user", "password")
    .build(AbiquoContext.class);
AdministrationService administration = context.getAdministrationService();

try
{
    Datacenter datacenter = administration.findDatacenter(DatacenterPredicates.name("Datacenter"));
    datacenter.setName("Updated Datacenter");
    datacenter.update();
}
finally
{
   context.close();
}

You can also take a look at the live project to see how live integration tests use the API.

Back to Home