vm: create subactivity for ip address allocations
Showing
... | @@ -8,6 +8,7 @@ from django.utils.translation import ugettext_lazy as _ | ... | @@ -8,6 +8,7 @@ from django.utils.translation import ugettext_lazy as _ |
from firewall.models import Vlan, Host | from firewall.models import Vlan, Host | ||
from ..tasks import net_tasks | from ..tasks import net_tasks | ||
from .activity import instance_activity | |||
logger = getLogger(__name__) | logger = getLogger(__name__) | ||
... | @@ -105,7 +106,7 @@ class Interface(Model): | ... | @@ -105,7 +106,7 @@ class Interface(Model): |
self.host.delete() | self.host.delete() | ||
@classmethod | @classmethod | ||
def create(cls, instance, vlan, managed, owner=None): | def create(cls, instance, vlan, managed, owner=None, base_activity=None): | ||
"""Create a new interface for a VM instance to the specified VLAN. | """Create a new interface for a VM instance to the specified VLAN. | ||
""" | """ | ||
if managed: | if managed: | ||
... | @@ -115,9 +116,19 @@ class Interface(Model): | ... | @@ -115,9 +116,19 @@ class Interface(Model): |
host.mac = str(cls.generate_mac(instance, vlan)) | host.mac = str(cls.generate_mac(instance, vlan)) | ||
host.hostname = instance.vm_name | host.hostname = instance.vm_name | ||
# Get adresses from firewall | # Get adresses from firewall | ||
addresses = vlan.get_new_address() | if base_activity is None: | ||
host.ipv4 = addresses['ipv4'] | act = instance_activity(code_suffix='allocating_ip', | ||
host.ipv6 = addresses['ipv6'] | instance=instance, user=owner) | ||
else: | |||
act = base_activity.sub_activity('allocating_ip') | |||
with act as act: | |||
Please
register
or
sign in
to reply
|
|||
addresses = vlan.get_new_address() | |||
host.ipv4 = addresses['ipv4'] | |||
host.ipv6 = addresses['ipv6'] | |||
act.result = ('new addresses: ipv4: %(ip4)s, ipv6: %(ip6)s, ' | |||
'vlan: %(vlan)s' % {'ip4': host.ipv4, | |||
'ip6': host.ipv6, | |||
'vlan': vlan.name}) | |||
host.owner = owner | host.owner = owner | ||
if vlan.network_type == 'public': | if vlan.network_type == 'public': | ||
host.shared_ip = False | host.shared_ip = False | ||
... | ... |