Commit 7c5eae88 by Kálmán Viktor

dashboard: node/trait fix

- use node_exact on vmlist (mega1 vs mega10)
- remove trait object if there is no more reference to it
parent f4df866a
......@@ -31,7 +31,7 @@ Choose a compute node to migrate {{obj}} to.
</label>
<input id="migrate-to-{{n.pk}}" type="radio" name="to_node" value="{{ n.pk }}" style="float: right;"
{% if current == n.pk %}disabled="disabled"{% endif %}
{% if recommended == n.pk %}checked="checked"{% endif %}
{% if recommended == n.pk and n.pk != current %}checked="checked"{% endif %}
/>
{% if n.pk not in nodes_w_traits %}
<span class="vm-migrate-node-property">
......
......@@ -73,7 +73,7 @@
</a>
</li>
<li>
<a href="{% url "dashboard.views.vm-list" %}?s=node:{{ node.name }}"
<a href="{% url "dashboard.views.vm-list" %}?s=node_exact:{{ node.name }}"
target="blank" class="text-center">
<i class="fa fa-desktop fa-2x"></i><br>
{% trans "Virtual Machines" %}
......
......@@ -143,8 +143,13 @@ class NodeDetailView(LoginRequiredMixin,
def __remove_trait(self, request):
try:
to_remove = request.POST.get('to_remove')
self.object = self.get_object()
self.object.traits.remove(to_remove)
trait = Trait.objects.get(pk=to_remove)
node = self.get_object()
node.traits.remove(to_remove)
if not trait.in_use:
trait.delete()
message = u"Success"
except: # note this won't really happen
message = u"Not success"
......@@ -155,7 +160,7 @@ class NodeDetailView(LoginRequiredMixin,
content_type="application/json"
)
else:
return redirect(self.object.get_absolute_url())
return redirect(node.get_absolute_url())
class NodeList(LoginRequiredMixin, GraphMixin, SingleTableView):
......
......@@ -170,3 +170,10 @@ class Trait(Model):
def __unicode__(self):
return self.name
@property
def in_use(self):
return (
self.instance_set.exists() or self.node_set.exists()
or self.instancetemplate_set.exists()
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment