Commit bab77516 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Simplify disconnecting vm from network

Use the new option of Ganeti, to remove a specific nic.
parent ee507bae
......@@ -38,8 +38,7 @@ from logging import getLogger
from django.conf import settings
from django.db import transaction
from synnefo.db.models import (VirtualMachine, Network, NetworkInterface,
from synnefo.db.models import (VirtualMachine, Network, NetworkLink)
from synnefo.logic import utils
from synnefo.util.rapi import GanetiRapiClient
......@@ -268,9 +267,9 @@ def create_instance(vm, flavor, image, password, personality):
'img_format': image['format']}
if personality:
kw['osparams']['img_personality'] = json.dumps(personality)
kw['osparams']['img_properties'] = json.dumps(image['metadata'])
# kw['hvparams'] = dict(serial_console=False)
......@@ -388,22 +387,16 @@ def delete_network(net):
def connect_to_network(vm, net):
nic = {'mode': 'bridged', 'link':}
nics=[('add', nic)],
rapi.ModifyInstance(vm.backend_id, nics=[('add', nic)],
def disconnect_from_network(vm, net):
nics = vm.nics.filter(network__public=False).order_by('index')
new_nics = [nic for nic in nics if != net]
if new_nics == nics:
return # Nothing to remove
ops = [('remove', {})]
for i, nic in enumerate(new_nics):
ops.append((i + 1, {
'mode': 'bridged',
rapi.ModifyInstance(vm.backend_id, nics=ops, dry_run=settings.TEST)
ops = [('remove', nic.index, {}) for nic in nics if == net]
if not ops: # Vm not connected to network
rapi.ModifyInstance(vm.backend_id, nics=ops[::-1], dry_run=settings.TEST)
def set_firewall_profile(vm, profile):
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 to comment