TIMEOUT_VIM_OPERATION = TIMEOUT_GENERIC_OPERATION
TIMEOUT_WIM_OPERATION = TIMEOUT_GENERIC_OPERATION
TIMEOUT_NS_OPERATION = 3600
-
POLLING_TIME_INTERVAL = 1
-
MAX_DELETE_ATTEMPTS = 3
def _show_detailed_status(old_detailed_status, new_detailed_status):
return resp.get('_admin', {}).get('operationalState')
def _op_has_finished(resp, entity):
- # _op_has_finished() returns:
+ # This function returns:
# 0 on success (operation has finished)
# 1 on pending (operation has not finished)
# -1 on error (bad response)
detailed_status_deleted = None
time_to_return = False
delete_attempts_left = MAX_DELETE_ATTEMPTS
+ wait_for_404 = False
try:
while True:
http_code, resp_unicode = http_cmd('{}/{}'.format(apiUrlStatus, entity_id))
# Display 'detailed-status: Deleted' and return
time_to_return = True
detailed_status_deleted = 'Deleted'
+ elif deleteFlag and http_code in (200, 201, 202, 204):
+ # In case of deletion and HTTP Status = 20* OK, deletion may be PROCESSING or COMPLETED
+ # If this is the case, we should keep on polling until 404 (deleted) is returned.
+ wait_for_404 = True
elif http_code not in (200, 201, 202, 204):
raise ClientException(str(resp))
if not time_to_return:
else:
# Operation has finished, either with success or error
if deleteFlag:
- if delete_attempts_left < MAX_DELETE_ATTEMPTS:
- time_to_return = True
delete_attempts_left -= 1
+ if not wait_for_404 and delete_attempts_left < MAX_DELETE_ATTEMPTS:
+ time_to_return = True
else:
time_to_return = True
new_detailed_status = _get_detailed_status(resp, entity_label, detailed_status_deleted)
+ # print 'DETAILED-STATUS: {}'.format(new_detailed_status)
+ # print 'DELETE-ATTEMPTS-LEFT: {}'.format(delete_attempts_left)
if not new_detailed_status:
new_detailed_status = 'In progress'
# TODO: Change LCM to provide detailed-status more up to date
except ClientException as inst:
print((inst.message))
exit(1)
- table = PrettyTable(['name', 'id'])
+ table = PrettyTable(['sdnc name', 'id'])
for sdnc in resp:
table.add_row([sdnc['name'], sdnc['_id']])
table.align = 'l'
def _get_id_for_wait(self, name):
# Returns id of name, or the id itself if given as argument
for sdnc in self.list():
- if name == sdnc['name']:
- return sdnc['_id']
- for wim in self.list():
if name == sdnc['_id']:
return sdnc['_id']
+ for sdnc in self.list():
+ if name == sdnc['name']:
+ return sdnc['_id']
return ''
def create(self, name, sdn_controller, wait=False):
sdnc_id_for_wait = self._get_id_for_wait(name)
http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
postfields_dict=sdn_controller)
- #print 'HTTP CODE: {}'.format(http_code)
- #print 'RESP: {}'.format(resp)
+ # print 'HTTP CODE: {}'.format(http_code)
+ # print 'RESP: {}'.format(resp)
if http_code in (200, 201, 202, 204):
- if resp:
- resp = json.loads(resp)
- if not resp or 'id' not in resp:
- raise ClientException('unexpected response from server - {}'.format(
- resp))
if wait:
- # Wait for status for SDNC instance update
- self._wait(sdnc_id_for_wait)
- print(resp['id'])
+ # In this case, 'resp' always returns None, so 'resp['id']' cannot be used.
+ # Use the previously obtained id instead.
+ wait_id = sdnc_id_for_wait
+ # Wait for status for VI instance update
+ self._wait(wait_id)
+ else:
+ pass
else:
msg = ""
if resp:
self._http.get2_cmd,
deleteFlag=deleteFlag)
+ def _get_id_for_wait(self, name):
+ # Returns id of name, or the id itself if given as argument
+ for vim in self.list():
+ if name == vim['uuid']:
+ return vim['uuid']
+ for vim in self.list():
+ if name == vim['name']:
+ return vim['uuid']
+ return ''
+
def create(self, name, vim_access, sdn_controller=None, sdn_port_mapping=None, wait=False):
if 'vim-type' not in vim_access:
#'openstack' not in vim_access['vim-type']):
def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False):
vim = self.get(vim_name)
-
+ vim_id_for_wait = self._get_id_for_wait(vim_name)
vim_config = {}
if 'config' in vim_account:
if vim_account.get('config')=="" and (sdn_controller or sdn_port_mapping):
#vim_account['config'] = json.dumps(vim_config)
http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
postfields_dict=vim_account)
- #print 'HTTP CODE: {}'.format(http_code)
- #print 'RESP: {}'.format(resp)
+ # print 'HTTP CODE: {}'.format(http_code)
+ # print 'RESP: {}'.format(resp)
if http_code in (200, 201, 202, 204):
- if resp:
- resp = json.loads(resp)
- if not resp or 'id' not in resp:
- raise ClientException('unexpected response from server - {}'.format(
- resp))
if wait:
- # Wait for status for VIM instance update
- self._wait(resp.get('id'))
- print(resp['id'])
+ # In this case, 'resp' always returns None, so 'resp['id']' cannot be used.
+ # Use the previously obtained id instead.
+ wait_id = vim_id_for_wait
+ # Wait for status for VI instance update
+ self._wait(wait_id)
+ else:
+ pass
else:
msg = ""
if resp:
def _get_id_for_wait(self, name):
# Returns id of name, or the id itself if given as argument
for wim in self.list():
- if name == wim['name']:
+ if name == wim['uuid']:
return wim['uuid']
for wim in self.list():
- if name == wim['uuid']:
+ if name == wim['name']:
return wim['uuid']
return ''
#print 'RESP: {}'.format(resp)
if http_code in (200, 201, 202, 204):
if wait:
- # 'resp' may be None.
- # In that case, 'resp['id']' cannot be used.
- # In that case, 'resp['id']' cannot be used, so use the previously obtained id instead
+ # In this case, 'resp' always returns None, so 'resp['id']' cannot be used.
+ # Use the previously obtained id instead.
wait_id = wim_id_for_wait
- if resp:
- resp = json.loads(resp)
- wait_id = resp.get('id')
# Wait for status for WIM instance update
self._wait(wait_id)
else: