示例#1
0
def lips(lb, ip, lips):
    """ 配置 lb 的 lips.

    """
    # 因为改了 DNS, 先清空本地 known_hosts 文件.
    cmd = "cat /dev/null >%s" % LOCAL_SSH_KNOWN_HOSTS
    rc, so, se = utils.shell(cmd)
    if rc != 0:
        message = "clean %s failed." % LOCAL_SSH_KNOWN_HOSTS
        logger.error(message)
        return False

    message = "Waiting for network administor to change "\
                "network conf for %s" % lb
    logger.info(message)

    # 发邮件让网络工程师修改 lb 的网络配置.
    subject = u"[接入集群]请在一小时之内修改%s的网络设置, 否则集群会建立失败" % lb
    context = ""
    mail.mail(None, subject, context)

    # 检查是否能够 ping 通.
    time.sleep(120)
    checkcmd = "ping -c 3 %s &>/dev/null" % ip
    ret = utils.check_wait_null(checkcmd, timeinit=0, 
                                interval=5, timeout=3600)
    if not ret:
        logger.error("Ping failed, lb:%s, ip:%s" % (lb, ip))
        return False

    # 配置 lip.
    cmd = "sudo -i wdconfig lvsfullnat_lip"
    rc, so, se = utils.remote_cmd(ip, cmd)
    if rc != 0:
        message = "Cfg lips failed, lb:%s, error:%s" % (lb, se)
        logger.error(message)
        return False

    cmd = "cd /tmp/post_config/lvsfullnat_lip_config && "\
            "sudo sh lvsfullnat_lip_config.sh %s " % " ".join(lips)
    rc, so, se = utils.remote_cmd(ip, cmd)
    if rc != 0:
        message = "Cfg lips failed, lb:%s, error:%s" % (lb, se)
        logger.error(message)
        return False

    return True
示例#2
0
def vms(region, instance_id, num, usage, email):
    num = int(num)

    ret = requests.get(CLONE_INSTALL_SCRIPT)
    user_data = ret.text

    _time = time.strftime("%Y%m%d%H%M%S", time.localtime())
    name = "{0}-{1}".format(instance_id, _time)
    ami_id = create_ami(region, instance_id, name)
    if not ami_id:
        return False

    _instance_info = instance_info(region, instance_id)
    install_list = {
        "region": region,
        "subnet_id": _instance_info["subnet_id"],
        "instance_type": _instance_info["instance_type"],
        "key_name": _instance_info["key_name"],
        "sg_id": _instance_info["sg_id"],
        "ami_id": ami_id,
        "user_data": user_data,
        "usage": usage,        
    }

    install_lists = list()
    for i in xrange(num):
        install_lists.append(install_list)

    pool = ThreadPool(100)
    
    install_results = pool.map(vm, install_lists)

    pool.close()
    pool.join()

    subject = u"[aws]克隆实例完毕"
    context = "<br/>"
    logger.info("%s" % install_results)
    context += html.get(install_results)
    mail.mail(email, subject, context)
    logger.info("%s" % context)

    return True
示例#3
0
def vms(region, subnet_id, instance_type, volume_capacity, \
        num, usage, key_name, sg_id, email):
    num = int(num)

    ret = requests.get(POST_INSTALL_SCRIPT)
    user_data = ret.text

    install_list = {
        "region": region,
        "subnet_id": subnet_id,
        "instance_type": instance_type,
        "volume_capacity": volume_capacity,
        "usage": usage,
        "key_name": key_name,
        "sg_id": sg_id,
        "ami_id": AMI_SNAP_INFO[region]["ami_id"],
        "snap_id": AMI_SNAP_INFO[region]["snap_id"],
        "user_data": user_data
    }
    install_lists = list()
    for i in xrange(num):
        install_lists.append(install_list)

    pool = ThreadPool(100)
    
    install_results = pool.map(vm, install_lists)

    pool.close()
    pool.join()

    subject = u"[aws]您申请的机器已经创建完毕"
    context = "<br/>"
    logger.info("%s" % install_results)
    context += html.get(install_results)
    mail.mail(email, subject, context)
    logger.info("%s" % context)

    return True
示例#4
0
def main():
    while 1:
        try:
            m = client.brpop("queue:check")
            m = eval(m[1])
            check_lists = m["check_lists"]
            task_id = m["task_id"]
            email = m["email"]
    
            logger.info(
                "check_lists-%s,email-%s" % (check_lists, email))
    
            check_results = check.multi(check_lists, task_id)
    
            subject = u"""[物理装机] 您提交的检查请求已经执行完毕"""
            context = "<br/>"
            logger.info("%s" % check_results)
            context += html.get(check_results)
            mail.mail(email, subject, context)
            logger.info("mail to %s, %s" % (email, context))

        except Exception, e:
            message = traceback.format_exc()
            logger.error(message)
示例#5
0
        sources = sources + [item['source']] * len(js.TITLE)

url = makejekyll(titles,urls,sources)

# Make mobi
mb = mobi(today)
for i in range(len(titles)):
    mb.append(titles[i].decode('utf-8'),htmls[i])

mb.fetch_image()
mb.make()

#vdisk = client()
#res = vdisk.share(today + ".mobi")
#url = json.loads(res[0])['url']
status = r'#数据科学家# 数据科学家日报' + url + r' 内容摘要:'
#status = status + today + r" Kindle版 链接:" + url.decode('utf-8').encode('utf-8')
#status = status + r"内容摘要:" + ";".join(titles)a
#import time
#time.sleep(28800)
for i in range(len(urls)):
    status = status + titles[i] + r";"

post(status)
m = mail()
m.set_subject(today)
m.set_attachment(today + ".mobi")
m.set_body("")
m.sendmail()