Commit a8e2421f by Szabolcs Gelencser

Get public IP's of interfaces on VM resume.

parent b24c1117
......@@ -83,12 +83,12 @@ def create_azure_interface(ifacepk, vlan_name):
nic_poller.wait()
nic_id = nic_poller.result().id
logging.info("created network interface with id: %s" % nic_id)
return nic_id
return {"azure_id": nic_id, "public_ip_name": public_ip_name}
except Exception, e:
logging.error("cloud not create network interface")
logging.error(str(e))
#TODO: should delete public ip (rollback)
return None
return {"azure_id": None, "public_ip_name": None}
@celery.task
......
......@@ -18,6 +18,7 @@ from vmcelery import celery, lib_connection, to_bool
from azure.common.credentials import ServicePrincipalCredentials
import azure.mgmt.compute
import azure.mgmt.network
SUBSCRIPTION_ID = os.getenv('SUBSCRIPTION_ID')
CLIENT_ID = os.getenv('CLIENT_ID')
......@@ -37,6 +38,11 @@ compute_client = azure.mgmt.compute.ComputeManagementClient(
SUBSCRIPTION_ID
)
network_client = azure.mgmt.network.NetworkManagementClient(
credentials,
SUBSCRIPTION_ID
)
sys.path.append(os.path.dirname(os.path.basename(__file__)))
vm_xml_dump = None
......@@ -385,11 +391,25 @@ def restore(name, path):
@celery.task
def resume(name):
""" Resume stopped virtual machines.
def resume(nics):
"""
#TODO: implement
return
Resume stopped virtual machines
return public ip of interfaces
"""
nics_with_public_ip = []
for nic in nics:
try:
public_ip_address = network_client.public_ip_addresses.get(
GROUP_NAME, nic["public_ip_name"])
nics_with_public_ip.append({
"id": nic["id"],
"public_ip": public_ip_address.ip_address,
})
except:
pass
return nics_with_public_ip
@celery.task
......
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