Exemple #1
0
class FloatingIP(BaseModel):
    floatingipid = UUIDType(serialized_name='floatingIpId')
    fixedipaddress = IPv4Type(serialized_name='fixedIPAddress', default='')
    floatingipaddress = IPv4Type(serialized_name='floatingIpAddress',
                                 default='')
    floatingnetworkid = UUIDType(serialized_name='floatingNetworkId')
    portid = UUIDType(serialized_name='portId')
    routerid = UUIDType(serialized_name='routerId')
class Prediction(SbbModel):
    __tablename__ = 'prediction'

    project = StringType(required=True)
    interval = IntType(required=True)
    period = IntType(required=True)
    ip_address = IPv4Type(required=True)
    model = StringType(required=True)
    pi_model = StringType()  # fake property for indexing
    created_at = IntType()

    @property
    def __key__(self):
        return "{0}-{1}-{2}-{3}-{4}".format(self.project, self.interval,
                                            self.period, self.ip_address,
                                            self.model)

    @property
    def __namespace__(self):
        return None

    @property
    def period_dt(self):
        return datetime.datetime.fromtimestamp(self.period)

    def before_save(self):
        self.pi_model = "{0}_{1}_{2}".format(self.project, self.interval,
                                             self.model)
        self.created_at = int(time.time())
Exemple #3
0
def delete_route(router_id, route_id):
    id_seg = route_id.split('-')
    if id_seg is None or len(id_seg) != 2:
        return json_response(status=RESOURCE_NOT_FOUND), HTTP_NOT_FOUND

    for s in id_seg:
        if not IPv4Type.valid_ip(s):
            return json_response(status=RESOURCE_NOT_FOUND), HTTP_NOT_FOUND
    dst_address, dst_netmask = id_seg

    key = ('delete', 'route', str(router_id), dst_address, dst_netmask)
    ret_queue = PseudoGeventQueue()
    args = [
        ROUTER_SCRIPT,
        'delete',
        'route',
        str(router_id),
        dst_address,
        dst_netmask,
    ]
    cmd_waiting_queues_put(router_id, router_hash, key, args, ret_queue)
    output = cmd_response_get(ret_queue)
    if output:
        return json_response(status=SERVER_ERROR,
                             description=output), HTTP_INTERNAL_SERVER_ERROR

    return json_response(status=SUCCESS), HTTP_OK
class GirderConfig(Model):
    '''
    A class for validating configurations supplied to GirderExporter.

    Attributes:
        api_key (str): Girder API key.
        root_id (str): ID of folder or collection under which all data will
            be exported.
        root_type (str, optional): Root entity type. Default: collection.
            Options: folder, collection
        host (str, optional): Docker host IP address. Default: 0.0.0.0.
        port (int, optional): Docker host port. Default: 8080.
    '''
    api_key = StringType(required=True)  # type: StringType
    root_id = StringType(required=True)  # type: StringType
    root_type = StringType(
        required=True,
        default='collection',
        validators=[lambda x: vd.is_in([x], ['collection', 'folder'])
                    ])  # type: StringType
    host = IPv4Type(required=True, default='0.0.0.0')  # type: IPv4Type
    port = IntType(required=True,
                   default=8080,
                   validators=[
                       lambda x: vd.is_lt(x, 65536),
                       lambda x: vd.is_gt(x, 1023),
                   ])  # type: IntType
