Skip to content

Commit

Permalink
Merge pull request #327 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer committed May 19, 2017
2 parents 2523617 + 203242d commit e094b4a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions IM/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,22 @@ def create_nics(self, inf, radl, credentials, subscription_id, group_name, subne
if radl.systems[0].getValue('availability_zone'):
location = radl.systems[0].getValue('availability_zone')

hasPublicIP = radl.hasPublicNet(system.name)

i = 0
res = []
publicAdded = False
while system.getValue("net_interface." + str(i) + ".connection"):
network_name = system.getValue("net_interface." + str(i) + ".connection")
# TODO: check how to do that
# fixed_ip = system.getValue("net_interface." + str(i) + ".ip")
network = radl.get_network_by_id(network_name)

if network.isPublic():
# Public nets are not added as nics
i += 1
continue

nic_name = "nic-%d" % i
ip_config_name = "ip-config-%d" % i

Expand All @@ -302,8 +311,11 @@ def create_nics(self, inf, radl, credentials, subscription_id, group_name, subne
}]
}

if network.isPublic():
primary = False
if hasPublicIP and not publicAdded:
# Create PublicIP
publicAdded = True
primary = True
public_ip_name = "public-ip-%d" % i
public_ip_parameters = {
'location': location,
Expand All @@ -329,7 +341,7 @@ def create_nics(self, inf, radl, credentials, subscription_id, group_name, subne
async_nic_creation = network_client.network_interfaces.create_or_update(
group_name, nic_name, nic_params)
nic = async_nic_creation.result()
res.append(nic)
res.append((nic, primary))

i += 1

Expand Down Expand Up @@ -384,7 +396,7 @@ def get_azure_vm_create_json(self, storage_account, vm_name, nics, radl, instanc
},
},
'network_profile': {
'network_interfaces': [{'id': nic.id, 'primary': nic == nics[0]} for nic in nics]
'network_interfaces': [{'id': nic.id, 'primary': primary} for nic, primary in nics]
},
}

Expand Down Expand Up @@ -632,11 +644,13 @@ def setIPs(self, vm, network_profile, credentials, subscription_id):
ip_conf = network_client.network_interfaces.get(sub, name).ip_configurations

for ip in ip_conf:
private_ips.append(ip.private_ip_address)
name = " ".join(ip.public_ip_address.id.split('/')[-1:])
sub = "".join(ip.public_ip_address.id.split('/')[4])
public_ip_info = network_client.public_ip_addresses.get(sub, name)
public_ips.append(public_ip_info.ip_address)
if ip.private_ip_address:
private_ips.append(ip.private_ip_address)
if ip.public_ip_address:
name = " ".join(ip.public_ip_address.id.split('/')[-1:])
sub = "".join(ip.public_ip_address.id.split('/')[4])
public_ip_info = network_client.public_ip_addresses.get(sub, name)
public_ips.append(public_ip_info.ip_address)

vm.setIps(public_ips, private_ips)

Expand Down

0 comments on commit e094b4a

Please sign in to comment.