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,
NetworkLink)
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'])
# Defined in settings.GANETI_CREATEINSTANCE_KWARGS
# kw['hvparams'] = dict(serial_console=False)
......@@ -388,22 +387,16 @@ def delete_network(net):
def connect_to_network(vm, net):
nic = {'mode': 'bridged', 'link': net.link.name}
rapi.ModifyInstance(vm.backend_id,
nics=[('add', nic)],
dry_run=settings.TEST)
rapi.ModifyInstance(vm.backend_id, nics=[('add', nic)],
dry_run=settings.TEST)
def disconnect_from_network(vm, net):
nics = vm.nics.filter(network__public=False).order_by('index')
new_nics = [nic for nic in nics if nic.network != net]
if new_nics == nics:
return # Nothing to remove
ops = [('remove', {})]
for i, nic in enumerate(new_nics):
ops.append((i + 1, {
'mode': 'bridged',
'link': nic.network.link.name}))
rapi.ModifyInstance(vm.backend_id, nics=ops, dry_run=settings.TEST)
ops = [('remove', nic.index, {}) for nic in nics if nic.network == net]
if not ops: # Vm not connected to network
return
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