- resp = ''
- if resp_unicode:
- resp = json.loads(resp_unicode)
- # print('HTTP CODE: {}'.format(http_code))
- # print('RESP: {}'.format(resp))
- # print('URL: {}/{}'.format(apiUrlStatus, entity_id))
- if deleteFlag and http_code == 404:
- # In case of deletion, '404 Not Found' means successfully deleted
- # 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:
- # Get operation status
- op_status = _op_has_finished(resp, entity_label)
- if op_status == -1:
- # An error occurred
- raise ClientException('unexpected response from server - {} '.format(
- str(resp)))
- elif op_status == 0:
- # If there was an error upon deletion, try again to delete the same instance
- # If the error is the same, there is probably nothing we can do but exit with error.
- # If the error is different (i.e. 404), the instance was probably already corrupt, that is,
- # operation(al)State was probably ERROR before deletion.
- # In such a case, even if the previous state was ERROR, the deletion was successful,
- # so detailed-status should be set to Deleted.
- if _has_delete_error(resp, entity_label, deleteFlag, delete_attempts_left):
- delete_attempts_left -= 1
- else:
- # Operation has finished, either with success or error
- if deleteFlag:
- 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
- # At the moment of this writing, 'detailed-status' may return different strings
- # from different resources:
- # /nslcm/v1/ns_lcm_op_occs/<id> ---> ''
- # /nslcm/v1/ns_instances_content/<id> ---> 'deleting charms'
- detailed_status = _show_detailed_status(detailed_status, new_detailed_status)
- if time_to_return: