示例#1
0
    def delete_prefixes(self):
        prefixes = LocationPrefix.select().where(
            LocationPrefix.location_id == self.location_id
        )

        for prefix in prefixes:
            prefix.delete_instance()
示例#2
0
    def post(self):
        if self.auth.account.account_type != "senior_admin":
            abort(
                403,
                message="Insufficient privileges to create a location prefix"
            )

        location_id = self.get_location_id()

        # make sure the location exists
        try:
            locationdb = Location.get(Location.location_id == location_id)
        except peewee.DoesNotExist:
            abort(400, message="location_id does not exist")

        prefix_type = str(request.form.get('prefix_type', 'ipv4')).lower()
        if prefix_type not in ['ipv4', 'ipv6']:
            abort(400, message='prefix_type must be either ipv4 or ipv6')

        prefix = request.form.get('prefix', None)

        if prefix is None or not Validate().ip_prefix(prefix, prefix_type):
            abort(
                400,
                message='invalid prefix for prefix_type ' + prefix_type
            )

        prefix_description = request.form.get('prefix_description', None)
        new_prefix = LocationPrefix()
        new_prefix.location_id = location_id
        new_prefix.prefix = prefix
        new_prefix.prefix_type = prefix_type
        if prefix_description is not None:
            new_prefix.prefix_description = prefix_description

        try:
            new_prefix.save()
        except peewee.IntegrityError as e:
            abort(
                400,
                message=str(e)
            )

        # notify listeners of dns data change
        self.send_update_notification()

        return {'status': 'ok', 'location_prefix': new_prefix.to_dict()}
示例#3
0
    def get(self, prefix_id):
        try:
            prefixdb = ModelPrefix.get(ModelPrefix.prefix_id == prefix_id)
            location = ModelLocation.get(
                ModelLocation.location_id == prefixdb.location_id)
        except peewee.DoesNotExist:
            abort(404, message="prefix not found")

        return {
            'status': 'ok',
            'location_prefix': prefixdb.to_dict(),
            'location': location.to_dict()
        }
示例#4
0
    def get(self, prefix_id):
        try:
            prefixdb = ModelPrefix.get(ModelPrefix.prefix_id == prefix_id)
            location = ModelLocation.get(
                ModelLocation.location_id == prefixdb.location_id
            )
        except peewee.DoesNotExist:
            abort(404, message="prefix not found")

        return {
            'status': 'ok',
            'location_prefix': prefixdb.to_dict(),
            'location': location.to_dict()
        }
示例#5
0
    def post(self):
        if self.auth.account.account_type != "senior_admin":
            abort(
                403,
                message="Insufficient privileges to create a location prefix"
            )

        location_id = self.get_location_id()

        # make sure the location exists
        try:
            locationdb = Location.get(Location.location_id == location_id)
        except peewee.DoesNotExist:
            abort(400, message="location_id does not exist")

        prefix_type = str(request.form.get('prefix_type', 'ipv4')).lower()
        if prefix_type not in ['ipv4', 'ipv6']:
            abort(400, message='prefix_type must be either ipv4 or ipv6')

        prefix = request.form.get('prefix', None)

        if prefix is None or not Validate().ip_prefix(prefix, prefix_type):
            abort(
                400,
                message='invalid prefix for prefix_type ' + prefix_type
            )

        prefix_description = request.form.get('prefix_description', None)
        new_prefix = LocationPrefix()
        new_prefix.location_id = location_id
        new_prefix.prefix = prefix
        new_prefix.prefix_type = prefix_type
        if prefix_description is not None:
            new_prefix.prefix_description = prefix_description

        try:
            new_prefix.save()
        except peewee.IntegrityError as e:
            abort(
                400,
                message=str(e)
            )

        return {'status': 'ok', 'location_prefix': new_prefix.to_dict()}
示例#6
0
    def delete(self, prefix_id):
        if self.auth.account.account_type != "senior_admin":
            abort(
                403,
                message="Insufficient privileges to delete a location prefix"
            )

        try:
            prefixdb = ModelPrefix.get(
                ModelPrefix.prefix_id == prefix_id
            )
        except peewee.DoesNotExist:
            abort(404, message="location prefix not found")

        prefixdb.delete_instance()

        return {'status': 'ok'}
