Commit e70e0f22 by Szabolcs Gelencser

Update public IP's of NICs on resume, show public ip of NIC on

dashboard
parent 654dbc54
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0009_auto_20161011_1328'),
]
operations = [
migrations.AddField(
model_name='instance',
name='public_ip',
field=models.TextField(blank=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0010_instance_public_ip'),
]
operations = [
migrations.AddField(
model_name='interface',
name='public_ip_name',
field=models.TextField(null=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0011_interface_public_ip_name'),
]
operations = [
migrations.RemoveField(
model_name='instance',
name='public_ip',
),
migrations.AddField(
model_name='interface',
name='public_ip',
field=models.TextField(blank=True),
),
]
......@@ -560,21 +560,15 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def get_connect_port(self, use_ipv6=False):
"""Get public port number for default access method.
"""
port, proto = ACCESS_PROTOCOLS[self.access_method][1:3]
if self.primary_host:
endpoints = self.primary_host.get_public_endpoints(port, proto)
endpoint = endpoints['ipv6'] if use_ipv6 else endpoints['ipv4']
return endpoint[1] if endpoint else None
else:
return None
return "22"
def get_connect_host(self, use_ipv6=False):
"""Get public hostname.
"""
if not self.primary_host:
return None
proto = 'ipv6' if use_ipv6 else 'ipv4'
return self.primary_host.get_hostname(proto=proto)
for i in self.interface_set.all():
if i.public_ip != "":
return i.public_ip
return None
def get_connect_command(self, use_ipv6=False):
"""Returns a formatted connect string.
......
......@@ -73,6 +73,8 @@ class Interface(Model):
related_name='interface_set')
model = CharField(max_length=10, choices=MODEL_TYPES, default='virtio')
azure_id = TextField(null=True)
public_ip_name = TextField(null=True)
public_ip = TextField(blank=True)
class Meta:
app_label = 'vm'
......@@ -166,13 +168,15 @@ class Interface(Model):
iface.save()
logger.debug("sending task to create azure interface")
azure_id = net_tasks.create_azure_interface.apply_async(
result = net_tasks.create_azure_interface.apply_async(
args=[iface.pk, vlan.name],
queue="localhost.net.fast"
).get()
if azure_id:
logger.debug("created azure interface with id: %s" % azure_id)
iface.azure_id = azure_id
if result["azure_id"]:
logger.debug("created azure interface with id: %s" % (
result["azure_id"]))
iface.azure_id = result["azure_id"]
iface.public_ip_name = result["public_ip_name"]
iface.save()
return iface
......
......@@ -369,7 +369,7 @@ class DeployOperation(InstanceOperation):
self.instance.STATUS.ERROR)
def on_abort(self, activity, error):
activity.resultant_state = 'STOPPED'
activity.resultant_state = 'PENDING'
def on_commit(self, activity):
activity.resultant_state = 'RUNNING'
......@@ -432,30 +432,25 @@ class DeployOperation(InstanceOperation):
self.instance.name))
@register_operation
class DeployDisksOperation(SubOperationMixin, InstanceOperation):
id = "_deploy_disks"
name = _("deploy disks")
description = _("Deploy all associated disks.")
def _operation(self):
devnums = list(ascii_lowercase) # a-z
for disk in self.instance.disks.all():
# assign device numbers
if disk.dev_num in devnums:
devnums.remove(disk.dev_num)
else:
disk.dev_num = devnums.pop(0)
disk.save()
# deploy disk
disk.deploy()
@register_operation
class ResumeVmOperation(SubOperationMixin, RemoteInstanceOperation):
class ResumeVmOperation(SubOperationMixin, InstanceOperation):
id = "_resume_vm"
name = _("boot virtual machine")
remote_queue = ("vm", "slow")
task = vm_tasks.resume
def _operation(self):
#TODO: implement resume functionality too
nics = [{
"id": nic.id,
"public_ip_name": nic.public_ip_name,
} for nic in self.instance.interface_set.all()]
result = vm_tasks.resume.apply_async(
args=[nics], queue="localhost.vm.fast"
).get(timeout=1200)
for nic in result:
nic_obj = Interface.objects.get(pk=nic["id"])
nic_obj.public_ip = nic["public_ip"]
nic_obj.save()
@register_operation
class DestroyOperation(InstanceOperation):
......
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