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. ...@@ -31,7 +31,7 @@ Choose a compute node to migrate {{obj}} to.
</label> </label>
<input id="migrate-to-{{n.pk}}" type="radio" name="to_node" value="{{ n.pk }}" style="float: right;" <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 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 %} {% if n.pk not in nodes_w_traits %}
<span class="vm-migrate-node-property"> <span class="vm-migrate-node-property">
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</a> </a>
</li> </li>
<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"> target="blank" class="text-center">
<i class="fa fa-desktop fa-2x"></i><br> <i class="fa fa-desktop fa-2x"></i><br>
{% trans "Virtual Machines" %} {% trans "Virtual Machines" %}
......
...@@ -143,8 +143,13 @@ class NodeDetailView(LoginRequiredMixin, ...@@ -143,8 +143,13 @@ class NodeDetailView(LoginRequiredMixin,
def __remove_trait(self, request): def __remove_trait(self, request):
try: try:
to_remove = request.POST.get('to_remove') to_remove = request.POST.get('to_remove')
self.object = self.get_object() trait = Trait.objects.get(pk=to_remove)
self.object.traits.remove(to_remove) node = self.get_object()
node.traits.remove(to_remove)
if not trait.in_use:
trait.delete()
message = u"Success" message = u"Success"
except: # note this won't really happen except: # note this won't really happen
message = u"Not success" message = u"Not success"
...@@ -155,7 +160,7 @@ class NodeDetailView(LoginRequiredMixin, ...@@ -155,7 +160,7 @@ class NodeDetailView(LoginRequiredMixin,
content_type="application/json" content_type="application/json"
) )
else: else:
return redirect(self.object.get_absolute_url()) return redirect(node.get_absolute_url())
class NodeList(LoginRequiredMixin, GraphMixin, SingleTableView): class NodeList(LoginRequiredMixin, GraphMixin, SingleTableView):
......
...@@ -170,3 +170,10 @@ class Trait(Model): ...@@ -170,3 +170,10 @@ class Trait(Model):
def __unicode__(self): def __unicode__(self):
return self.name 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