2.6.14.2 Python

Importing the Assembly

Importing an assembly into Oracle VM Manager using the REST API only requires you to submit a PUT request to a properly constructed URI. As a result, there is no requirement to build a JSON body for the request, however since there are GET variables passed in the URL, we set these parameters separately to performing URL construction. The following Python code illustrates this:

assembly_url='http://example.com/assemblys/my_assembly.ovf
repo_id=get_id_from_name(s,baseUri,'Repository',"MyRepository")
uri='{base}/Repository/{repoid}/importAssembly'.format(
    base=baseUri,
    repoid=repo_id['value'],
    )
params={'url': assembly_url }
r=s.put(uri,params=params)
job=r.json()
# wait for the job to complete
assembly_id=wait_for_job(job['id']['uri'],s)
Importing a Virtual Machine From an Assembly

Once the assembly has completed its import, it is possible to query the API to obtain the ID values for virtual machines contained within the assembly. An assembly Vm Id is required to import it as a functional virtual machine within your environment. In this example we import all of the virtual machines in the assembly into our environment:

...
r=s.get('{base}/Assembly/{id}'.format(base=baseUri,id=assembly_id['value']))
assembly=r.json()
for i in assembly['assemblyVmIds']:
    uri='{base}/Vm/createFromAssemblyVm/{id}'.format(base=baseUri,id=i['value'])
    r=s.put(uri)
    job=r.json()
    # wait for the job to complete
    wait_for_job(job['id']['uri'],s)    

By sending a GET request to the API first to obtain the full list of details for the assembly that we are working with, we can loop through each of the assemblyVmIds. In this loop, we are able to construct the URI required for the PUT request that must be submitted to trigger the import.