A lease admission policy module looks like this:
from haizea.core.scheduler.policy import LeaseAdmissionPolicy class MyPolicy(LeaseAdmissionPolicy): def __init__(self, slottable): LeaseAdmissionPolicy.__init__(self, slottable) def accept_lease(self, lease): # Your code goes here
The accept_lease method receives a Lease object, and must return True if the lease can be accepted, and False if it should be rejected. You can also add code to the constructor, but cannot alter its parameter list. Haizea includes some built-in admission policies that you can see in src/haizea/policies/admission.py
The lease admission policy that Haizea must use is specified using the policy-admission option of the [scheduling] section in the configuration file. So, assuming you save your module as policies.py, you would specify the following in the configuration file:
[scheduling] ... policy-admission: policies.MyPolicy ...
For this to work, you have to make sure that the policies.py module you created is in your PYTHONPATH when you start Haizea.
For example, let's suppose we want to write an admission policy that, as described earlier, will reject AR leases that are not requested at least one hour in advance. This policy module would look like this:
from haizea.core.scheduler.policy import LeaseAdmissionPolicy from haizea.core.leases import Lease from haizea.common.utils import get_clock from mx.DateTime import TimeDelta class MyPolicy(LeaseAdmissionPolicy): def __init__(self, slottable): LeaseAdmissionPolicy.__init__(self, slottable) def accept_lease(self, lease): allowed = TimeDelta(hours=1) now = get_clock().get_time() if lease.get_type() == Lease.ADVANCE_RESERVATION: if lease.start.requested - now <= allowed: return False return True
Save this file as policies.py, make sure the directory it's in is in your PYTHONPATH, and set [scheduling].policy-admission to policies.MyPolicy in the configuration file. If you rerun the example from the quickstart guide, instead of seeing this:
[2006-11-25 13:15:00.00] LSCHED Lease #2 has been requested. [2006-11-25 13:15:00.00] LSCHED Lease #2 has been marked as pending.
You will see that the AR lease, which is requested 15 minutes before it starts, is rejected:
[2006-11-25 13:15:00.00] LSCHED Lease #2 has been requested. [2006-11-25 13:15:00.00] LSCHED Lease #2 has not been accepted
In fact, if you modify the starting time to be the following:
<start> <exact time="02:00:00"/> </start>
The lease will be accepted again, although it will start later than before:
[2006-11-25 15:00:00.00] VMSCHED Started VMs for lease 2 on nodes [1, 2, 3, 4] [2006-11-25 15:30:00.00] VMSCHED Stopped VMs for lease 2 on nodes [1, 2, 3, 4]
Borja Sotomayor 2009-12-17