Add formatters, which is required for easier debugging
This commit is contained in:
parent
97193e1522
commit
d48e095b0e
@ -129,7 +129,7 @@ class DynamicAllocationLinearProgram(object):
|
|||||||
spaces_grouped_by_disk = list(grouper(solution.x, len(self.spaces)))
|
spaces_grouped_by_disk = list(grouper(solution.x, len(self.spaces)))
|
||||||
for disk_i in range(len(self.disks)):
|
for disk_i in range(len(self.disks)):
|
||||||
disk_id = self.disks[disk_i].id
|
disk_id = self.disks[disk_i].id
|
||||||
disk = {'disk_id': disk_id, 'spaces': []}
|
disk = {'disk_id': disk_id, 'size': self.disks[disk_i].size, 'spaces': []}
|
||||||
spaces_for_disk = spaces_grouped_by_disk[disk_i]
|
spaces_for_disk = spaces_grouped_by_disk[disk_i]
|
||||||
|
|
||||||
for space_i, space_size in enumerate(spaces_for_disk):
|
for space_i, space_size in enumerate(spaces_for_disk):
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@ -21,6 +19,7 @@ from oslo_log import log
|
|||||||
|
|
||||||
from bareon_dynamic_allocator import utils
|
from bareon_dynamic_allocator import utils
|
||||||
from bareon_dynamic_allocator.allocators import DynamicAllocator
|
from bareon_dynamic_allocator.allocators import DynamicAllocator
|
||||||
|
from bareon_dynamic_allocator import viewer
|
||||||
|
|
||||||
|
|
||||||
cli_opts = [
|
cli_opts = [
|
||||||
@ -75,7 +74,8 @@ def parse_configs(conf):
|
|||||||
|
|
||||||
|
|
||||||
def save_result(data, output_file):
|
def save_result(data, output_file):
|
||||||
pprint(data)
|
viewer.StdoutViewer(data).show_me()
|
||||||
|
viewer.SVGViewer(data).show_me()
|
||||||
|
|
||||||
|
|
||||||
def validate_schema(schema):
|
def validate_schema(schema):
|
||||||
|
86
bareon_dynamic_allocator/viewer.py
Normal file
86
bareon_dynamic_allocator/viewer.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
# Copyright 2015 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 then
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from pprint import pprint
|
||||||
|
import svgwrite
|
||||||
|
from svgwrite import cm, mm
|
||||||
|
|
||||||
|
|
||||||
|
class StdoutViewer(object):
|
||||||
|
|
||||||
|
def __init__(self, disks_spaces_mapping):
|
||||||
|
self.disks_spaces_mapping = disks_spaces_mapping
|
||||||
|
|
||||||
|
def show_me(self):
|
||||||
|
pprint(self.disks_spaces_mapping)
|
||||||
|
|
||||||
|
|
||||||
|
class SVGViewer(object):
|
||||||
|
|
||||||
|
PALETTE = ['#666547', '#fb2e01', '#6fcb9f', '#ffe28a', '#fffeb3']
|
||||||
|
DISK_HEIGHT = 3 * cm
|
||||||
|
SPACE_HEIGHT = 3 * cm
|
||||||
|
WIDTH_MULTIPLIER = 10
|
||||||
|
DISKS_INTERVAL = 150
|
||||||
|
SPACES_X_INTERVAL = 2
|
||||||
|
STYLE = "fill:{color};stroke:black;stroke-width:5;"
|
||||||
|
|
||||||
|
def __init__(self, disks_spaces_mapping, file_path='/tmp/bareon.svg'):
|
||||||
|
self.disks_spaces_mapping = disks_spaces_mapping
|
||||||
|
self.dwg = svgwrite.Drawing(filename=file_path, debug=True)
|
||||||
|
|
||||||
|
def show_me(self):
|
||||||
|
self._add_disk_with_spaces()
|
||||||
|
self.dwg.save()
|
||||||
|
|
||||||
|
def _add_disk_with_spaces(self):
|
||||||
|
disk_g = self.dwg.add(self.dwg.g(id='disks-group', transform="translate({0}, {1})".format(30, 30)))
|
||||||
|
|
||||||
|
for disk_idx, disk_w_spaces in enumerate(self.disks_spaces_mapping):
|
||||||
|
disk_id = disk_w_spaces['disk_id']
|
||||||
|
size = disk_w_spaces['size']
|
||||||
|
|
||||||
|
disk = disk_g.add(self.dwg.g(id=disk_id, transform="translate(0, {0})".format(disk_idx * self.DISKS_INTERVAL)))
|
||||||
|
disk.add(self.dwg.text(text='{0} size={1}'.format(disk_id, size), fill="black"))
|
||||||
|
|
||||||
|
disk_rect = disk.add(self.dwg.g(transform="translate({0}, {1})".format(0, 10), id='in-{0}'.format(disk_id)))
|
||||||
|
disk_rect.add(self.dwg.rect(
|
||||||
|
style=self.STYLE.format(color='#f5f5f5'),
|
||||||
|
ry=5,
|
||||||
|
rx=5,
|
||||||
|
size=(self.WIDTH_MULTIPLIER * disk_w_spaces['size'],
|
||||||
|
self.DISK_HEIGHT)))
|
||||||
|
|
||||||
|
last_insert = [0, 0]
|
||||||
|
for space_idx, space in enumerate(disk_w_spaces['spaces']):
|
||||||
|
palette = self.PALETTE[space_idx % len(self.PALETTE)]
|
||||||
|
disk_rect.add(self.dwg.rect(
|
||||||
|
style=self.STYLE.format(color=palette),
|
||||||
|
ry=5,
|
||||||
|
rx=5,
|
||||||
|
id=space['space_id'],
|
||||||
|
insert=last_insert,
|
||||||
|
size=(self.WIDTH_MULTIPLIER * space['size'], self.SPACE_HEIGHT)))
|
||||||
|
|
||||||
|
last_insert[0] += self.WIDTH_MULTIPLIER * space['size']
|
||||||
|
|
||||||
|
spaces_lines = ['{0} size={1}'.format(space['space_id'], space['size']) for space in disk_w_spaces['spaces']]
|
||||||
|
|
||||||
|
last_insert[0] = self.WIDTH_MULTIPLIER * disk_w_spaces['size']
|
||||||
|
last_insert[0] += 10
|
||||||
|
last_insert[1] += 20
|
||||||
|
for space_idx, space_line in enumerate(spaces_lines):
|
||||||
|
palette = self.PALETTE[space_idx % len(self.PALETTE)]
|
||||||
|
disk_rect.add(self.dwg.text(insert=last_insert, text=space_line, fill=palette))
|
||||||
|
last_insert[1] += 20
|
@ -10,3 +10,4 @@ PyYAML==3.10
|
|||||||
six>=1.5.2
|
six>=1.5.2
|
||||||
scipy
|
scipy
|
||||||
numpy
|
numpy
|
||||||
|
svgwrite
|
||||||
|
Loading…
x
Reference in New Issue
Block a user