コード例 #1
0
    def move(self, vms, pm):
        # When we move VMs from its original PMs to the new PM, we should remove it from original PM's running set and
        # and add it to the new PM's running set.
        if isinstance(vms, VirtualMachine):
            pre_pm_id = vms.current_pm_id
            if pre_pm_id is not None:
                self.pm_set[pre_pm_id].running_vms.discard(vms)
                if len(self.pm_set[pre_pm_id].running_vms) == 0:
                    self.active_pm_id.discard(pre_pm_id)
                    self.idle_pm_id.add(pre_pm_id)
                    self.pm_set[pre_pm_id] = PhysicalMachine(pre_pm_id, 1000)
            vms.current_pm_id = pm.id
            pm.running_vms.add(vms)
        else:

            for vm in vms:
                pre_pm_id = vm.current_pm_id
                if pre_pm_id is not None:
                    self.pm_set[pre_pm_id].running_vms.discard(vm)
                    if len(self.pm_set[pre_pm_id].running_vms) == 0:
                        self.active_pm_id.discard(pre_pm_id)
                        self.idle_pm_id.add(pre_pm_id)
                        self.pm_set[pre_pm_id] = PhysicalMachine(
                            pre_pm_id, 1000)
                vm.current_pm_id = pm.id
                pm.running_vms.add(vm)
        pm.update()
        self.pm_group_renew()
コード例 #2
0
    def __init__(self, num_pms, num_slots):
        """
        :param num_pms:
        :param num_slots:
        """
        self.num_pms = num_pms
        self.num_slots = num_slots
        self.vm_set = list()
        self.vm_new = list()
        self.pm_set = dict()  # dict[id:pm]
        self.idle_pm_id = set()  # store idle pms
        self.active_pm_id = set()  # store running pms

        # Create PMs
        for i in range(self.num_pms):
            pm_id = i + 1
            pm = PhysicalMachine(pm_id, num_slots=1000)
            self.idle_pm_id.add(pm_id)
            self.pm_set[pm_id] = pm

        # Create PM Category
        pm_category = ['B', 'L', 'LT', 'S', 'SS', 'LS', 'T', 'UT', 'ULLT']
        self.pm_groups = dict()
        for x in pm_category:
            self.pm_groups[x] = set()
コード例 #3
0
    def __init__(self, num_pms, len_slots, ele_price, groups=None):
        """
        :param num_pms: number of PMs
        :param len_slots: T
        :param ele_price: electricity price
        :return: cost
        :type num_pms: int
        :type len_slots: int
        :type ele_price: list[float]
        :type groups: dict[int, Group]
        """

        self.num_pms = num_pms
        self.job_set = {}
        """:type : dict[int, Job]"""

        self.ele_price = ele_price
        if groups is None:
            self.groups = {}
        else:
            self.groups = groups

        self.refined_groups = {}

        self.cur_pm_id = 1
        self.active_pm_id = set()

        from generate_input import L_MIN, L_MAX  # Notice: Must import after calling the function gen_data()!

        self.l_min = L_MIN
        self.l_max = L_MAX

        # Create PMs
        self.pm_set = {}
        for i in range(self.num_pms):
            pm_id = i + 1
            pm = PhysicalMachine(pm_id, num_slots=len_slots)
            self.pm_set[pm_id] = pm

        # Create refined PMs (for virtual allocation)
        self.refined_pm_set = {}
        for i in range(self.num_pms):
            pm_id = i + 1
            refined_pm = PhysicalMachine(pm_id, num_slots=len_slots)
            self.refined_pm_set[pm_id] = refined_pm
コード例 #4
0
 def release(self, pm):
     pm_id = pm.id
     while len(pm.running_vms) != 0:
         vm = pm.running_vms.pop()
         self.fillwith(vm)
     self.active_pm_id.discard(pm_id)
     self.idle_pm_id.add(pm_id)
     # print('{} is released.'.format(pm_id))
     self.pm_set[pm_id] = PhysicalMachine(pm_id, 1000)
     self.pm_group_renew()
コード例 #5
0
    def pm_re_categorize(self):
        # Re-categorize the PM, if the number of VMs running on it is none
        # then remove it from active_pm_id set, add it to idle_pm_id and re-initialize the PM.
        empty_pm_id = set()
        for pm_id in self.active_pm_id:
            if not self.pm_set[pm_id].running_vms:
                empty_pm_id.add(pm_id)

        for pm_id in empty_pm_id:
            self.active_pm_id.discard(pm_id)
            self.idle_pm_id.add(pm_id)
            self.pm_set[pm_id] = PhysicalMachine(pm_id, 1000)

        for pm_id in self.active_pm_id:
            self.pm_set[pm_id].update()
コード例 #6
0
    def pm_group_renew(self):
        # According to the category of each PM, divide active PMs into different groups.
        self.pm_re_categorize()
        for x in self.pm_groups.keys():
            self.pm_groups[x].clear()

        empty_pm_id = set()
        for pm_id in self.active_pm_id:
            pm = self.pm_set[pm_id]
            pm.update()
            if not pm.category:
                empty_pm_id.add(pm.id)
                self.pm_set[pm.id] = PhysicalMachine(pm.id, 1000)

        for pm_id in empty_pm_id:
            self.active_pm_id.discard(pm_id)
            self.idle_pm_id.add(pm_id)

        for pm_id in self.active_pm_id:
            pm = self.pm_set[pm_id]
            self.pm_groups[pm.category].add(pm)
コード例 #7
0
    def __init__(self, num_pms, len_slots, ele_price):
        """
        :param num_pms: num of PMs
        :param len_slots: length of the simulation time
        :param ele_price: electricity price
        :return: cost
        :type num_pms: int
        :type len_slots: int
        :type ele_price: list[float]
        """
        self.num_pms = num_pms
        self.job_set = {}
        self.ele_price = ele_price

        self.cur_pm_id = 1
        self.active_pm_id = set()

        # Create PMs
        self.pm_set = {}
        for i in range(num_pms):
            pm_id = i + 1
            pm = PhysicalMachine(pm_id, num_slots=len_slots)
            self.pm_set[pm_id] = pm