From 6c93495f155d51b24d35c1ea0d61a5012e85943b Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Tue, 3 May 2011 11:16:08 +0200 Subject: [PATCH] Enhanced elector to allow elections for hot migration. Note: Memory filter is currently hard-disabled because node needs a better method to provide this value. --- ccserver/election.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ccserver/election.py b/ccserver/election.py index 4ed0882..3431746 100644 --- a/ccserver/election.py +++ b/ccserver/election.py @@ -34,10 +34,21 @@ class Elector(object): ('has_alloc', 'filter allocatable hv'), ('duplicate_name', 'filter vm duplicate names'), ('enough_disk', 'filter hv with not enough disk'),), + + 'hot': (('is_hv', 'filter r=hv'), + ('not_source_hv', 'filter source hv'), + ('is_connected', 'filter connected hv'), + ('vm_htype_eq_hv', 'filter bad hv types'), + ('has_rights', 'filter rights'), + ('has_alloc', 'filter allocatable hv'), + ('duplicate_name', 'filter vm duplicate names'), + #('enough_ram', 'filter hv with not enough ram'), + ('enough_disk', 'filter hv with not enough disk'),), } # Available algos for each types: - ALGO_BY_TYPES = {'cold': ('fair', )} + ALGO_BY_TYPES = {'cold': ('fair', ), + 'hot': ('fair', )} def __init__(self, server, query_vm, query_dest, login): # The server instance for this election: @@ -78,7 +89,7 @@ class Elector(object): candidates = self._get_candidates(self.FILTERS[mtype]) # Distributes VMs to each candidate: - migration_plan = distribute(candidates) + migration_plan = distribute(mtype, candidates) # Return the migration plan: return migration_plan @@ -118,7 +129,7 @@ class Elector(object): ##### Distribution algorithm methods: ##### - def _algo_fair(self, candidates): + def _algo_fair(self, mtype, candidates): migration_plan = [] # Sort vm by number of destination hv: @@ -140,7 +151,7 @@ class Elector(object): hv = min(hvs, key=lambda x: hv_alloc[x['id']]) migration_plan.append({'sid': vm['id'], 'did': hv['id'], - 'type': 'cold'}) + 'type': mtype}) hv_alloc[hv['id']] = hv_alloc.get(hv['id'], 0) + 1 return migration_plan -- GitLab