Exemplo n.º 1
0
def export_zpools():
    ''' Export all imported pools

    '''
    zpool_list = pool_list("status")
    for name in zpool_list:
        exec_cmd_outputs_to_log(["/usr/sbin/zpool", "export", name], logging)
Exemplo n.º 2
0
def get_zpool_free_size(name):
    '''Return free size, available for pool's top-level filesystem.
    Pool is imported if necessary
    '''

    status = exec_cmd_outputs_to_log(["/usr/sbin/zpool", "list", name],
                                     logging)
    if status != 0:
        status = exec_cmd_outputs_to_log(
            ["/usr/sbin/zpool", "import", "-N", name], logging)
        if status != 0:
            logging.warning(("Couldn't import pool %s, "
                             "you can try to run "
                             "\"zpool import -Nf %s\" "
                             "before proceeding"), name, name)

    if status == 0:
        try:
            argslist = [
                "/usr/sbin/zfs", "get", "-Hp", "-o", "value", "available", name
            ]
            (zfsout, zfserr) = Popen(argslist, stdout=PIPE,
                                     stderr=PIPE).communicate()
        except OSError, err:
            logging.error("OSError occured during zfs call: %s", err)
            return -1

        if zfserr:
            logging.error("Error occured during zpool call: %s", zfserr)
            return -1

        return int(zfsout)
Exemplo n.º 3
0
def get_zpool_be_names(name):
    ''' Return list of names which seem to be names of zpool boot environments.
    Pool is imported if necessary
    '''
    be_names = list()
    prefix = "%s/ROOT" % (name)
    status = exec_cmd_outputs_to_log(["/usr/sbin/zpool", "list", name],
                                     logging)
    if status != 0:
        status = exec_cmd_outputs_to_log(
            ["/usr/sbin/zpool", "import", "-N", name], logging)
        if status != 0:
            logging.warning(("Couldn't import pool %s, "
                             "you can try to run "
                             "\"zpool import -Nf %s\" "
                             "before proceeding"), name, name)

    if status == 0:
        try:
            argslist = [
                "/usr/sbin/zfs", "list", "-t", "filesystem", "-d", "1", "-H",
                "-o", "name", "-r", prefix
            ]
            (zfsout, zfserr) = Popen(argslist,
                                     stdout=PIPE,
                                     universal_newlines=True,
                                     stderr=PIPE).communicate()
        except OSError as err:
            logging.error("OSError occured during zfs call: %s", err)
            return be_names

        if zfserr:
            logging.error("Error occured during zfs call: %s", zfserr)
            return be_names

        line = zfsout.splitlines(False)
        for entry in line:
            prefix_slash = "%s/" % (prefix)
            if entry.startswith(prefix_slash):
                be_names.append(entry.split(prefix_slash)[1])

    return be_names
Exemplo n.º 4
0
def exec_cmd(cmd, description):
    ''' Execute the given command.

        Args:
            cmd: Command to execute.  The command and it's arguments
		 should be provided as a list, suitable for used
		 with subprocess.Popen(shell=False)
            description: Description to use for printing errors.

        Raises:
            InstallationError
    
    '''
    logging.debug("Executing: %s", " ".join(cmd))
    if exec_cmd_outputs_to_log(cmd, logging) != 0:
        logging.error("Failed to %s", description)
        raise ti_utils.InstallationError
Exemplo n.º 5
0
def exec_cmd(cmd, description):
    ''' Execute the given command.

        Args:
            cmd: Command to execute.  The command and it's arguments
		 should be provided as a list, suitable for used
		 with subprocess.Popen(shell=False)
            description: Description to use for printing errors.

        Raises:
            InstallationError
    
    '''
    logging.debug("Executing: %s", " ".join(cmd))
    if exec_cmd_outputs_to_log(cmd, logging) != 0:
        logging.error("Failed to %s", description)
        raise ti_utils.InstallationError