Exemple #5
0
class Suppression(OriginModel):
    CURRENT_VERSION = 2

    rowkey = UUIDType(default=uuid.uuid4)
    regex = StringType(required=True)
    created = TimestampType(default=arrow.get)
    disabled = TimestampType(serialize_when_none=False)
    expires = TimestampType(required=True)
    ipaddr = IPv4Type(required=True)
    userid = StringType(required=True)
    comment = StringType(required=True)
    version = IntType(default=CURRENT_VERSION)

    default_sort_order = 'created'
    pk = 'rowkey'

    @property
    def active(self):
        if self.disabled or self.expires < arrow.get():
            return False
        else:
            return True

    @property
    def state(self):
        if self.disabled:
            return "disabled (%s, %s)" % (self.disabled,
                                          self.disabled.humanize())
        elif self.expires < arrow.get():
            return "expired (%s, %s)" % (self.expires, self.expires.humanize())
        else:
            return "active"

    @property
    def re(self):
        return re.compile(self.regex)

    @classmethod
    def migrate(cls, item):
        """ Takes an old version 1 item and returns a new version 2
        Suppression.
        """
        new_suppression = None
        try:
            new_suppression = cls({
                'rowkey': uuid.UUID(item['rowkey']),
                'regex': item['regex'],
                'created': arrow.get(int(item['created_at'])),
                'expires': arrow.get(int(item['expires'])),
                'ipaddr': item['ipaddr'],
                'userid': item['userid'],
                'comment': item['comment']
            })
            if not item['active'] == 'True':
                new_suppression.disabled = arrow.get(int(item['active']))
        except Exception:
            logger.exception("Unable to migrate suppression to v2: %s", item)
        return new_suppression
Exemple #6
0
class Subnet(BaseModel):
    subnet_id = StringType(serialized_name="subnetId")
    subnet_name = StringType(serialized_name="subnetName")
    network_id = StringType(serialized_name='networkId')
    cidr = StringType(serialized_name='cidr')
    allocation_pools = ListType(ModelType(IpAllocPool),
                                serialized_name='allocation_pools')
    gateway_ip = IPv4Type(serialized_name='gatewayIp')
    dns_nameservers = ListType(IPv4Type, serialized_name='dnsNameservers')
class Example(SbbModel):
    __tablename__ = 'example'

    project = StringType(required=True)
    interval = IntType(required=True)
    p_interval = StringType()  # fake property for indexing
    period = IntType(required=True)
    ip_address = IPv4Type(required=True)

    @property
    def __key__(self):
        return "{0}-{1}-{2}-{3}".format(self.project, self.interval,
                                        self.period, self.ip_address)

    @property
    def __namespace__(self):
        return None

    @property
    def period_dt(self):
        return datetime.datetime.fromtimestamp(self.period)

    def before_save(self):
        self.p_interval = "{0}_{1}".format(self.project, self.interval)

    def reduce_interval(self, new_interval):
        if new_interval > 24 * 60:
            raise ValueError(
                'Maximum interval allowed is 1440 minutes (1 day)')
        period = datetime.datetime.fromtimestamp(self.period)
        diff = ((period.minute + period.hour * 60) * 60) % (new_interval * 60)
        self.period = self.period - diff
        self.interval = new_interval

    def __add__(self, other):
        if not isinstance(other, Example):
            raise ValueError
        new_example = copy.copy(self)
        for key, value in other._custom_data.items():
            if key in self._custom_data:
                if isinstance(value, (int, float)):
                    new_example._custom_data[key] += value
        return new_example
class IpAddress(SbbModel):
    ipaddress = IPv4Type(primary_key=True)
    status = IntType()
 class Data(Model):
     a = IPv4Type()
Exemple #10
0
 class Proxy(XMLModel):
     ip_address = IPv4Type()
Exemple #11
0
class FloatingIPCreate(BaseModel):
    floatingnetworkid = UUIDType(serialized_name='floatingNetworkId',
                                 required=True)
    floatingipaddress = IPv4Type(serialized_name='floatingIpAddress')
    portid = UUIDType(serialized_name='portId')
    fixedipaddress = IPv4Type(serialized_name='fixedIPAddress')
Exemple #12
0
class ExternalFixedIps(BaseModel):
    subnet_id = StringType(serialized_name='subnetId', required=True)
    ip = IPv4Type(serialized_name='ip', required=True)
Exemple #13
0
class IpAllocPool(BaseModel):
    start = IPv4Type(serialized_name='start', required=True)
    end = IPv4Type(serialized_name='end', required=True)