gc3libs.backends.vmpool

exception gc3libs.backends.vmpool.InstanceNotFound(msg, do_log=False)

Specified instance was not found

class gc3libs.backends.vmpool.VMPool(path, connection)

Persistable container for a list of VM objects.

Holds a list of all VM IDs of inserted VMs, and a cache of the actual VM objects. If information about a VM is requested, which is not currently in the cache, a request is made to the cloud provider API (through the conn object passed to the constructor) to get that information.

The VMPool looks like a mixture of the set and dict interfaces:

  • VMs are added to the container using the add_vm method:

    | >>> vmpool.add_vm(vm1)
    

    (There is no dictionary-like D[x]=y setter syntax, though, as that would require spelling out the VM ID.)

  • VMs can be removed via the remove_vm method or the del syntax; in both cases it’s the VM ID that must be passed:

    | >>> vmpool.remove_vm(vm1)
    
    | >>> del vmpool[vm1]
    
  • Iterating over a VMPool instance returns the VM IDs.

  • Other sequence methods work as expected: the VM info can be accessed with the usual [] lookup syntax from its ID, the len() of a VMPool object is the total number of VM IDs registered, etc..

VMPool objects can be persisted using the `gc3libs.persistence`:module: framework. Note however that the VM cache will be empty upon loading a VMPool instance from persistent storage.

add_vm(vm, cache=True)

Add a VM object to the list of VMs.

get_all_vms()

Return list of all known VMs.

get_vm(vm_id, force_reload=False)

Return the VM object with id vm_id.

If it is found in the local cache, that object is returned. Otherwise a new VM object is searched for in the EC2 endpoint.

load()

Populate list of VM IDs from the data saved on disk.

remove_vm(vm_id)

Remove VM with id vm_id from the list of known VMs. No connection to the EC2 endpoint is performed.

save()

Ensure all VM IDs will be found by the next load() call.

update(remove=False)

Synchronize list of VM IDs with contents of disk storage.

If optional argument remove is true, then remove VMs whose ID is no longer present in the on-disk storage.