virtualbox.pool
– machine pool management¶
Virtual Machine pool¶
The MachinePool
manages a pool of linked clones against a defined
“root machine”. This module works with multiple processes running on the
host machine at a time. It manages a resource lock over the root virtual
machine to ensure consistency.
In this example the machine win7 has a current version of guest editions installed and is in a powered off state.
Create multiple clones:
pool = MachinePool('win7')
sessions = []
for i in range(3):
sessions.append(pool.acquire("Mick", "password"))
# You now have three running machines.
for session in sessions:
with session.guest.create_session("Mick", "password") as gs:
_, out, _ = gs.execute("ipconfig")
print(out)
for session in sessions:
pool.release(session)
A reliable version of the above code would look like this:
pool = MachinePool('win7')
sessions = []
try:
for i in range(3):
sessions.append(pool.acquire("Mick", "password"))
# You now have three running machines.
for session in sessions:
with session.guest.create_session("Mick", "password") as gs:
_, out, _ = gs.execute("ipconfig")
print(out)
finally:
for session in sessions:
try:
pool.release(session)
except Exception as err:
print("Error raised on release: %s" % err)