Exemple #1
0
 def get_all_pools(self):
     pools = _ipam.get_ip_pools(4)
     names = [rds.get(_POOL_NAME_KEY % p.cidr) for p in pools]
     return [
         WrappedNetwork.from_calico(p, name)
         for p, name in zip(pools, names)
     ]
Exemple #2
0
    def remove_ip_pool(self, cidr):
        try:
            cidr = IPNetwork(cidr)
        except (AddrFormatError, ValueError):
            return

        name = rds.get(_POOL_NAME_KEY % cidr)
        rds.delete(_POOL_NAME_KEY % cidr)
        rds.delete(_POOL_CIDR_KEY % name)
        _ipam.remove_ip_pool(4, cidr)
        _ipam.remove_profile(name)
Exemple #3
0
    def remove_ip_pool(self, cidr):
        try:
            cidr = IPNetwork(cidr)
        except (AddrFormatError, ValueError):
            return

        name = rds.get(_POOL_NAME_KEY % cidr)
        rds.delete(_POOL_NAME_KEY % cidr)
        rds.delete(_POOL_CIDR_KEY % name)
        _ipam.remove_ip_pool(4, cidr)
        _ipam.remove_profile(name)
Exemple #4
0
    def get_pool(self, ip):
        """ip can be either an IP or a CIDR"""
        if '/' in ip:
            try:
                ip = IPAddress(IPNetwork(ip).first)
            except (AddrFormatError, ValueError):
                return
        else:
            try:
                ip = IPAddress(ip)
            except (AddrFormatError, ValueError):
                return

        pool = _ipam.get_pool(ip)
        name = rds.get(_POOL_NAME_KEY % pool.cidr)
        return WrappedNetwork.from_calico(pool, name)
Exemple #5
0
def kill_container(id_or_cid):
    c = _get_container(id_or_cid)
    c.kill()

    key = ERU_AGENT_DIE_REASON % c.container_id
    r = rds.get(key)
    rds.delete(key)
    if r is not None:
        c.set_props({'oom': 1})

    c.callback_report(status='die')

    migrate_container.apply_async(args=(c.container_id, True))

    _log.info('Kill container (container_id=%s)', c.container_id)
    return DEFAULT_RETURN_VALUE
Exemple #6
0
def kill_container(id_or_cid):
    c = _get_container(id_or_cid)
    c.kill()

    key = ERU_AGENT_DIE_REASON % c.container_id
    r = rds.get(key)
    rds.delete(key)
    if r is not None:
        c.set_props({'oom': 1})

    c.callback_report(status='die')

    migrate_container.apply_async(args=(c.container_id, True))

    _log.info('Kill container (container_id=%s)', c.container_id)
    return DEFAULT_RETURN_VALUE
Exemple #7
0
    def get_pool(self, ip):
        """ip can be either an IP or a CIDR"""
        if '/' in ip:
            try:
                ip = IPAddress(IPNetwork(ip).first)
            except (AddrFormatError, ValueError):
                return
        else:
            try:
                ip = IPAddress(ip)
            except (AddrFormatError, ValueError):
                return

        pool = _ipam.get_pool(ip)
        name = rds.get(_POOL_NAME_KEY % pool.cidr)
        return WrappedNetwork.from_calico(pool, name)
Exemple #8
0
def get_docker_certs(ip):
    """
    return valid .cert absolute file paths: (ca_path, cert_path, key_path), in
    the mean time, ensure the files are on both local and redis
    """
    results = []
    # make sure the directory for the cert files is created
    make_certs_dir(ip)
    for fname in needed_cert_files:
        file_path = make_cert_path(ip, fname)
        key = make_redis_cert_file_key(ip, fname)

        # respect redis file first, if not found, provide with local copy,
        # this could make things easier when changing certificate files
        content = rds.get(key)
        if content:
            ensure_file(file_path, mode=0444, content=content)
        else:
            with open(file_path) as f:
                rds.set(key, f.read())

        results.append(file_path)

    return results
Exemple #9
0
def get_docker_certs(ip):
    """
    return valid .cert absolute file paths: (ca_path, cert_path, key_path), in
    the mean time, ensure the files are on both local and redis
    """
    results = []
    # make sure the directory for the cert files is created
    make_certs_dir(ip)
    for fname in needed_cert_files:
        file_path = make_cert_path(ip, fname)
        key = make_redis_cert_file_key(ip, fname)

        # respect redis file first, if not found, provide with local copy,
        # this could make things easier when changing certificate files
        content = rds.get(key)
        if content:
            ensure_file(file_path, mode=0444, content=content)
        else:
            with open(file_path) as f:
                rds.set(key, f.read())

        results.append(file_path)

    return results
Exemple #10
0
 def get_props(self):
     props = rds.get(self._property_key) or '{}'
     return json.loads(props)
Exemple #11
0
 def get_props(self):
     props = rds.get(self._property_key) or '{}'
     return json.loads(props)
Exemple #12
0
def check_eip_bound(eip):
    return bool(rds.get(_EIP_BOUND_KEY % eip))
Exemple #13
0
 def _get_cores(self):
     try:
         return cPickle.loads(rds.get(self._cores_key))
     except (EOFError, TypeError):
         return {}
Exemple #14
0
def check_eip_bound(eip):
    return bool(rds.get(_EIP_BOUND_KEY % eip))
Exemple #15
0
 def _get_cores(self):
     try:
         return cPickle.loads(rds.get(self._cores_key))
     except (EOFError, TypeError):
         return {}
Exemple #16
0
 def get_all_pools(self):
     pools = _ipam.get_ip_pools(4)
     names = [rds.get(_POOL_NAME_KEY % p.cidr) for p in pools]
     return [WrappedNetwork.from_calico(p, name) for p, name in zip(pools, names)]