def update(self, request, id, tenant_id, body=None): LOG.info("Updating IP block %(id)s for %(tenant_id)s" % locals()) ip_block = self._find_block(id=id, tenant_id=tenant_id) params = self._extract_required_params(body, 'ip_block') ip_block.update(**utils.exclude(params, 'cidr', 'type')) LOG.debug("Updated IP block %(id)s parameters: %(params)s" % locals()) return wsgi.Result(dict(ip_block=ip_block.data()), 200)
def _extract_required_params(self, params, model_name): params = params or {} model_params = params.get(model_name, {}) return utils.stringify_keys(utils.exclude(model_params, *self.exclude_attr))
def update(self, request, policy_id, id, tenant_id, body=None): policy = models.Policy.find_by(id=policy_id, tenant_id=tenant_id) ip_octet = policy.find_ip_octet(id) params = self._extract_required_params(body, 'ip_octet') ip_octet.update(**utils.exclude(params, 'policy_id')) return dict(ip_octet=ip_octet.data())
def update(self, **values): attrs = utils.exclude(values, *self._auto_generated_attrs) self.merge_attributes(attrs) result = self.save() self._notify_fields("update") return result
def _extract_required_params(self, params, model_name): params = params or {} model_params = params.get(model_name, {}) return utils.stringify_keys( utils.exclude(model_params, *self.exclude_attr))
def test_returns_none_if_dict_is_none(self): self.assertIsNone(utils.exclude(None, 'key1'))
def test_excludes_given_keys(self): dictionary = {'key1': "value1", 'key2': "value2", 'key3': "value3"} self.assertEqual(utils.exclude(dictionary, 'key2', 'key3'), {'key1': "value1"})
def test_excludes_ignore_non_exsistant_keys(self): dictionary = {'key1': "value1", 'key2': "value2", 'key3': "value3"} self.assertEqual(utils.exclude(dictionary, 'key2', 'nonexistant'), {'key1': "value1", 'key3': "value3"})
def update(self, request, id, tenant_id, body=None): ip_block = self._find_block(id=id, tenant_id=tenant_id) params = self._extract_required_params(body, 'ip_block') ip_block.update(**utils.exclude(params, 'cidr', 'type')) return wsgi.Result(dict(ip_block=ip_block.data()), 200)
def update(self, request, policy_id, id, tenant_id, body=None): policy = models.Policy.find_by(id=policy_id, tenant_id=tenant_id) ip_range = policy.find_ip_range(id) params = self._extract_required_params(body, "ip_range") ip_range.update(**utils.exclude(params, "policy_id")) return dict(ip_range=ip_range.data())
def test_excludes_ignore_non_exsistant_keys(self): dictionary = {'key1': "value1", 'key2': "value2", 'key3': "value3"} self.assertEqual(utils.exclude(dictionary, 'key2', 'nonexistant'), { 'key1': "value1", 'key3': "value3" })