cluster.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:znappy 作者: eBayClassifiedsGroup 项目源码 文件源码
def action_restore(znappy, t):
    snapshots, _ = list_snapshots(znappy.cluster, t)

    # Sort by smallest amount of (absolute) "lag" to get closest snapshot
    master = sorted(snapshots.values(), key=lambda s: abs(int(t - s.time)))[0]

    print "Master host will be: {}".format(master.host.name)

    # get snapshots created before master
    snapshots, excluded = list_snapshots(znappy.cluster, master.time, before=True)
    snapshots = {h: snapshots[h] for h in snapshots if h != master.host.name}
    snapshots[master.host.name] = master
    master.host.name in excluded and excluded.pop(excluded.index(master.host.name))

    print snapshot_table(snapshots, t, excluded=excluded).get_string(sortby='host')

    choice = raw_input("Are you sure? [y/N]: ").lower()
    if choice != 'y':
        return "Aborted!"

    env.user     = raw_input('[ldap] username: ')
    env.password = getpass.getpass('[sudo] password for {}: '.format(env.user))

    if not tsudo('localhost', '/bin/true').return_code == 0:
        return 'Failed to verify credentials'

    # lock the whole cluster
    while not znappy.cluster.lock():
        time.sleep(0.5)

    # time to bork the sjit
    try:
        for host in snapshots:
            env.host_string = host
            sudo('znappy snapshot restore {0}'.format(snapshots[host].name))
    # ye it should be that easy
    except Exception, e:
        print e.message
        return "Failed to restore cluster!"

    znappy.cluster.release()

    return "cluster restore complete"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号