Ejemplo n.º 1
0
    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())
Ejemplo n.º 2
0
    def create(self,
               isd,
               as_id,
               is_core=False,
               label=None,
               mtu=None,
               owner=None,
               init_certificates=True):
        """
        Create the AS and initialise the required keys
        :param ISD isd:
        :param str as_id: valid AS-identifier string
        :param bool is_core: should this AS be created as a core AS?
        :param str label: optional
        :param User owner: optional
        :returns: AS
        """
        as_id_int = as_ids.parse(as_id)
        as_ = super().create(isd=isd,
                             as_id=as_id,
                             as_id_int=as_id_int,
                             is_core=is_core,
                             label=label,
                             mtu=mtu or DEFAULT_LINK_MTU,
                             owner=owner,
                             master_as_key=AS._make_master_as_key())

        as_.generate_keys()
        if init_certificates:
            as_.generate_certs()
            if is_core:
                isd.trcs.create()

        return as_
Ejemplo n.º 3
0
def _create_AS(isd, as_id, is_core=False):
    as_ = AS(isd=isd,
             as_id=as_id,
             as_id_int=as_ids.parse(as_id),
             is_core=is_core)
    as_.save()
    return as_
Ejemplo n.º 4
0
def _create_AS(isd, as_id, is_core=False):
    # bypass ASManager.create to avoid initializing keys
    as_ = AS(isd=isd,
             as_id=as_id,
             as_id_int=as_ids.parse(as_id),
             is_core=is_core)
    as_.save()
    return as_
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 def setUp(self):
     self.isd = ISD.objects.create(isd_id=1, label='Test')
     # bypass ASManager.create to avoid initializing keys
     as_id = 'ff00:0:110'
     self.AS = AS(isd=self.isd, as_id=as_id, as_id_int=as_ids.parse(as_id))
     self.AS.save()
Ejemplo n.º 8
0
 def test_parse_fail(self, as_id_str):
     try:
         parsed = as_ids.parse(as_id_str)
     except ValueError:
         return
     self.fail("Expected failure, returned %x instead" % parsed)