4.2.2 Utilities Paths and Examples

In terms of the REST interface to the Web Services Utilities API, different methods exposed by the API are grouped together based on their functional relationships to Oracle VM Manager to create separate utilities. Each utility has its own relative path beyond the base URI that provides access to the methods that are available for that utility. The relative paths and a description of the utility is provided below:

  • /ArchiveManagement: utility to control the event and job logs housekeeping schedule

  • /BackupManagement: utility to access the Oracle VM Manager backup configuration and to provide the ability to start a backup operation on demand

  • /BusinessManagement: utility that provides tools to extend the functionality provided by the core API

  • /Certificate: utility to manage certificate registration for certificate-based authentication

  • /LogManagement: utility to control runtime selection of which OVM software components (identified by the java package name) can write to the system log file and the level of detail of the messages written.

  • /MacManagement: utility to control how MAC addresses are generated for VNICs

  • /StatisticsManagement: utility to control the statistics configuration, including how often statistics are collected and how long they are stored for

The methods available for each of the utilities is documented fully in the documentation provided with the SDK. The reader is encouraged to refer to this documentation to discover the full range of functionality provided by the Web Services Utilities API.

The Java example source code provided in OvmWsUtilitiesRestClient.java, in the SDK, provides excellent examples of how to access the methods exposed through the REST API using the Jersey Bundle tools. In the highly truncated sample below, it is easy to see that the different utility paths defined above are set as string values that can be combined to construct the correct URI to access each utility:

...
public class OvmWsUtilitiesRestClient extends RestClient implements OvmWsUtilitiesClient
{
    private static final String UTILITIES_PATH             = "Utilities";
    private static final String BUSINESS_MANAGEMENT_PATH   = "BusinessManagement";
    private static final String STATISTICS_MANAGEMENT_PATH = "StatisticsManagement";
    private static final String STATISTICS_ATTRIBUTES_PATH = "StatisticsAttributes";
    private static final String MAC_MANAGEMENT_PATH        = "MacManagement";
    private static final String MAC_ADDRESS_RANGE_PATH     = "MacAddressRange";
    private static final String ARCHIVE_MANAGEMENT_PATH    = "ArchiveManagement";
    private static final String ARCHIVE_ATTRIBUTES_PATH    = "ArchiveAttributes";
    private static final String BACKUP_MANAGEMENT_PATH     = "BackupManagement";
    private static final String BACKUP_ATTRIBUTES_PATH     = "BackupAttributes";
    private static final String LOG_MANAGEMENT_PATH        = "LogManagement";
    private static final String LOG_LOGGERATTRIBUTES_PATH  = "LoggerAttributes";

    private final URI           businessManagementURI;
    private final URI           backupManagementURI;
    private final URI           logManagementURI;

    public OvmWsUtilitiesRestClient(final RestClient parentClient)
    {
        super(parentClient, UTILITIES_PATH);

        businessManagementURI = 
           UriBuilder.fromUri(getBaseURI()).segment(BUSINESS_MANAGEMENT_PATH).build();
        backupManagementURI = 
           UriBuilder.fromUri(getBaseURI()).segment(BACKUP_MANAGEMENT_PATH).build();
        logManagementURI = UriBuilder.fromUri(getBaseURI()).segment(LOG_MANAGEMENT_PATH).build();
    }

    @Override
    public BusinessSelection<EthernetPort> getAvailableEthernetPorts(final Id<Server> 
          serverId, final Id<Network> networkId)
        throws WsException
    {
        try
        {
            final Map<String, Object> queryParameters =
                    createQueryParameterMap("serverId", serverId.getValue(), "networkId", 
                             networkId.getValue());
            final Builder b =
                    getResourceFromUriAndPathElementsWithQueryParameters(businessManagementURI, 
                               queryParameters, "availableEthernetPorts");

            @SuppressWarnings("unchecked")
            final BusinessSelection<EthernetPort> ethernetPorts = b.get(BusinessSelection.class);

            return ethernetPorts;
        }
        catch (final UniformInterfaceException ex)
        {
            throw convertException(ex);
        }
    }
...
}

In the code above, also included, is an example definition for the getAvailableEthernetPorts method. Here you can that since this class extends the RestClient class, it is able to use the getResourceFromUriAndPathElementsWithQueryParameters method in conjunction with the Jersey Builder to submit an HTTP GET request that returns the available Ethernet ports.

According to the documentation provided with the SDK, and extrapolating from the Java code, it should be easy to replicate this example in Python. The sample presented below provides a complete example of the Python code required to construct a similar query:

# import the requests library to handle HTTP requests and session maintenance
import requests
# import the json library for JSON translation (not required for this example)
import json

# instantiate a session object and populate it with authentication credentials
s=requests.Session()
s.auth=('user','password')
s.verify=False #disables SSL certificate verification
# configure the session to always use JSON
s.headers.update({'Accept': 'application/json', 'Content-Type': 'application/json'})

# set up a baseUri object to contain the URI to the Utilities API
baseUri='https://127.0.0.1:7002/ovm/core/wsapi/rest/Utilities'

# construct the URI according to the requirements set out in the documentation
uri='{base}/BusinessManagement/availableEthernetPorts'.format(
    base=baseUri)

# configure the query parameters
params={
    "serverId": "00:e0:81:4d:40:f5:00:e0:81:4d:40:be:00:e0:81:4d",
    "networkId": "0aac4c00"
}

# submit a get request to the uri and store the response
r=s.get(uri,params=params)
# use the requests library's native json parser to obtain a usable python object
availPorts=r.json()