Exemplo n.º 1
0
def get_nfs_export_path_list(host_or_ip):
    path_list = []
    
    cmd = ['/sbin/showmount', '-e', host_or_ip]
    logger.info("use showmount to get NFS export paths:")
    if os.getuid()!=0:
        cmd = ['/usr/bin/sudo',] + cmd
        logger.info("/usr/bin/sudo /sbin/showmount -e %s" % host_or_ip)
    else:
        logger.info("/sbin/showmount -e %s" % host_or_ip)
    
    try:
        results = process.run_program_and_capture_results(cmd, None, logger, expected_rcs=[0])
        for line in results.split('\n'):
            line = line.strip()
            if line.startswith('/'):
                path_list.append(line)
    
    except process.SubprocBadRcError, e:
        # check the various error codes
        if e.rc==110:
            ue = convert_exc_to_user_error(sys.exc_info(),
                                           errors[ERR_CONN_TIMEOUT],
                                           msg_args={'host':host_or_ip})
        else:
            ue = convert_exc_to_user_error(sys.exc_info(),
                                           errors[ERR_NFS_LIST_EXC],
                                           msg_args={"host":host_or_ip,
                                                     "exc":"%s(%s)" % (e.__class__.__name__,
                                                                       unicode(e))})
        raise ue
Exemplo n.º 2
0
 def run_smbinfo(credentials_file):
     with capture_logging(logging.getLogger()) as l:
         r = re.compile(re.escape("Share: ") + r'(.+)$')
         shares = []
         cmd = [smbinfo, '-a', credentials_file, 'list-shares', host_or_ip]
         if os.getuid()!=0:
             cmd = ['/usr/bin/sudo',] + cmd
         try:
             results = process.run_program_and_capture_results(cmd, None, logger, expected_rcs=[0])
             for line in results.split('\n'):
                 mo = r.match(line)
                 if mo!=None:
                     shares.append(mo.group(1))
         except process.SubprocBadRcError, e:
             # check the various error codes
             if e.rc==4:
                 ue = convert_exc_to_user_error(sys.exc_info(),
                                                errors[ERR_SHARE_LIST_PERM],
                                                msg_args={'host':host_or_ip})
             elif e.rc==110:
                 ue = convert_exc_to_user_error(sys.exc_info(),
                                                errors[ERR_SHARE_CONN_TIMEOUT],
                                                msg_args={'host':host_or_ip})
             else:
                 ue = convert_exc_to_user_error(sys.exc_info(),
                                                errors[ERR_SHARE_LIST_EXC],
                                                msg_args={"host":host_or_ip,
                                                          "exc":"%s(%s)" % (e.__class__.__name__,
                                                                            unicode(e))})
             ue.developer_msg = l.getvalue()
             raise ue
         except Exception, e:
             ue = convert_exc_to_user_error(sys.exc_info(),
                                            errors[ERR_SHARE_LIST_EXC],
                                            msg_args={"host":host_or_ip,
                                                      "exc":"%s(%s)" % (e.__class__.__name__,
                                                                        unicode(e))})
             ue.developer_msg = l.getvalue()
             raise ue
Exemplo n.º 3
0
        "The Crypto python module (www.pycrypto.org) is required, but either not installed or installed incorrectly. The python used was at '%(py)s'. The error thrown when attempting to import it was '%(exc)s'"
    ),
)


# Import the crypto libraries. These are not set up by default on
try:
    import Crypto
    from Crypto.Cipher import AES

    logger.debug("Imported Crypto module successfully.")
except ImportError:
    (et, ev, tb) = sys.exc_info()
    logger.exception("Unable to import Crypto.Cipher.AES")
    exc = convert_exc_to_user_error(
        (et, ev, tb), errors[ERR_PW_PYCRYPTO], msg_args={"exc": "%s(%s)" % (et.__name__, str(ev)), "py": sys.executable}
    )
    exc.developer_msg = "If on MacOSX, and you are having trouble installing pycrypto, take a look at http://mike.pirnat.com/2011/02/08/building-pycrypto-on-snow-leopard-and-non-apple-python/"
    raise exc


#
# Constants
#

# length of key to use
KEY_LENGTH = 32

# key length must be a multiple of the following AES-specfic value
KEY_MOD = 16
# length of data passed to low level encryption alg. must be a multiple of the following AES-specific value
Exemplo n.º 4
0
        # check the various error codes
        if e.rc==110:
            ue = convert_exc_to_user_error(sys.exc_info(),
                                           errors[ERR_CONN_TIMEOUT],
                                           msg_args={'host':host_or_ip})
        else:
            ue = convert_exc_to_user_error(sys.exc_info(),
                                           errors[ERR_NFS_LIST_EXC],
                                           msg_args={"host":host_or_ip,
                                                     "exc":"%s(%s)" % (e.__class__.__name__,
                                                                       unicode(e))})
        raise ue
    except Exception, e:
        ue = convert_exc_to_user_error(sys.exc_info(),
                                       errors[ERR_NFS_LIST_EXC],
                                       msg_args={"host":host_or_ip,
                                                 "exc":"%s(%s)" % (e.__class__.__name__,
                                                                   unicode(e))})
        raise ue
    
    return path_list

def get_mounted_filesystems():
    """Call df and parse the output (which is tricky).
    """
    if sys.platform=='darwin':
        BLOCKSIZE = 512L
    else: # linux
        BLOCKSIZE = KB
    result = process.run_program_and_capture_results(['/bin/mount',], None, logger)
    rows = result.split('\n')