def _extract_int_param(self, name, value, allow_zero=True, allow_negative=False): try: return param_utils.extract_int(name, value, allow_zero, allow_negative) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e))
def index(self, req, identity, resource_name=None): """ Lists summary information for all events """ whitelist = {"limit": "single", "marker": "single", "sort_dir": "single", "sort_keys": "multi"} filter_whitelist = { "resource_status": "mixed", "resource_action": "mixed", "resource_name": "mixed", "resource_type": "mixed", } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) key = rpc_api.PARAM_LIMIT if key in params: try: limit = param_utils.extract_int(key, params[key], allow_zero=True) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e)) params[key] = limit if resource_name is None: if not filter_params: filter_params = None else: filter_params["resource_name"] = resource_name events = self._event_list(req, identity, filters=filter_params, **params) if not events and resource_name is not None: msg = _("No events found for resource %s") % resource_name raise exc.HTTPNotFound(msg) return {"events": events}
def index(self, req, identity): """ Lists summary information for all resources """ nested_depth = 0 key = rpc_api.PARAM_NESTED_DEPTH if key in req.params: nested_depth = param_utils.extract_int(key, req.params[key]) res_list = self.rpc_client.list_stack_resources( req.context, identity, nested_depth) return {'resources': [format_resource(req, res) for res in res_list]}
def index(self, req, identity, resource_name=None): """ Lists summary information for all events """ whitelist = { 'limit': 'single', 'marker': 'single', 'sort_dir': 'single', 'sort_keys': 'multi', } filter_whitelist = { 'resource_status': 'mixed', 'resource_action': 'mixed', 'resource_name': 'mixed', 'resource_type': 'mixed', } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) if not filter_params: filter_params = None key = rpc_api.PARAM_LIMIT if key in params: try: limit = param_utils.extract_int(key, params[key], allow_zero=True) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e)) params[key] = limit if resource_name is None: events = self._event_list(req, identity, filters=filter_params, **params) else: res_match = lambda e: e[rpc_api.EVENT_RES_NAME] == resource_name events = self._event_list(req, identity, res_match, filters=filter_params, **params) if not events: msg = _('No events found for resource %s') % resource_name raise exc.HTTPNotFound(msg) return {'events': events}
def update(self, req, identity, body): """ Update an existing stack with a new template and/or parameters """ data = InstantiationData(body) args = data.args() key = rpc_api.PARAM_TIMEOUT if key in args: args[key] = param_utils.extract_int(key, args[key]) self.rpc_client.update_stack(req.context, identity, data.template(), data.environment(), data.files(), args) raise exc.HTTPAccepted()
def index(self, req, identity): """ Lists summary information for all resources """ nested_depth = 0 key = rpc_api.PARAM_NESTED_DEPTH if key in req.params: nested_depth = param_utils.extract_int(key, req.params[key]) res_list = self.rpc_client.list_stack_resources(req.context, identity, nested_depth) return {'resources': [format_resource(req, res) for res in res_list]}
def update_patch(self, req, identity, body): """ Update an existing stack with a new template by patching the parameters Add the flag patch to the args so the engine code can distinguish """ data = InstantiationData(body, patch=True) args = data.args() key = rpc_api.PARAM_TIMEOUT if key in args: args[key] = param_utils.extract_int(key, args[key]) self.rpc_client.update_stack(req.context, identity, data.template(), data.environment(), data.files(), args) raise exc.HTTPAccepted()
def index(self, req, identity): """ Lists summary information for all resources """ nested_depth = 0 key = rpc_api.PARAM_NESTED_DEPTH if key in req.params: try: nested_depth = param_utils.extract_int(key, req.params[key]) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e)) res_list = self.rpc_client.list_stack_resources( req.context, identity, nested_depth) return {'resources': [format_resource(req, res) for res in res_list]}
def index(self, req, identity, resource_name=None): """ Lists summary information for all events """ whitelist = { 'limit': 'single', 'marker': 'single', 'sort_dir': 'single', 'sort_keys': 'multi', } filter_whitelist = { 'resource_status': 'mixed', 'resource_action': 'mixed', 'resource_name': 'mixed', 'resource_type': 'mixed', } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) if not filter_params: filter_params = None key = rpc_api.PARAM_LIMIT if key in params: try: limit = param_utils.extract_int(key, params[key], allow_zero=True) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e)) params[key] = limit if resource_name is None: events = self._event_list(req, identity, filters=filter_params, **params) else: def res_match(e): return e[rpc_api.EVENT_RES_NAME] == resource_name events = self._event_list(req, identity, res_match, filters=filter_params, **params) if not events: msg = _('No events found for resource %s') % resource_name raise exc.HTTPNotFound(msg) return {'events': events}
def index(self, req, identity): """ Lists summary information for all resources """ nested_depth = 0 key = rpc_api.PARAM_NESTED_DEPTH if key in req.params: try: nested_depth = param_utils.extract_int(key, req.params[key]) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e)) res_list = self.rpc_client.list_stack_resources(req.context, identity, nested_depth) return {'resources': [format_resource(req, res) for res in res_list]}
def index(self, req, identity, resource_name=None): """Lists summary information for all events.""" param_types = { 'limit': util.PARAM_TYPE_SINGLE, 'marker': util.PARAM_TYPE_SINGLE, 'sort_dir': util.PARAM_TYPE_SINGLE, 'sort_keys': util.PARAM_TYPE_MULTI, 'nested_depth': util.PARAM_TYPE_SINGLE, } filter_param_types = { 'resource_status': util.PARAM_TYPE_MIXED, 'resource_action': util.PARAM_TYPE_MIXED, 'resource_name': util.PARAM_TYPE_MIXED, 'resource_type': util.PARAM_TYPE_MIXED, } params = util.get_allowed_params(req.params, param_types) filter_params = util.get_allowed_params(req.params, filter_param_types) int_params = (rpc_api.PARAM_LIMIT, rpc_api.PARAM_NESTED_DEPTH) try: for key in int_params: if key in params: params[key] = param_utils.extract_int(key, params[key], allow_zero=True) except ValueError as e: raise exc.HTTPBadRequest(str(e)) if resource_name is None: if not filter_params: filter_params = None else: filter_params['resource_name'] = resource_name events = self._event_list(req, identity, filters=filter_params, **params) if not events and resource_name is not None: msg = _('No events found for resource %s') % resource_name raise exc.HTTPNotFound(msg) return {'events': events}
def create(self, req, body): """ Create a new stack """ data = InstantiationData(body) args = data.args() key = rpc_api.PARAM_TIMEOUT if key in args: args[key] = param_utils.extract_int(key, args[key]) result = self.rpc_client.create_stack(req.context, data.stack_name(), data.template(), data.environment(), data.files(), args) formatted_stack = stacks_view.format_stack(req, {rpc_api.STACK_ID: result}) return {'stack': formatted_stack}
def index(self, req, identity, resource_name=None): """Lists summary information for all events.""" whitelist = { 'limit': util.PARAM_TYPE_SINGLE, 'marker': util.PARAM_TYPE_SINGLE, 'sort_dir': util.PARAM_TYPE_SINGLE, 'sort_keys': util.PARAM_TYPE_MULTI, 'nested_depth': util.PARAM_TYPE_SINGLE, } filter_whitelist = { 'resource_status': util.PARAM_TYPE_MIXED, 'resource_action': util.PARAM_TYPE_MIXED, 'resource_name': util.PARAM_TYPE_MIXED, 'resource_type': util.PARAM_TYPE_MIXED, } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) int_params = (rpc_api.PARAM_LIMIT, rpc_api.PARAM_NESTED_DEPTH) try: for key in int_params: if key in params: params[key] = param_utils.extract_int( key, params[key], allow_zero=True) except ValueError as e: raise exc.HTTPBadRequest(six.text_type(e)) if resource_name is None: if not filter_params: filter_params = None else: filter_params['resource_name'] = resource_name events = self._event_list( req, identity, filters=filter_params, **params) if not events and resource_name is not None: msg = _('No events found for resource %s') % resource_name raise exc.HTTPNotFound(msg) return {'events': events}
def create(self, req, body): """ Create a new stack """ data = InstantiationData(body) args = data.args() key = rpc_api.PARAM_TIMEOUT if key in args: args[key] = param_utils.extract_int(key, args[key]) result = self.rpc_client.create_stack(req.context, data.stack_name(), data.template(), data.environment(), data.files(), args) formatted_stack = stacks_view.format_stack( req, {rpc_api.STACK_ID: result} ) return {'stack': formatted_stack}
def _index(self, req, tenant_safe=True): filter_whitelist = { 'id': 'mixed', 'status': 'mixed', 'name': 'mixed', 'action': 'mixed', 'tenant': 'mixed', 'username': '******', 'owner_id': 'mixed', } whitelist = { 'limit': 'single', 'marker': 'single', 'sort_dir': 'single', 'sort_keys': 'multi', 'show_deleted': 'single', 'show_nested': 'single', 'show_hidden': 'single', 'tags': 'single', 'tags_any': 'single', 'not_tags': 'single', 'not_tags_any': 'single', } params = util.get_allowed_params(req.params, whitelist) filter_params = util.get_allowed_params(req.params, filter_whitelist) show_deleted = False if rpc_api.PARAM_SHOW_DELETED in params: params[rpc_api.PARAM_SHOW_DELETED] = param_utils.extract_bool( params[rpc_api.PARAM_SHOW_DELETED]) show_deleted = params[rpc_api.PARAM_SHOW_DELETED] show_nested = False if rpc_api.PARAM_SHOW_NESTED in params: params[rpc_api.PARAM_SHOW_NESTED] = param_utils.extract_bool( params[rpc_api.PARAM_SHOW_NESTED]) show_nested = params[rpc_api.PARAM_SHOW_NESTED] key = rpc_api.PARAM_LIMIT if key in params: params[key] = param_utils.extract_int(key, params[key]) show_hidden = False if rpc_api.PARAM_SHOW_HIDDEN in params: params[rpc_api.PARAM_SHOW_HIDDEN] = param_utils.extract_bool( params[rpc_api.PARAM_SHOW_HIDDEN]) show_hidden = params[rpc_api.PARAM_SHOW_HIDDEN] tags = None if rpc_api.PARAM_TAGS in params: params[rpc_api.PARAM_TAGS] = param_utils.extract_tags( params[rpc_api.PARAM_TAGS]) tags = params[rpc_api.PARAM_TAGS] tags_any = None if rpc_api.PARAM_TAGS_ANY in params: params[rpc_api.PARAM_TAGS_ANY] = param_utils.extract_tags( params[rpc_api.PARAM_TAGS_ANY]) tags_any = params[rpc_api.PARAM_TAGS_ANY] not_tags = None if rpc_api.PARAM_NOT_TAGS in params: params[rpc_api.PARAM_NOT_TAGS] = param_utils.extract_tags( params[rpc_api.PARAM_NOT_TAGS]) not_tags = params[rpc_api.PARAM_NOT_TAGS] not_tags_any = None if rpc_api.PARAM_NOT_TAGS_ANY in params: params[rpc_api.PARAM_NOT_TAGS_ANY] = param_utils.extract_tags( params[rpc_api.PARAM_NOT_TAGS_ANY]) not_tags_any = params[rpc_api.PARAM_NOT_TAGS_ANY] # get the with_count value, if invalid, raise ValueError with_count = False if req.params.get('with_count'): with_count = param_utils.extract_bool( req.params.get('with_count')) if not filter_params: filter_params = None stacks = self.rpc_client.list_stacks(req.context, filters=filter_params, tenant_safe=tenant_safe, **params) count = None if with_count: try: # Check if engine has been updated to a version with # support to count_stacks before trying to use it. count = self.rpc_client.count_stacks(req.context, filters=filter_params, tenant_safe=tenant_safe, show_deleted=show_deleted, show_nested=show_nested, show_hidden=show_hidden, tags=tags, tags_any=tags_any, not_tags=not_tags, not_tags_any=not_tags_any) except AttributeError as exc: LOG.warn(_LW("Old Engine Version: %s") % exc) return stacks_view.collection(req, stacks=stacks, count=count, tenant_safe=tenant_safe)
def test_extract_int(self): # None case self.assertIsNone(param_utils.extract_int('num', None)) # 0 case self.assertEqual(0, param_utils.extract_int('num', 0)) self.assertEqual(0, param_utils.extract_int('num', 0, allow_zero=True)) self.assertEqual(0, param_utils.extract_int('num', '0')) self.assertEqual(0, param_utils.extract_int('num', '0', allow_zero=True)) self.assertRaises(ValueError, param_utils.extract_int, 'num', 0, allow_zero=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', '0', allow_zero=False) # positive values self.assertEqual(1, param_utils.extract_int('num', 1)) self.assertEqual(1, param_utils.extract_int('num', '1')) self.assertRaises(ValueError, param_utils.extract_int, 'num', '1.1') self.assertRaises(ValueError, param_utils.extract_int, 'num', 1.1) # negative values self.assertEqual( -1, param_utils.extract_int('num', -1, allow_negative=True)) self.assertEqual( -1, param_utils.extract_int('num', '-1', allow_negative=True)) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1.1', allow_negative=True) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1.1, allow_negative=True) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1') self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1.1') self.assertRaises(ValueError, param_utils.extract_int, 'num', -1.1) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1, allow_negative=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1', allow_negative=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1.1', allow_negative=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1.1, allow_negative=False) # Non-int value self.assertRaises(ValueError, param_utils.extract_int, 'num', 'abc') self.assertRaises(ValueError, param_utils.extract_int, 'num', '') self.assertRaises(ValueError, param_utils.extract_int, 'num', 'true') self.assertRaises(ValueError, param_utils.extract_int, 'num', True)
def test_extract_int(self): # None case self.assertIsNone(param_utils.extract_int('num', None)) # 0 case self.assertEqual(0, param_utils.extract_int('num', 0)) self.assertEqual(0, param_utils.extract_int('num', 0, allow_zero=True)) self.assertEqual(0, param_utils.extract_int('num', '0')) self.assertEqual(0, param_utils.extract_int('num', '0', allow_zero=True)) self.assertRaises(ValueError, param_utils.extract_int, 'num', 0, allow_zero=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', '0', allow_zero=False) # positive values self.assertEqual(1, param_utils.extract_int('num', 1)) self.assertEqual(1, param_utils.extract_int('num', '1')) self.assertRaises(ValueError, param_utils.extract_int, 'num', '1.1') self.assertRaises(ValueError, param_utils.extract_int, 'num', 1.1) # negative values self.assertEqual(-1, param_utils.extract_int('num', -1, allow_negative=True)) self.assertEqual(-1, param_utils.extract_int('num', '-1', allow_negative=True)) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1.1', allow_negative=True) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1.1, allow_negative=True) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1') self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1.1') self.assertRaises(ValueError, param_utils.extract_int, 'num', -1.1) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1, allow_negative=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1', allow_negative=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', '-1.1', allow_negative=False) self.assertRaises(ValueError, param_utils.extract_int, 'num', -1.1, allow_negative=False) # Non-int value self.assertRaises(ValueError, param_utils.extract_int, 'num', 'abc') self.assertRaises(ValueError, param_utils.extract_int, 'num', '') self.assertRaises(ValueError, param_utils.extract_int, 'num', 'true') self.assertRaises(ValueError, param_utils.extract_int, 'num', True)