コード例 #1
0
def run_uptime(group):
    # 准备变量
    vars_dict = group.vars_dict

    # 创建临时目录
    TMP = settings.OPS_ROOT + '/' + str(time.time()) + '/'
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    KEY = TMP + str(time.time()) + '.key'
    write_key(group.key, KEY)

    # Playbook实例
    callback = UptimeCallback(group)
    uptime_playbook = Playbook(group, KEY, callback)
    uptime_playbook.import_vars(vars_dict)
    from manager.ansible_v2.playsource import UPTIME_PLAY_SOURCE

    UPTIME_PLAY_SOURCE[0]['hosts'] = list(
        group.hosts.filter(
            Q(_status=settings.STATUS_HOST_CAN_BE_USE)
            or Q(_status=settings.STATUS_HOST_UPTIME_ERROR)).values_list(
                'connect_ip', flat=True))

    uptime_playbook.import_task(UPTIME_PLAY_SOURCE)
    uptime_playbook.run()
コード例 #2
0
def run_ssh_check(group):
    # 准备变量
    vars_dict = group.vars_dict

    # 创建临时目录
    TMP = settings.OPS_ROOT + '/' + str(time.time()) + '/'
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    KEY = TMP + str(time.time()) + '.key'
    write_key(group.key, KEY)

    # Playbook实例
    callback = SSHCallback(group)
    ssh_playbook = Playbook(group, KEY, callback)
    ssh_playbook.import_vars(vars_dict)
    from manager.ansible_v2.playsource import PING_PLAY_SOURCE

    PING_PLAY_SOURCE[0]['hosts'] = list(
        group.hosts.exclude(
            Q(_status=settings.STATUS_HOST_PAUSE)
            or Q(_status=settings.STATUS_HOST_CLOSE)).values_list('connect_ip',
                                                                  flat=True))

    ssh_playbook.import_task(PING_PLAY_SOURCE)
    ssh_playbook.run()
コード例 #3
0
def run_uptime(group):
    # 准备变量
    vars_dict = {}

    for var in group.group_vars.all():
        vars_dict[var.key] = var.value

    if group.jumper is not None and group.key is not None:
        vars_dict['JUMPER_IP'] = group.jumper.connect_ip
        vars_dict['JUMPER_PORT'] = group.jumper.sshport

    # 创建临时目录
    TMP = settings.OPS_ROOT + '/' + str(time.time()) + '/'
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    KEY = TMP + str(time.time()) + '.key'
    write_key(group.key, KEY)

    # Playbook实例
    callback = UptimeCallback(group)
    uptime_playbook = Playbook(group, KEY, callback)
    uptime_playbook.import_vars(vars_dict)
    from manager.ansible_v2.play_source import UPTIME_PLAY_SOURCE

    UPTIME_PLAY_SOURCE[0]['hosts'] = list(
        group.hosts.exclude(
            Q(_status=settings.STATUS_HOST_PAUSE)
            or Q(_status=settings.STATUS_HOST_CLOSE)).values_list('connect_ip',
                                                                  flat=True))

    uptime_playbook.import_task(UPTIME_PLAY_SOURCE)
    uptime_playbook.run()
コード例 #4
0
def run_disk_overflow(group, RESOURCE, callback):
    # 准备变量
    vars_dict = group.vars_dict

    # 创建临时目录
    TMP = settings.OPS_ROOT + '/' + str(time.time()) + '/'
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    KEY = TMP + str(time.time()) + '.key'
    write_key(group.key, KEY)

    dof = Playbook(group, KEY, callback)
    dof.import_vars(vars_dict)

    RESOURCE[0]['hosts'] = list(
        group.hosts.filter(
            Q(_status=settings.STATUS_HOST_CAN_BE_USE)
            or Q(_status=settings.STATUS_HOST_DISK_SPACE_FULL)
            or Q(_status=settings.STATUS_HOST_DISK_INODE_FULL)).values_list(
                'connect_ip', flat=True))

    dof.import_task(RESOURCE)
    dof.run()