예제 #1
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
예제 #2
0
파일: user_as.py 프로젝트: mlegner/scionlab
    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