Radomir Dopieralski 05e505c5c6 Sexy boxes drag and drop
The plan edit page is modified to show the flavors with a visualisation
of the nodes. Roles can be dragged and dropped on the flavors.

TODO: actually save the flavor for a role in the form
TODO: add a popup for adding the roles to flavors

Change-Id: I9b97f39e3800b5b6c2e5639fcfd186b4196d0190
2014-10-03 14:06:28 +02:00

52 lines
1.9 KiB
Python

# -*- coding: utf8 -*-
#
# 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 tuskar_ui import api
from tuskar_ui.infrastructure.overview import views
def flavor_nodes(request, flavor):
"""Lists all nodes that match the given flavor exactly."""
for node in api.node.Node.list(request):
if all([
int(node.cpus) == int(flavor.vcpus),
int(node.memory_mb) == int(flavor.ram),
int(node.local_gb) == int(flavor.disk),
# TODO(rdopieralski) add architecture when available
]):
yield node
class IndexView(views.IndexView):
template_name = "tuskar_boxes/overview/index.html"
def get_context_data(self, *args, **kwargs):
context = super(IndexView, self).get_context_data(*args, **kwargs)
flavors = api.flavor.Flavor.list(self.request)
flavors.sort(key=lambda np: (np.vcpus, np.ram, np.disk))
context['flavors'] = []
for flavor in flavors:
nodes = [{
'role': '',
} for node in flavor_nodes(self.request, flavor)]
flavor = {
'name': flavor.name,
'vcpus': flavor.vcpus,
'ram': flavor.ram,
'disk': flavor.disk,
'nodes': nodes,
}
if nodes: # Don't list empty flavors
context['flavors'].append(flavor)
return context