def as_id(self) -> str: """ Shortcut to AS.as_id. Returns the ASID stored directly on this Key object, in order to keep this information after deleting an AS. """ return as_ids.format(self._as_id_int)
def test_parse_format(self, as_id_str, expected_int): parsed = as_ids.parse(as_id_str) self.assertEqual(parsed, expected_int) parsed = as_ids.parse(as_id_str.upper()) self.assertEqual(parsed, expected_int) formatted = as_ids.format(parsed) self.assertEqual(formatted, as_id_str.lower())
def create(self, owner: User, installation_type: str, isd: int, public_ip: str = "", wants_user_ap: bool = False, wants_vpn: bool = False, as_id: str = None, label: str = None) -> 'UserAS': """Create a UserAS :param User owner: owner of this UserAS :param str installation_type: :param int isd: :param str public_ip: optional public IP address for the host of the AS :param bool wants_user_ap: optional boolean if the User AS should be AP :param str wants_vpn: optional boolean if the User AP should provide a VPN :param str as_id: optional as_id, if None is given, the next free ID is chosen :param str label: optional label :returns: UserAS """ owner.check_as_quota() assert isd, "No ISD provided" if as_id: as_id_int = as_ids.parse(as_id) else: as_id_int = self.get_next_id() as_id = as_ids.format(as_id_int) user_as = super().create( owner=owner, label=label, isd=isd, as_id=as_id, as_id_int=as_id_int, installation_type=installation_type, master_as_key=AS._make_master_as_key() ) user_as.generate_keys() user_as.generate_certs() user_as.init_default_services(public_ip=public_ip) if wants_user_ap: host = user_as.hosts.first() vpn = None if wants_vpn: vpn = VPN.objects.create(server=host) AttachmentPoint.objects.create(AS=user_as, vpn=vpn) return user_as
def create(self, owner: User, installation_type: str, isd: int, as_id: str = None, label: str = None) -> 'UserAS': """Create a UserAS :param User owner: owner of this UserAS :param str installation_type: :param int isd: :param str as_id: optional as_id, if None is given, the next free ID is chosen :param str label: optional label :returns: UserAS """ owner.check_as_quota() assert isd, "No ISD provided" if as_id: as_id_int = as_ids.parse(as_id) else: as_id_int = self.get_next_id() as_id = as_ids.format(as_id_int) user_as = super().create( owner=owner, label=label, isd=isd, as_id=as_id, as_id_int=as_id_int, installation_type=installation_type, master_as_key=AS._make_master_as_key() ) user_as.generate_keys() user_as.generate_certs() user_as.init_default_services() return user_as
def test_first(self): as_id_int = UserAS.objects.get_next_id() self.assertEqual(as_id_int, USER_AS_ID_BEGIN) self.assertEqual(as_ids_utils.format(as_id_int), 'ffaa:1:1')