Skip to content

Commit 18a6f89

Browse files
authored
Merge pull request #6506 from DIRACGridBot/cherry-pick-2-955038301-integration
[sweep:integration] feat: add network selection to CloudCE
2 parents d364911 + 5037837 commit 18a6f89

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/DIRAC/Resources/Computing/CloudComputingElement.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
(Required) The raw ID of the flavor to use or the name of a flavor
9999
prefixed by "name:".
100100
101+
Instance_Networks:
102+
(Optional) A comma seperated list of either the raw IDs or the names
103+
prefixed by "name:" of the networks to use.
104+
101105
Instance_SSHKey:
102106
(Optional) The ID of an SSH key (on OpenStack this is just a plain name).
103107
If not specified the node will be booted without an extra key.
@@ -135,6 +139,7 @@
135139
Driver_ex_tenant_name = clouduser
136140
Instance_Image = name:CentOS-7-x86_64-GenericCloud-1905
137141
Instance_Flavor = name:m1.medium
142+
Instance_Networks = name:my_public_net,name:my_private_net
138143
Instance_SSHKey = mysshkey
139144
140145
"""
@@ -279,6 +284,35 @@ def _getFlavor(self):
279284
return flavor
280285
raise KeyError("No matching flavor found for %s" % rawID)
281286

287+
def _getNetworks(self):
288+
"""Extracts network list from configuration system.
289+
290+
:return: List of network objects or None if not set
291+
"""
292+
rawIDs = self.ceParameters.get("Instance_Networks", None)
293+
if not rawIDs:
294+
return None
295+
drv = self._getDriver()
296+
avail_networks = drv.ex_list_networks()
297+
networks = []
298+
for netID in rawIDs.split(","):
299+
found = False
300+
for net in avail_networks:
301+
netName = ""
302+
if netID.startswith("name:"):
303+
netName = netID[5:]
304+
if not netName and net.id == netID:
305+
networks.append(net)
306+
found = True
307+
break
308+
elif netName and net.name == netName:
309+
networks.append(net)
310+
found = True
311+
break
312+
if not found:
313+
raise KeyError("No matching network found for %s" % netID)
314+
return networks
315+
282316
def _getSSHKeyID(self):
283317
"""Extract ssh key id from configuration system.
284318
@@ -426,6 +460,9 @@ def submitJob(self, executableFile, proxy, numberOfJobs=1):
426460
instParams = {}
427461
instParams["image"] = self._getImage()
428462
instParams["size"] = self._getFlavor()
463+
networks = self._getNetworks()
464+
if networks:
465+
instParams["networks"] = networks
429466
instParams["ex_keyname"] = self._getSSHKeyID()
430467
instParams["ex_userdata"] = self._getMetadata(executableFile)
431468
instParams["ex_config_drive"] = True

0 commit comments

Comments
 (0)