Exemple #1
0
 def input_finish_func(s, status, state):
     if status == 'cancel':
         return (popme, [])
     elif status == 'confirmed':
         passwd = s
         cmd = cmd_tmpl % (ssid, passwd)
         utils.run_cmd_with_timeout(cmd, 100)
         return (s2, [])
Exemple #2
0
def resolve_scratch_root(arg_scratch_root):
    scratch_root = os.environ.get('SCRATCH_ROOT')
    if not arg_scratch_root:
        if scratch_root is None:
            arg_scratch_root = os.getcwd() + "/scratch"
        else:
            # Scratch space could be mounted in a filesystem (such as NFS) on a network drive.
            # If the network is down, it could cause the access access check to hang. So run a
            # simple ls command with a timeout to prevent the hang.
            (out,
             status) = utils.run_cmd_with_timeout(cmd="ls -d " + scratch_root,
                                                  timeout=1,
                                                  exit_on_failure=0)
            if status == 0 and out != "":
                arg_scratch_root = scratch_root
            else:
                arg_scratch_root = os.getcwd() + "/scratch"
                log.warning(
                    "Env variable $SCRATCH_ROOT=\"{}\" is not accessible.\n"
                    "Using \"{}\" instead.".format(scratch_root,
                                                   arg_scratch_root))
    else:
        arg_scratch_root = os.path.realpath(arg_scratch_root)

    try:
        os.system("mkdir -p " + arg_scratch_root)
    except OSError:
        log.fatal(
            "Invalid --scratch-root=\"%s\" switch - failed to create directory!",
            arg_scratch_root)
        sys.exit(1)
    return (arg_scratch_root)
Exemple #3
0
def resolve_scratch_root(arg_scratch_root):
    scratch_root = os.environ.get('SCRATCH_ROOT')
    if not arg_scratch_root:
        if scratch_root is None:
            arg_scratch_root = DEFAULT_SCRATCH_ROOT
        else:
            # Scratch space could be mounted in a filesystem (such as NFS) on a network drive.
            # If the network is down, it could cause the access access check to hang. So run a
            # simple ls command with a timeout to prevent the hang.
            (out, status) = run_cmd_with_timeout(cmd="ls -d " + scratch_root,
                                                 timeout=1,
                                                 exit_on_failure=0)
            if status == 0 and out != "":
                arg_scratch_root = scratch_root
            else:
                arg_scratch_root = DEFAULT_SCRATCH_ROOT
                log.warning(
                    "Env variable $SCRATCH_ROOT=\"{}\" is not accessible.\n"
                    "Using \"{}\" instead.".format(scratch_root,
                                                   arg_scratch_root))
    else:
        arg_scratch_root = os.path.realpath(arg_scratch_root)

    try:
        os.makedirs(arg_scratch_root, exist_ok=True)
    except PermissionError as e:
        log.fatal("Failed to create scratch root {}:\n{}.".format(
            arg_scratch_root, e))
        sys.exit(1)

    if not os.access(arg_scratch_root, os.W_OK):
        log.fatal("Scratch root {} is not writable!".format(arg_scratch_root))
        sys.exit(1)

    return arg_scratch_root
Exemple #4
0
    def s2_key1_handler(state):
        selected = state['selected']
        conns = state['conns']
        conn_num = len(conns)

        if selected == 0:
            # 'cancel' -> s0
            new_scene = s0
        elif selected == conn_num + 1:
            # 'new connection' -> new connection scene
            new_scene = ('push', s4)
        else:
            selected_conn = conns[selected - 1]
            up = selected_conn['up']
            uuid = selected_conn['uuid']

            if up == 0:
                action = 'up'
            else:
                action = 'down'

            cmd_tmpl = 'nmcli connection %s uuid %s'
            cmd = cmd_tmpl % (action, uuid)
            code, msg = utils.run_cmd_with_timeout(cmd, 15)
            new_scene = None

        return (new_scene, [])