Added a vm_placement package and bin_packing module

This commit is contained in:
Anton Beloglazov 2012-09-20 12:32:14 +10:00
parent d0f1b62a8d
commit f3ce42d0d1
4 changed files with 110 additions and 0 deletions

View File

View File

@ -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

View File

View File

@ -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