Commit 63501e0a by Szabolcs Gelencser

Add initial attached networks implementation

parent 344674c6
......@@ -12,32 +12,17 @@
{% trans "Interfaces" %}
</h2>
{% for i in instance.interface_set.all %}
{% for i in networks %}
<div>
<h3 class="list-group-item-heading dashboard-vm-details-network-h3">
<i class="fa fa-{% if i.host %}globe{% else %}link{% endif %}"></i>
{% if i.vxlan %}
{{ i.vxlan.name }} (user)
{% else %}
{{ i.vlan.name }}
{% if not i.host%}({% trans "unmanaged" %}){% endif %}
{% endif %}
{{ i.name }}
{% if not i.subnets.0.enable_dhcp %}({% trans "unmanaged" %}){% endif %}
{% if user.is_superuser and i.host %}
<a href="{{ i.host.get_absolute_url }}"
class="btn btn-default btn-xs">{% trans "edit" %}</a>
{% endif %}
{% if i.vxlan %}
{% with op=op.remove_user_interface %}{% if op %}
<span class="operation-wrapper">
<a href="{{op.get_url}}?interface={{ i.pk }}"
class="btn btn-{{op.effect}} btn-xs operation interface-remove"
{% if op.disabled %}disabled{% endif %}>{% trans "remove" %}
</a>
</span>
{% endif %}{% endwith %}
{% else %}
{% with op=op.remove_interface %}{% if op %}
<span class="operation-wrapper">
<a href="{{op.get_url}}?interface={{ i.pk }}"
......@@ -46,7 +31,6 @@
</a>
</span>
{% endif %}{% endwith %}
{% endif %}
</h3>
{% if i.host %}
<div class="row">
......
......@@ -387,6 +387,7 @@ class FormOperationMixin(object):
def post(self, request, extra=None, *args, **kwargs):
if extra is None:
extra = {}
self.object = self.get_object()
form = self.form_class(self.request.POST, **self.get_form_kwargs())
if form.is_valid():
extra.update(form.cleaned_data)
......
......@@ -142,6 +142,23 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
activities = openstack_api.nova.instance_action_list(self.request, instance.id)
ports = openstack_api.neutron.port_list(self.request)
instance_net_ids = [p.network_id for p in ports if p.device_id == self.object.id]
all_networks = openstack_api.neutron.network_list(self.request)
instance_networks = [n for n in all_networks if n.id in instance_net_ids and len(n.subnets) > 0]
router_ports = [p for p in ports if p.device_owner == 'network:router_interface']
routers = openstack_api.neutron.router_list(self.request)
router_by_id = {r.id: r for r in routers}
for n in instance_networks:
n.subnet = n.subnets[0]
#TODO: mark network public if it is based on router ports and router
context['networks'] = instance_networks
# context['vlans'] = Vlan.get_objects_with_level(
# 'user', self.request.user
# ).exclude( # exclude already added interfaces
......
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