Commit f200db6e authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Create NIC before send job to Ganeti

Create NICs in building state before enqueuing corresponding jobs to
Ganeti. This has already been done when creating the instance, but not
when connecting it to other networks.
parent 2ba950f7
......@@ -742,7 +742,8 @@ def disconnect_network(network, backend, group=None):
return job_ids
def connect_to_network(vm, network, address=None):
def connect_to_network(vm, nic):
network = nic.network
backend = vm.backend
network = Network.objects.select_for_update().get(id=network.id)
bnet, created = BackendNetwork.objects.get_or_create(backend=backend,
......@@ -753,9 +754,9 @@ def connect_to_network(vm, network, address=None):
depends = [[job, ["success", "error", "canceled"]] for job in depend_jobs]
nic = {'ip': address, 'network': network.backend_id}
nic = {'ip': nic.ipv4, 'network': network.backend_id}
log.debug("Connecting vm %s to network %s(%s)", vm, network, address)
log.debug("Connecting NIC %s to VM %s", nic, vm)
kwargs = {
"instance": vm.backend_vm_id,
......
......@@ -358,7 +358,12 @@ def connect(vm, network):
log.info("Connecting VM %s to Network %s(%s)", vm, network, address)
return backend.connect_to_network(vm, network, address)
nic = NetworkInterface.objects.create(machine=vm,
network=network,
ipv4=address,
state="BUILDING")
return backend.connect_to_network(vm, nic)
@server_command("DISCONNECT")
......@@ -434,8 +439,13 @@ def console(vm, console_type):
@server_command("CONNECT")
def add_floating_ip(vm, address):
floating_ip = add_floating_ip_to_vm(vm, address)
log.info("Connecting VM %s to floating IP %s", vm, floating_ip)
return backend.connect_to_network(vm, floating_ip.network, address)
nic = NetworkInterface.objects.create(machine=vm,
network=floating_ip.network,
ipv4=floating_ip.ipv4,
state="BUILDING")
log.info("Connecting VM %s to floating IP %s. NIC: %s", vm, floating_ip,
nic)
return backend.connect_to_network(vm, nic)
def add_floating_ip_to_vm(vm, address):
......
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