2.6.14.1 Java

Importing the Assembly

The WsDevClient class contains the following code to handle the assembly import:

...
final Job importAssemblyJob = api.repositoryImportAssembly(testRepoId, assemblyUrl);
System.out.println("import assembly job id: " + importAssemblyJob.getId());
testAssemblyId = waitForJobComplete(api, importAssemblyJob, Assembly.class); 

The assemblyUrl is defined in the WsDevClient.properties file. The URL must point to a valid assembly package that Oracle VM Manager can access and download. The repositoryImportAssembly method uses two more generic methods defined in the OvmWsRestClient class to construct the URI and then to submit the PUT request using the Jersey Builder:

@Override
    public Job repositoryImportAssembly(final Id<Repository> repositoryId, final String url) 
        throws WsException
    {
        final Map<String, Object> params = createQueryParameterMap("url", url);
        return actionWithQueryParameters(repositoryId, "importAssembly", params, null);
    }

Action requests that contain query parameters within the URI are constructed and submitted using the actionWithQueryParameters method in the RestClient class, described previously.

Importing a Virtual Machine From An Assembly

After the assembly has been imported into Oracle VM Manager you may want to import a virtual machine from within the assembly into your environment. First, you need to obtain the assemblyVm ID for the virtual machine that you want to import. For this, the WsDevClient class includes the following code to loop over the Vm ID's within the assembly. The code is simple and selects the first ID that it detects in the loop.

assemblyVms = api.assemblyVmGetListById(assembly.getAssemblyVmIds());
Id<AssemblyVm> testAssemblyVmId = null;
for (final AssemblyVm assemblyVm : assemblyVms)
{
    if (testAssemblyVmId == null)
    {
        testAssemblyVmId = assemblyVm.getId();
    }

Once an assemblyVmId has been set, the vmCreateFromAssemblyVm method can be called from OvmWsRestClient:

if (testAssemblyVmId != null)
{
    final Job importVmFromAssemblyJob = api.vmCreateFromAssemblyVm(testAssemblyVmId);
    System.out.println("import vm from assembly job id: " + importVmFromAssemblyJob.getId());
    importedAssemblyVmId = waitForJobComplete(api, importVmFromAssemblyJob, Vm.class);
} 

Although this is an action request that functions through a PUT request, the URI construction is different to the format that we used when importing the assembly into Oracle VM Manager. For this reason, the vmCreateFromAssemblyVm method does not rely on a more generic method to construct the request:

public Job vmCreateFromAssemblyVm(final Id<AssemblyVm> assemblyVmId) 
             throws WsException
{
    try
    {
        final Builder b = getResourceFromPathElements(Vm.class.getSimpleName(), 
                    "createFromAssemblyVm", assemblyVmId.getValue());
        final Job job = b.put(Job.class);
        return job;
    }
    catch (final UniformInterfaceException ex)
    {
       throw convertException(ex);
    }
}