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 test_first(self): as_id_int = UserAS.objects.get_next_id() self.assertEqual(as_id_int, USER_AS_ID_BEGIN) self.assertEqual(as_ids.format(as_id_int), 'ffaa:1:1')
def create(self, owner, attachment_point, public_port, installation_type, as_id=None, label=None, use_vpn=False, public_ip=None, bind_ip=None, bind_port=None, vpn_client_ip=None): """ Create a UserAS attached to the given attachment point. :param User owner: owner of this UserAS :param AttachmentPoint attachment_point: the attachment point (AP) to connect to :param int public_port: the public port for the connection to the AP :param str as_id: optional as_id, if None is given, the next free ID is chosen :param str label: optional label :param bool use_vpn: use VPN for the connection to the AP :param str public_ip: the public IP for the connection to the AP. Must be specified if use_vpn is not enabled. :param str bind_ip: the bind IP for the connection to the AP (for NAT) :param str bind_port: the bind port for the connection to the AP (for NAT port remapping) :param str vpn_client_ip: the specific IP address to assign to the VPN client (if vpn). A free one if not specified, and ignored if use_vpn == False. :returns: UserAS """ owner.check_as_quota() isd = attachment_point.AS.isd 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 = UserAS( owner=owner, label=label, isd=isd, as_id=as_id, as_id_int=as_id_int, attachment_point=attachment_point, public_ip=public_ip, bind_ip=bind_ip, bind_port=bind_port, installation_type=installation_type, ) user_as.init_keys() user_as.generate_certificate_chain() user_as.save() user_as.init_default_services( public_ip=public_ip, bind_ip=_VAGRANT_VM_LOCAL_IP if installation_type == UserAS.VM else bind_ip, ) host = user_as.hosts.get() if use_vpn: vpn_client = attachment_point.vpn.create_client(host=host, active=True, client_ip=vpn_client_ip) interface_client = Interface.objects.create( border_router=BorderRouter.objects.first_or_create(host), public_ip=vpn_client.ip, public_port=public_port, ) interface_ap = Interface.objects.create( border_router=attachment_point.get_border_router_for_useras_interface(), public_ip=attachment_point.vpn.server_vpn_ip ) else: interface_client = Interface.objects.create( border_router=BorderRouter.objects.first_or_create(host), public_port=public_port, bind_port=bind_port ) interface_ap = Interface.objects.create( border_router=attachment_point.get_border_router_for_useras_interface(), ) Link.objects.create( type=Link.PROVIDER, interfaceA=interface_ap, interfaceB=interface_client ) attachment_point.split_border_routers() attachment_point.trigger_deployment() return user_as