def _find_sg_on_server(instance_id, set_id): # ids are (sic!) ints sg_id = int_from_string(set_id, on_error=lambda value_: abort(404)) for sg in _security_groups_for_server(instance_id): if sg.id == sg_id: return sg abort(404)
def _find_rule(sg_id, rule_id): """Find rule record in given security group""" # rule ids are (sic!) ints rid = int_from_string(rule_id, on_error=lambda value_: abort(404)) for rule in _get_security_group(sg_id).rules: if rule['id'] == rid: return rule abort(404)
def instance_console_output(instance_id): set_audit_resource_id(instance_id) length = int_from_string(request.args.get("length"), allow_none=True) g.unused_args.discard("length") try: server = fetch_instance(instance_id) data = server.get_console_output(length=length) except osc_exc.NotFound: abort(404) return make_json_response({"instance": link_for_server(server), "console-output": data})
def test_may_parse_none_if_asked(self): self.assertEquals(None, int_from_string(None, allow_none=True))
def test_parses_zero_string(self): self.assertEquals(0, int_from_string('0'))
def test_parses_string(self): self.assertEquals(42, int_from_string('42'))
def from_argument(self, value): return int_from_string( value, self.min_val, self.max_val, on_error=self._illegal_argument)
def from_argument(self, value): return int_from_string(value, self.min_val, self.max_val, on_error=self._illegal_argument)
def test_parses_zero_string(self): self.assertEquals(0, int_from_string("0"))
def test_parses_string(self): self.assertEquals(42, int_from_string("42"))
def _parse_int_request_argument(name): value = request.args.get(name) try: return int_from_string(value, allow_none=True) except ValueError: raise exc.InvalidArgumentValue(name, 'int', value)