示例#7
0
    def delete(self, prefix_id):
        if self.auth.account.account_type != "senior_admin":
            abort(
                403,
                message="Insufficient privileges to delete a location prefix")

        try:
            prefixdb = ModelPrefix.get(ModelPrefix.prefix_id == prefix_id)
        except peewee.DoesNotExist:
            abort(404, message="location prefix not found")

        prefixdb.delete_instance()

        # notify listeners of dns data change
        self.send_update_notification()

        return {'status': 'ok'}
示例#8
0
    def put(self, prefix_id):
        if self.auth.account.account_type != "senior_admin":
            abort(
                403,
                message="Insufficient privileges to update a location prefix"
            )

        try:
            prefixdb = ModelPrefix.get(ModelPrefix.prefix_id == prefix_id)
        except peewee.DoesNotExist:
            abort(404, message="prefix not found")

        prefix_type = str(request.form.get('prefix_type', 'ipv4')).lower()
        if prefix_type not in ['ipv4', 'ipv6']:
            abort(400, message='prefix_type must be either ipv4 or ipv6')

        prefix = request.form.get('prefix', None)
        valid_prefix = Validate().ip_prefix(prefix, prefix_type)

        if not valid_prefix:
            abort(
                400,
                message='invalid prefix for prefix_type ' + prefix_type
            )

        prefix_description = request.form.get('prefix_description', None)

        prefixdb.prefix = prefix
        prefixdb.prefix_type = prefix_type
        if prefix_description is not None:
            prefixdb.prefix_description = prefix_description
        try:
            prefixdb.save()
        except peewee.IntegrityError as e:
            abort(
                400,
                message=str(e)
            )

        # notify listeners of dns data change
        self.send_update_notification()

        return {'status': 'ok', 'location_prefix': prefixdb.to_dict()}
示例#9
0
    def get(self):
        location_id = self.get_location_id()

        # make sure location exists
        try:
            location = Location.get(Location.location_id == location_id)
        except peewee.DoesNotExist:
            abort(404, message="location_id does not exist")

        query = LocationPrefix.select().where(
            LocationPrefix.location_id == location_id)
        prefixes = []
        for prefix in query:
            prefixes.append(prefix.to_dict())

        return {
            'status': 'ok',
            'location_prefixes': prefixes,
            'location': location.to_dict()
        }
示例#10
0
    def get(self):
        location_id = self.get_location_id()

        # make sure location exists
        try:
            location = Location.get(Location.location_id == location_id)
        except peewee.DoesNotExist:
            abort(404, message="location_id does not exist")

        query = LocationPrefix.select().where(
            LocationPrefix.location_id == location_id
        )
        prefixes = []
        for prefix in query:
            prefixes.append(prefix.to_dict())

        return {
            'status': 'ok',
            'location_prefixes': prefixes,
            'location': location.to_dict()
        }
示例#11
0
    def put(self, prefix_id):
        if self.auth.account.account_type != "senior_admin":
            abort(
                403,
                message="Insufficient privileges to update a location prefix"
            )

        try:
            prefixdb = ModelPrefix.get(ModelPrefix.prefix_id == prefix_id)
        except peewee.DoesNotExist:
            abort(404, message="prefix not found")

        prefix_type = str(request.form.get('prefix_type', 'ipv4')).lower()
        if prefix_type not in ['ipv4', 'ipv6']:
            abort(400, message='prefix_type must be either ipv4 or ipv6')

        prefix = request.form.get('prefix', None)
        valid_prefix = Validate().ip_prefix(prefix, prefix_type)

        if not valid_prefix:
            abort(
                400,
                message='invalid prefix for prefix_type ' + prefix_type
            )

        prefix_description = request.form.get('prefix_description', None)

        prefixdb.prefix = prefix
        prefixdb.prefix_type = prefix_type
        if prefix_description is not None:
            prefixdb.prefix_description = prefix_description
        try:
            prefixdb.save()
        except peewee.IntegrityError as e:
            abort(
                400,
                message=str(e)
            )

        return {'status': 'ok', 'location_prefix': prefixdb.to_dict()}
示例#12
0
    def delete_prefixes(self):
        prefixes = LocationPrefix.select().where(
            LocationPrefix.location_id == self.location_id)

        for prefix in prefixes:
            prefix.delete_instance()