Skip to content

Commit

Permalink
Merge pull request #1567 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
micafer authored May 30, 2024
2 parents c5a2362 + 0caa046 commit 09576d7
Showing 4 changed files with 59 additions and 2 deletions.
20 changes: 20 additions & 0 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
@@ -1305,6 +1305,11 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
self.log_info("No private networks found. Force the creation.")
self.set_nets_to_create(radl)

if not driver.ex_list_floating_ip_pools():
self.log_info("No floating IP pools found. Avoid the public VMs"
" to be attached to a private one.")
self.remove_private_nets(radl)

with inf._lock:
self.create_networks(driver, radl, inf)

@@ -1412,6 +1417,21 @@ def get_private_nets(self, driver):
res.append(net)
return res

@staticmethod
def remove_private_nets(radl):
"""
Remove the private networks
"""
if radl.hasPublicNet(radl.systems[0].name):
i = 0
while radl.systems[0].getValue("net_interface." + str(i) + ".connection"):
net_name = radl.systems[0].getValue("net_interface." + str(i) + ".connection")
network = radl.get_network_by_id(net_name)
if not network.isPublic():
radl.systems[0].remove_net_interface(i)
else:
i += 1

@staticmethod
def set_nets_to_create(radl):
"""
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ PyYAML
cheroot
boto >= 2.29
apache-libcloud >= 3.3.1
RADL >= 1.1.6
RADL >= 1.3.3
bottle
netaddr
requests >= 2.19
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@
description="IM is a tool to manage virtual infrastructures on Cloud deployments",
platforms=["any"],
install_requires=["ansible >=2.4", "paramiko >= 1.14", "PyYAML", suds_pkg, sqlite_pkg, "cheroot",
"boto >= 2.29", "apache-libcloud >= 3.2.0", "RADL >= 1.1.5", "bottle", "netaddr",
"boto >= 2.29", "apache-libcloud >= 3.2.0", "RADL >= 1.3.3", "bottle", "netaddr",
"requests >= 2.19", "scp", "tosca-parser", 'defusedxml', 'urllib3>=1.23', 'hvac',
'psutil', 'scar', 'requests-cache >= 1.0.0', 'packaging']
)
37 changes: 37 additions & 0 deletions test/unit/connectors/OpenStack.py
Original file line number Diff line number Diff line change
@@ -1055,6 +1055,43 @@ def test_get_driver(self, get_driver):
ost_cloud.get_driver(auth)
self.assertEqual(get_driver.call_count, 2)

def test_remove_private_nets(self):
radl_data = """
network net2 (outbound = 'yes')
network net1 ()
system test (
net_interface.0.connection = 'net1' and
net_interface.1.connection = 'net2' and
net_interface.1.dns_name = 'test' and
disk.0.os.name = 'linux'
)"""
radl = radl_parse.parse_radl(radl_data)
OpenStackCloudConnector.remove_private_nets(radl)

self.assertEqual(radl.systems[0].getValue('net_interface.0.connection'), 'net2')
self.assertEqual(radl.systems[0].getValue('net_interface.0.dns_name'), 'test')
self.assertIsNone(radl.systems[0].getValue('net_interface.1.connection'))
self.assertIsNone(radl.systems[0].getValue('net_interface.1.dns_name'))

radl_data = """
network net1 (outbound = 'yes')
network net2 ()
network net3 ()
network net4 (outbound = 'yes')
system test (
net_interface.0.connection = 'net1' and
net_interface.1.connection = 'net2' and
net_interface.2.connection = 'net3' and
net_interface.3.connection = 'net4' and
disk.0.os.name = 'linux'
)"""
radl = radl_parse.parse_radl(radl_data)
OpenStackCloudConnector.remove_private_nets(radl)

self.assertEqual(radl.systems[0].getValue('net_interface.1.connection'), 'net4')
self.assertIsNone(radl.systems[0].getValue('net_interface.2.connection'))
self.assertIsNone(radl.systems[0].getValue('net_interface.3.connection'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 09576d7

Please sign in to comment.