From c67aa04291c63aaba6bb9f59b6b331c12036ee9d Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 18 Feb 2016 18:32:16 +0300 Subject: [PATCH] Extract Disk and Space object into separate file --- bareon_dynamic_allocator/allocators.py | 32 +--------------- bareon_dynamic_allocator/objects/__init__.py | 20 ++++++++++ bareon_dynamic_allocator/objects/disk.py | 24 ++++++++++++ bareon_dynamic_allocator/objects/space.py | 39 ++++++++++++++++++++ 4 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 bareon_dynamic_allocator/objects/__init__.py create mode 100644 bareon_dynamic_allocator/objects/disk.py create mode 100644 bareon_dynamic_allocator/objects/space.py diff --git a/bareon_dynamic_allocator/allocators.py b/bareon_dynamic_allocator/allocators.py index 5eb98d9..a16c06f 100644 --- a/bareon_dynamic_allocator/allocators.py +++ b/bareon_dynamic_allocator/allocators.py @@ -18,13 +18,14 @@ import itertools import math import numpy as np -import six from oslo_log import log from scipy.optimize import linprog from termcolor import colored from bareon_dynamic_allocator import errors +from bareon_dynamic_allocator.objects import Disk +from bareon_dynamic_allocator.objects import Space from bareon_dynamic_allocator.parser import Parser from bareon_dynamic_allocator.sequences import CrossSumInequalitySequence @@ -79,35 +80,6 @@ def format_equation(matrix, vector, row_len): return '\n'.join(equation) -class Disk(object): - - def __init__(self, **kwargs): - for k, v in six.iteritems(kwargs): - setattr(self, k, v) - - -class Space(object): - - def __init__(self, **kwargs): - for k, v in six.iteritems(kwargs): - setattr(self, k, v) - - # If no min_size specified set it to 0 - if not kwargs.get('min_size'): - self.min_size = 0 - - # Exact size can be repreneted as min_size and max_size - if kwargs.get('size'): - self.min_size = kwargs.get('size') - self.max_size = kwargs.get('size') - - if not kwargs.get('best_with_disks'): - self.best_with_disks = set([]) - - def __repr__(self): - return str(self.__dict__) - - class DynamicAllocator(object): def __init__(self, hw_info, schema): diff --git a/bareon_dynamic_allocator/objects/__init__.py b/bareon_dynamic_allocator/objects/__init__.py new file mode 100644 index 0000000..d2530e6 --- /dev/null +++ b/bareon_dynamic_allocator/objects/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mirantis, Inc. +# +# 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. + +# flake8: noqa + +from bareon_dynamic_allocator.objects.disk import Disk +from bareon_dynamic_allocator.objects.space import Space diff --git a/bareon_dynamic_allocator/objects/disk.py b/bareon_dynamic_allocator/objects/disk.py new file mode 100644 index 0000000..84b80a1 --- /dev/null +++ b/bareon_dynamic_allocator/objects/disk.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mirantis, Inc. +# +# 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. + +import six + + +class Disk(object): + + def __init__(self, **kwargs): + for k, v in six.iteritems(kwargs): + setattr(self, k, v) diff --git a/bareon_dynamic_allocator/objects/space.py b/bareon_dynamic_allocator/objects/space.py new file mode 100644 index 0000000..cd8f788 --- /dev/null +++ b/bareon_dynamic_allocator/objects/space.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mirantis, Inc. +# +# 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. + +import six + + +class Space(object): + + def __init__(self, **kwargs): + for k, v in six.iteritems(kwargs): + setattr(self, k, v) + + # If no min_size specified set it to 0 + if not kwargs.get('min_size'): + self.min_size = 0 + + # Exact size can be repreneted as min_size and max_size + if kwargs.get('size'): + self.min_size = kwargs.get('size') + self.max_size = kwargs.get('size') + + if not kwargs.get('best_with_disks'): + self.best_with_disks = set([]) + + def __repr__(self): + return str(self.__dict__)