diff --git a/neat/globals/vm_placement/__init__.py b/neat/globals/vm_placement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/neat/globals/vm_placement/bin_packing.py b/neat/globals/vm_placement/bin_packing.py new file mode 100644 index 0000000..b002edd --- /dev/null +++ b/neat/globals/vm_placement/bin_packing.py @@ -0,0 +1,61 @@ +# Copyright 2012 Anton Beloglazov +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" Bin Packing based VM placement algorithms. +""" + +from contracts import contract +from neat.contracts_extra import * + + +@contract +def best_fit_decreasing_factory(time_step, migration_time, params): + """ Creates the Best Fit Decreasing (BFD) heuristic for placing VMs on hosts. + + :param time_step: The length of the simulation time step in seconds. + :type time_step: int,>=0 + + :param migration_time: The VM migration time in time seconds. + :type migration_time: int,>=0 + + :param params: A dictionary containing the algorithm's parameters. + :type params: dict(str: *) + + :return: A function implementing the BFD algorithm. + :rtype: function + """ + return lambda hosts_cpu, hosts_ram, vms_cpu, vms_ram, state=None: \ + (best_fit_decreasing(hosts_cpu, hosts_ram, vms_cpu, vms_ram), {}) + + +@contract +def best_fit_decreasing(hosts_cpu, hosts_ram, vms_cpu, vms_ram): + """ The Best Fit Decreasing (BFD) heuristic for placing VMs on hosts. + + :param hosts_cpu: A map of host names and their available CPU frequency in MHz. + :type hosts_cpu: dict(str: int) + + :param hosts_ram: A map of host names and their available RAM capacity in MB. + :type hosts_ram: dict(str: number) + + :param vms_cpu: A map of VM UUID and their CPU utilization in MHz. + :type vms_cpu: dict(str: float) + + :param vms_ram: A map of VM UUID and their RAM usage in MB. + :type vms_ram: dict(str: number) + + :return: A map of VM UUIDs to host names. + :rtype: str + """ + pass diff --git a/tests/globals/vm_placement/__init__.py b/tests/globals/vm_placement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/globals/vm_placement/test_bin_packing.py b/tests/globals/vm_placement/test_bin_packing.py new file mode 100644 index 0000000..2022195 --- /dev/null +++ b/tests/globals/vm_placement/test_bin_packing.py @@ -0,0 +1,49 @@ +# Copyright 2012 Anton Beloglazov +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from mocktest import * +from pyqcy import * + +import neat.globals.vm_placement.bin_packing as algs + + +class BinPacking(TestCase): + + pass + # @qc(10) + # def minimum_migration_time_factory( + # x=dict_( + # keys=str_(of='abc123-', min_length=36, max_length=36), + # values=int_(min=0, max=3000), + # min_length=1, max_length=5 + # ) + # ): + # alg = selection.minimum_migration_time_factory(300, 20, dict()) + # values = x.values() + # vm_index = values.index(min(values)) + # vm = x.keys()[vm_index] + # assert alg(dict(), x) == (vm, {}) + + # @qc(10) + # def minimum_migration_time( + # x=dict_( + # keys=str_(of='abc123-', min_length=36, max_length=36), + # values=int_(min=0, max=3000), + # min_length=1, max_length=5 + # ) + # ): + # values = x.values() + # vm_index = values.index(min(values)) + # vm = x.keys()[vm_index] + # assert selection.minimum_migration_time(x) == vm