示例#1
0
 def add_ip(self, ip):
     if isinstance(ip, basestring):
         try:
             ip = IPAddress(ip)
         except AddrFormatError:
             return False
     ipnum = ip.value
     if rds.sismember(self.gatekey, ipnum):
         rds.srem(self.gatekey, ipnum)
     rds.sadd(self.storekey, ipnum)
     return True
示例#2
0
 def add_ip(self, ip):
     if isinstance(ip, basestring):
         try:
             ip = IPAddress(ip)
         except AddrFormatError:
             return False
     ipnum = ip.value
     if rds.sismember(self.gatekey, ipnum):
         rds.srem(self.gatekey, ipnum)
     rds.sadd(self.storekey, ipnum)
     return True
示例#3
0
    def acquire_gateway_ip(self, host):
        ipnum = rds.spop(self.gatekey)
        if not ipnum:
            return

        vg = VLanGateway.create(ipnum, self.id, host.id)
        if not vg:
            rds.sadd(self.gatekey, ipnum)
            return

        return vg
示例#4
0
    def acquire_gateway_ip(self, host):
        ipnum = rds.spop(self.gatekey)
        if not ipnum:
            return

        vg = VLanGateway.create(ipnum, self.id, host.id)
        if not vg:
            rds.sadd(self.gatekey, ipnum)
            return

        return vg
示例#5
0
def fix_ip(n):
    network = n.network
    base = int(network.network_address)
    for ipnums in more_itertools.chunked(xrange(base+n.gateway_count, base+network.num_addresses), 500):
        rds.sadd(n.storekey, *ipnums)

    rds.sadd(n.gatekey, *range(base, base+n.gateway_count))

    for ip in n.ips.all():
        rds.srem(n.storekey, ip.ipnum)

    for gateway in n.gates.all():
        rds.srem(n.gatekey, gateway.ipnum)
示例#6
0
def fix_ip(n):
    network = n.network
    base = int(network.network_address)
    for ipnums in more_itertools.chunked(
            xrange(base + n.gateway_count, base + network.num_addresses), 500):
        rds.sadd(n.storekey, *ipnums)

    rds.sadd(n.gatekey, *range(base, base + n.gateway_count))

    for ip in n.ips.all():
        rds.srem(n.storekey, ip.ipnum)

    for gateway in n.gates.all():
        rds.srem(n.gatekey, gateway.ipnum)
示例#7
0
    def create(cls, name, netspace, gateway_count=100):
        """create network and store ips(int) under this network in redis"""
        try:
            n = cls(name, netspace, gateway_count)
            db.session.add(n)
            db.session.commit()

            # create sub IPs
            network = n.network
            base = network.first

            # 一次写500个吧
            # 写容器可用IP
            for ipnums in more_itertools.chunked(xrange(base+gateway_count, base+network.size), 500):
                rds.sadd(n.storekey, *ipnums)

            # 写宿主机可用IP
            rds.sadd(n.gatekey, *range(base, base+gateway_count))
            return n
        except sqlalchemy.exc.IntegrityError:
            db.session.rollback()
            return None
示例#8
0
    def create(cls, name, netspace, gateway_count=100):
        """create network and store ips(int) under this network in redis"""
        try:
            n = cls(name, netspace, gateway_count)
            db.session.add(n)
            db.session.commit()

            # create sub IPs
            network = n.network
            base = network.first

            # 一次写500个吧
            # 写容器可用IP
            for ipnums in more_itertools.chunked(
                    xrange(base + gateway_count, base + network.size), 500):
                rds.sadd(n.storekey, *ipnums)

            # 写宿主机可用IP
            rds.sadd(n.gatekey, *range(base, base + gateway_count))
            return n
        except sqlalchemy.exc.IntegrityError:
            db.session.rollback()
            return None
示例#9
0
def add_container_backends(container):
    rds.hset(_app_key(container), container.entrypoint, _entrypoint_key(container))
    backends = container.get_backends()
    if backends:
        rds.sadd(_entrypoint_key(container), *backends)
示例#10
0
 def release_gateway(self, ip):
     rds.sadd(self.gatekey, int(ip))
示例#11
0
 def release_ip(self, ip):
     rds.sadd(self.storekey, int(ip))
示例#12
0
 def release_eip(self, eip):
     rds.sadd(self.EIP_POOL_KEY, eip.value)
示例#13
0
 def add_eip(self, *eips):
     rds.sadd(self.EIP_POOL_KEY, *[eip.value for eip in eips])
示例#14
0
def add_container_backends(container):
    rds.hset(_app_key(container), container.entrypoint,
             _entrypoint_key(container))
    backends = container.get_backends()
    if backends:
        rds.sadd(_entrypoint_key(container), *backends)
示例#15
0
 def release_gateway(self, ip):
     rds.sadd(self.gatekey, int(ip))
示例#16
0
 def release_ip(self, ip):
     rds.sadd(self.storekey, int(ip))