Skip to content

Commit 0892b54

Browse files
committed
refactor wait for network create
1 parent 780a263 commit 0892b54

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

netfoundry/network_group.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,28 @@ def create_network(self, name: str, network_group_id: str = None, location: str
242242
else:
243243
raise RuntimeError(f"got unexpected HTTP code {STATUS_CODES._codes[response_code][0].upper()} ({response_code}) and response {response.text}")
244244

245-
if resource.get('_links') and resource['_links'].get('process-executions'):
246-
_links = resource['_links'].get('process-executions')
247-
if isinstance(_links, list):
248-
process_id = _links[0]['href'].split('/')[6]
245+
try:
246+
process_executions = resource['_links'].get('process-executions')
247+
if isinstance(process_executions, list):
248+
find_executions_url = process_executions[0]['href']
249249
else:
250-
process_id = _links['href'].split('/')[6]
251-
if wait:
250+
find_executions_url = process_executions['href']
251+
processes = list()
252+
process_id = None
253+
for i in find_generic_resources(url=find_executions_url, headers=headers, embedded=NET_RESOURCES['process-executions']._embedded, proxies=self.proxies, verify=self.verify):
254+
processes.extend(i)
255+
for process in processes:
256+
if process['name'].startswith('Create Network'):
257+
process_id = process['id']
258+
break
259+
if wait and process_id:
252260
self.Networks.wait_for_process(process_id, RESOURCES["process-executions"].status_symbols['complete'], wait=wait, sleep=sleep)
253261
resource = self.get_resource_by_id(type="network", id=resource['id'])
254-
return(resource)
255-
else: # only wait for the process to start, not finish, or timeout
256-
# FIXME: commented to allow create to succeed to workaround MOP-18095
257-
# self.Networks.wait_for_process(process_id, RESOURCES['process-executions'].status_symbols['progress'] + RESOURCES['process-executions'].status_symbols['complete'], wait=9, sleep=3)
258-
return(resource)
259-
elif wait:
260-
self.logger.warning("unable to wait for async complete because response did not provide a process execution id")
262+
else:
263+
self.logger.warning("not configured to wait or no process_id found in list of executions")
264+
except Exception as e:
265+
self.logger.warning(f"unable to wait for async process to complete, caught {e}")
266+
finally:
261267
return(resource)
262268

263269
def delete_network(self, network_id=None, network_name=None):

0 commit comments

Comments
 (0)