Exemplo n.º 1
0
def remove_container_backends(container):
    """删除单个container的后端服务
    并不删除有哪些entrypoint, 这些service discovery方便知道哪些没了"""
    entrypoint_key = 'eru:app:{0}:entrypoint:{1}:backends'.format(container.appname, container.entrypoint)
    backends = container.get_backends()
    if backends:
        rds.srem(entrypoint_key, *backends)
Exemplo n.º 2
0
 def acquire_specific_ip(self, ip_str):
     """take a specific IP from network"""
     try:
         ip = ip_address(ip_str)
     except ValueError:
         return None
     if rds.sismember(self.storekey, ip._ip):
         rds.srem(self.storekey, ip._ip)
         return IP.create(ip._ip, self)
Exemplo n.º 3
0
def take_gateway(netspace, ip, host):
    net = Network.get_by_netspace(netspace)
    if not net:
        print 'net %s not found' % netspace
        return
    ipnum = int(IPv4Address(unicode(ip)))
    rds.srem(net.gatekey, ipnum)
    VLanGateway.create(ipnum, net.id, host.id)
    print '%s on %s --> %s done' % (ip, host.ip, netspace)
Exemplo n.º 4
0
 def add_ip(self, ip):
     if isinstance(ip, basestring):
         try:
             ip = IPv4Address(ip)
         except AddressValueError:
             return False
     ipnum = int(ip)
     if rds.sismember(self.gatekey, ipnum):
         rds.srem(self.gatekey, ipnum)
     rds.sadd(self.storekey, ipnum)
     return True
Exemplo n.º 5
0
def remove_container_for_agent(container):
    host = container.host
    key = 'eru:agent:{0}:containers'.format(host.name)
    rds.srem(key, container.container_id)
Exemplo n.º 6
0
        dockerjob.remove_host_containers(containers, host)
        current_flask.logger.info('Task<id=%s>: Containers (cids=%s) removed', task_id, cids)
        if rmi:
            dockerjob.remove_image(task.version, host)
    except Exception, e:
        task.finish_with_result(consts.TASK_FAILED)
        notifier.pub_fail()
        current_flask.logger.error('Task<id=%s>: Exception (e=%s)', task_id, e)
    else:
        for c in containers:
            c.delete()
        task.finish_with_result(consts.TASK_SUCCESS)
        notifier.pub_success()
        if container_ids:
            rds.srem('eru:agent:%s:containers' % host.name, *container_ids)
        rds.delete(*flags.keys())
        current_flask.logger.info('Task<id=%s>: Done', task_id)

@current_app.task()
def create_containers_with_macvlan(task_id, ncontainer, nshare, cores, network_ids, spec_ips=None):
    """
    执行task_id的任务. 部署ncontainer个容器, 占用*_core_ids这些核, 绑定到networks这些子网
    """
    #TODO support part core
    current_flask.logger.info('Task<id=%s>: Started', task_id)
    task = Task.get(task_id)
    if not task:
        current_flask.logger.error('Task (id=%s) not found, quit', task_id)
        return
Exemplo n.º 7
0
        dockerjob.remove_host_containers(containers, host)
        current_flask.logger.info("Task<id=%s>: Containers (cids=%s) removed", task_id, cids)
        if rmi:
            dockerjob.remove_image(task.version, host)
    except Exception, e:
        task.finish_with_result(consts.TASK_FAILED)
        notifier.pub_fail()
        current_flask.logger.error("Task<id=%s>: Exception (e=%s)", task_id, e)
    else:
        for c in containers:
            c.delete()
        task.finish_with_result(consts.TASK_SUCCESS)
        notifier.pub_success()
        if container_ids:
            rds.srem("eru:agent:%s:containers" % host.name, *container_ids)
        rds.delete(*flags.keys())
        current_flask.logger.info("Task<id=%s>: Done", task_id)


@current_app.task()
def create_containers_with_macvlan(task_id, ncontainer, nshare, cores, network_ids, spec_ips=None):
    """
    执行task_id的任务. 部署ncontainer个容器, 占用*_core_ids这些核, 绑定到networks这些子网
    """
    # TODO support part core
    current_flask.logger.info("Task<id=%s>: Started", task_id)
    task = Task.get(task_id)
    if not task:
        current_flask.logger.error("Task (id=%s) not found, quit", task_id)
        return