def _validate_pagination(pagination_size): if pagination_size < 0: raise manager_exceptions.IllegalActionError( 'Invalid pagination size: {0}.'.format(pagination_size)) if pagination_size > config.instance.max_results: raise manager_exceptions.IllegalActionError( 'Invalid pagination size: {0}. Max allowed: {1}'.format( pagination_size, config.instance.max_results))
def _verify_no_multi_node_cluster(action): if not (cluster_status and node_status and 'initialized' in node_status): return if not node_status['initialized']: raise manager_exceptions.IllegalActionError( 'Action `{0}` is not available while ' 'initializing a cluster'.format(action)) if len(cluster_status.nodes) > 1: raise manager_exceptions.IllegalActionError( 'Action `{0}` is not available on a ' 'cluster with more than one node'.format(action))
def validate_deployment_and_site_visibility(deployment, site): if is_visibility_wider(deployment.visibility, site.visibility): raise manager_exceptions.IllegalActionError( "The visibility of deployment `{0}`: `{1}` can't be wider than " "the visibility of it's site `{2}`: `{3}`".format( deployment.id, deployment.visibility, site.name, site.visibility))
def validate_global_modification(resource): # A global resource can't be modify from outside its tenant if resource.visibility == VisibilityState.GLOBAL and \ resource.tenant_name != current_tenant.name: raise manager_exceptions.IllegalActionError( "Can't modify the global resource `{0}` from outside its " "tenant `{1}`".format(resource.id, resource.tenant_name))
def wrapper(*args, **kwargs): if authenticator.external_authentication: raise manager_exceptions.IllegalActionError( 'Action `{0}` is not available when ' 'using external authentication'.format(action) ) return func(*args, **kwargs)
def _validate_pagination(pagination_size): if pagination_size < 0: raise manager_exceptions.IllegalActionError( 'Invalid pagination size: {0}.'.format( pagination_size ) )
def _validate_returned_size(size): if size > config.instance.max_results: raise manager_exceptions.IllegalActionError( 'Response size ({0}) bigger than max allowed ({1}), ' 'please use pagination.'.format( size, config.instance.max_results ) )
def patch(self, filters_model, filter_id, filtered_resource): """Update a filter by its ID This function updates the filter rules and visibility """ rest_utils.validate_inputs({'filter_id': filter_id}) if not request.json: raise manager_exceptions.IllegalActionError( 'Update a filter request must include at least one parameter ' 'to update') request_dict = rest_utils.get_json_and_verify_params( {'filter_rules': { 'type': list, 'optional': True }}) filter_rules = request_dict.get('filter_rules') visibility = rest_utils.get_visibility_parameter( optional=True, valid_values=VisibilityState.STATES) storage_manager = get_storage_manager() filter_elem = storage_manager.get(filters_model, filter_id) _verify_not_a_system_filter(filter_elem, 'update') if visibility: get_resource_manager().validate_visibility_value( filters_model, filter_elem, visibility) filter_elem.visibility = visibility if filter_rules: new_filter_rules = create_filter_rules_list( filter_rules, filtered_resource) new_attrs_filter_rules = _get_filter_rules_by_type( new_filter_rules, 'attribute') new_labels_filter_rules = _get_filter_rules_by_type( new_filter_rules, 'label') if new_attrs_filter_rules: if new_labels_filter_rules: # Both need to be updated filter_elem.value = new_filter_rules else: # Only labels filter rules should be saved filter_elem.value = (filter_elem.labels_filter_rules + new_filter_rules) elif new_labels_filter_rules: # Only attributes filter rules should be saved filter_elem.value = (filter_elem.attrs_filter_rules + new_filter_rules) else: # Should not get here raise manager_exceptions.BadParametersError( 'Unknown filter rules type') filter_elem.updated_at = get_formatted_timestamp() return storage_manager.update(filter_elem)
def cancel_execution(self, execution_id, force=False): """ Cancel an execution by its id If force is False (default), this method will request the executed workflow to gracefully terminate. It is up to the workflow to follow up on that request. If force is used, this method will request the abrupt and immediate termination of the executed workflow. This is valid for all workflows, regardless of whether they provide support for graceful termination or not. Note that in either case, the execution is not yet cancelled upon returning from the method. Instead, it'll be in a 'cancelling' or 'force_cancelling' status (as can be seen in models.Execution). Once the execution is truly stopped, it'll be in 'cancelled' status (unless force was not used and the executed workflow doesn't support graceful termination, in which case it might simply continue regardless and end up with a 'terminated' status) :param execution_id: The execution id :param force: A boolean describing whether to force cancellation :return: The updated execution object :rtype: models.Execution :raises manager_exceptions.IllegalActionError """ execution = self.get_execution(execution_id) if execution.status not in (models.Execution.PENDING, models.Execution.STARTED) and \ (not force or execution.status != models.Execution .CANCELLING): raise manager_exceptions.IllegalActionError( "Can't {0}cancel execution {1} because it's in status {2}" .format( 'force-' if force else '', execution_id, execution.status)) new_status = models.Execution.CANCELLING if not force \ else models.Execution.FORCE_CANCELLING self.sm.update_execution_status( execution_id, new_status, '') return self.get_execution(execution_id)
def _verify_not_a_system_filter(filter_elem, action): if filter_elem.is_system_filter: raise manager_exceptions.IllegalActionError( f'Cannot {action} a system filter')
def wrapper(*args, **kwargs): if authenticator.ldap: raise manager_exceptions.IllegalActionError( 'Action `{0}` is not available in ldap mode'.format( action)) return func(*args, **kwargs)