Commit b0ff5771 by Bach Dániel

Merge branch 'issue-31' into 'master'

Log Host life cycle
parents e036da5c 9e66bb5d
...@@ -373,13 +373,14 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -373,13 +373,14 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
activity.resultant_state = 'PENDING' activity.resultant_state = 'PENDING'
with instance_activity(code_suffix='create', instance=inst, with instance_activity(code_suffix='create', instance=inst,
on_commit=__on_commit, user=inst.owner): on_commit=__on_commit, user=inst.owner) as act:
# create related entities # create related entities
inst.disks.add(*[disk.get_exclusive() for disk in disks]) inst.disks.add(*[disk.get_exclusive() for disk in disks])
for net in networks: for net in networks:
Interface.create(instance=inst, vlan=net.vlan, Interface.create(instance=inst, vlan=net.vlan,
owner=inst.owner, managed=net.managed) owner=inst.owner, managed=net.managed,
base_activity=act)
inst.req_traits.add(*req_traits) inst.req_traits.add(*req_traits)
inst.tags.add(*tags) inst.tags.add(*tags)
......
...@@ -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
if base_activity is None:
act = instance_activity(code_suffix='allocating_ip',
instance=instance, user=owner)
else:
act = base_activity.sub_activity('allocating_ip')
with act as act:
addresses = vlan.get_new_address() addresses = vlan.get_new_address()
host.ipv4 = addresses['ipv4'] host.ipv4 = addresses['ipv4']
host.ipv6 = addresses['ipv6'] 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
......
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