Commit 6278f2fc by Bach Dániel

Merge branch 'feature-vm-ipv6' into 'master'

Feature Vm Ipv6
parents af05a3bd 06519506
...@@ -215,7 +215,7 @@ class Rule(models.Model): ...@@ -215,7 +215,7 @@ class Rule(models.Model):
dst = None dst = None
if host: if host:
ip = (host.ipv4, host.ipv6_with_prefixlen) ip = (host.ipv4, host.ipv6_with_host_prefixlen)
if self.direction == 'in': if self.direction == 'in':
dst = ip dst = ip
else: else:
...@@ -530,14 +530,30 @@ class Host(models.Model): ...@@ -530,14 +530,30 @@ class Host(models.Model):
def incoming_rules(self): def incoming_rules(self):
return self.rules.filter(direction='in') return self.rules.filter(direction='in')
@property @staticmethod
def ipv6_with_prefixlen(self): def create_ipnetwork(ip, prefixlen):
try: try:
net = IPNetwork(self.ipv6) net = IPNetwork(ip)
net.prefixlen = self.vlan.host_ipv6_prefixlen net.prefixlen = prefixlen
return net
except TypeError: except TypeError:
return None return None
else:
return net
@property
def ipv4_with_vlan_prefixlen(self):
return Host.create_ipnetwork(
self.ipv4, self.vlan.network4.prefixlen)
@property
def ipv6_with_vlan_prefixlen(self):
return Host.create_ipnetwork(
self.ipv6, self.vlan.network6.prefixlen)
@property
def ipv6_with_host_prefixlen(self):
return Host.create_ipnetwork(
self.ipv6, self.vlan.host_ipv6_prefixlen)
def get_external_ipv4(self): def get_external_ipv4(self):
return self.external_ipv4 if self.external_ipv4 else self.ipv4 return self.external_ipv4 if self.external_ipv4 else self.ipv4
...@@ -600,6 +616,19 @@ class Host(models.Model): ...@@ -600,6 +616,19 @@ class Host(models.Model):
description='created by host.save()', description='created by host.save()',
type='AAAA').save() type='AAAA').save()
def get_network_config(self):
interface = {'addresses': []}
if self.ipv4 and self.vlan.network4:
interface['addresses'].append(str(self.ipv4_with_vlan_prefixlen))
interface['gw4'] = str(self.vlan.network4.ip)
if self.ipv6 and self.vlan.network6:
interface['addresses'].append(str(self.ipv6_with_vlan_prefixlen))
interface['gw6'] = str(self.vlan.network6.ip)
return interface
def enable_net(self): def enable_net(self):
for i in settings.get('default_host_groups', []): for i in settings.get('default_host_groups', []):
self.groups.add(Group.objects.get(name=i)) self.groups.add(Group.objects.get(name=i))
......
...@@ -41,7 +41,7 @@ from .models import ( ...@@ -41,7 +41,7 @@ from .models import (
Instance, InstanceActivity, InstanceTemplate, Interface, Node, Instance, InstanceActivity, InstanceTemplate, Interface, Node,
NodeActivity, pwgen NodeActivity, pwgen
) )
from .tasks import agent_tasks from .tasks import agent_tasks, local_agent_tasks
from dashboard.store_api import Store, NoStoreException from dashboard.store_api import Store, NoStoreException
...@@ -153,6 +153,7 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -153,6 +153,7 @@ class AddInterfaceOperation(InstanceOperation):
self.rollback(net, activity) self.rollback(net, activity)
raise raise
net.deploy() net.deploy()
local_agent_tasks.send_networking_commands(self.instance, activity)
def get_activity_name(self, kwargs): def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("add %(vlan)s interface"), return create_readable(ugettext_noop("add %(vlan)s interface"),
......
...@@ -76,3 +76,8 @@ def get_keys(vm): ...@@ -76,3 +76,8 @@ def get_keys(vm):
@celery.task(name='agent.send_expiration') @celery.task(name='agent.send_expiration')
def send_expiration(vm, url): def send_expiration(vm, url):
pass pass
@celery.task(name='agent.change_ip')
def change_ip(vm, interfaces, dns):
pass
...@@ -19,7 +19,9 @@ from common.models import create_readable ...@@ -19,7 +19,9 @@ from common.models import create_readable
from manager.mancelery import celery from manager.mancelery import celery
from vm.tasks.agent_tasks import (restart_networking, change_password, from vm.tasks.agent_tasks import (restart_networking, change_password,
set_time, set_hostname, start_access_server, set_time, set_hostname, start_access_server,
cleanup, update) cleanup, update, change_ip)
from firewall.models import Host
import time import time
from base64 import encodestring from base64 import encodestring
from StringIO import StringIO from StringIO import StringIO
...@@ -31,13 +33,11 @@ from celery.result import TimeoutError ...@@ -31,13 +33,11 @@ from celery.result import TimeoutError
from monitor.client import Client from monitor.client import Client
def send_init_commands(instance, act, vm): def send_init_commands(instance, act):
vm = instance.vm_name
queue = instance.get_remote_queue_name("agent") queue = instance.get_remote_queue_name("agent")
with act.sub_activity('cleanup', readable_name=ugettext_noop('cleanup')): with act.sub_activity('cleanup', readable_name=ugettext_noop('cleanup')):
cleanup.apply_async(queue=queue, args=(vm, )) cleanup.apply_async(queue=queue, args=(vm, ))
with act.sub_activity('restart_networking',
readable_name=ugettext_noop('restart networking')):
restart_networking.apply_async(queue=queue, args=(vm, ))
with act.sub_activity('change_password', with act.sub_activity('change_password',
readable_name=ugettext_noop('change password')): readable_name=ugettext_noop('change password')):
change_password.apply_async(queue=queue, args=(vm, instance.pw)) change_password.apply_async(queue=queue, args=(vm, instance.pw))
...@@ -49,6 +49,17 @@ def send_init_commands(instance, act, vm): ...@@ -49,6 +49,17 @@ def send_init_commands(instance, act, vm):
queue=queue, args=(vm, instance.primary_host.hostname)) queue=queue, args=(vm, instance.primary_host.hostname))
def send_networking_commands(instance, act):
queue = instance.get_remote_queue_name("agent")
with act.sub_activity('change_ip',
readable_name=ugettext_noop('change ip')):
change_ip.apply_async(queue=queue, args=(
instance.vm_name, ) + get_network_configs(instance))
with act.sub_activity('restart_networking',
readable_name=ugettext_noop('restart networking')):
restart_networking.apply_async(queue=queue, args=(instance.vm_name, ))
def create_agent_tar(): def create_agent_tar():
def exclude(tarinfo): def exclude(tarinfo):
if tarinfo.name.startswith('./.git'): if tarinfo.name.startswith('./.git'):
...@@ -94,8 +105,9 @@ def agent_started(vm, version=None): ...@@ -94,8 +105,9 @@ def agent_started(vm, version=None):
if not initialized: if not initialized:
measure_boot_time(instance) measure_boot_time(instance)
send_init_commands(instance, act, vm) send_init_commands(instance, act)
send_networking_commands(instance, act)
with act.sub_activity( with act.sub_activity(
'start_access_server', 'start_access_server',
readable_name=ugettext_noop('start access server') readable_name=ugettext_noop('start access server')
...@@ -134,6 +146,13 @@ def agent_stopped(vm): ...@@ -134,6 +146,13 @@ def agent_stopped(vm):
pass pass
def get_network_configs(instance):
interfaces = {}
for host in Host.objects.filter(interface__instance=instance):
interfaces[str(host.mac)] = host.get_network_config()
return (interfaces, settings.FIREWALL_SETTINGS['rdns_ip'])
def update_agent(instance, act=None): def update_agent(instance, act=None):
if act: if act:
act = act.sub_activity( act = act.sub_activity(
......
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