コード例 #1
0
def parse_items(result_set):
    items = []
    from com.ziclix.python.sql import DataHandler
    data_handler = DataHandler()
    try:
        meta_data = result_set.getMetaData()
        while result_set.next():
            attr_name_to_value = {}
            for column_number in range(1, meta_data.getColumnCount() + 1):

                column_type = meta_data.getColumnType(column_number)

                value = None
                try:
                    value = data_handler.getPyObject(_ResultSet(result_set),
                                                     column_number,
                                                     column_type)
                except:
                    column_type_ = meta_data.getColumnTypeName(column_number)
                    errorMessage = ('Unrecognized column type %s (%d), '
                                    'scipping' % (column_type_, column_number))
                    logger.debugException(errorMessage)

                column_name = meta_data.getColumnName(column_number)
                attr_name_to_value[column_name] = value

            items.append(_Item(**attr_name_to_value))
    except SQLException:
        logger.debugException('Failed to process result set')
        raise command.ExecuteException('Failed to execute sql query')
    safeFn(result_set.close)()
    return items
コード例 #2
0
    def get_platform(self, shell):

        if shell.getClientType() == 'ssh':
            cmd = 'uname -a'
        else:
            cmd = 'uname'

        output = shell.execCmd(cmd)
        if shell.getLastCmdReturnCode() != 0:
            raise command.ExecuteException('Non zero return code')
        if output:
            osname = None
            if output.find('SunOS') != -1:
                osname = 'SunOS'
            elif output.find('VMkernel') != -1:
                osname = 'VMkernel'
            elif output.find('Linux') != -1:
                osname = 'Linux'
            elif output.find('FreeBSD') != -1:
                osname = 'FreeBSD'
            elif output.find('HP-UX') != -1:
                osname = 'HP-UX'
            elif output.find('AIX') != -1:
                osname = 'AIX'
            elif output.find('Darwin') != -1:
                osname = 'MacOs'
            elif output.find('OpenBSD') != -1:
                osname = 'OpenBSD'
            else:
                logger.debug('unknown OS: ' + output)
            return osname and os_platform_discoverer.enum.by_name(osname)
コード例 #3
0
def get_socket_descriptors(shell):
    r'''
    Discovers pid, local_addr, local_port, is_listen, protocol_type,
    remote_addr, remote_port using pfiles command for all the processes

    shellutils.Shell -> list[(str?, (str?, str?, bool?, int?, str?, str?))]
    @raise ValueError: if no shell passed
    @raise command.ExecutionException: on command execution failure
    @raise com.hp.ucmdb.discovery.library.clients.protocols.command.TimeoutException: on command timeout
    '''
    if not shell:
        raise ValueError('Invalid shell')

    marker = '_next_pid_marker_'
    cmdLine = (
        'for i in '
        '`ps -e|awk \'{if($4 != "<defunct>") if($1 != "PID") print $1}\'`;\n '
        'do '
        'echo %s$i; '
        'nice pfiles $i 2>&1|awk "/S_ISSOCK|S_IFSOCK|SOCK_STREAM|SOCK_DGRAM|port/ { print }"; '
        'done' % marker)

    result = []
    output = shell.execCmd(cmdLine, shell.getDefaultCommandTimeout() * 4)
    if shell.getLastCmdReturnCode() != 0:
        raise command.ExecuteException()

    for pid, socket_descriptor in _parse_socket_descriptors(output, marker):
        local_ip, local_port, is_listen, protocol_type, _, _ = socket_descriptor
        if local_ip and local_port is not None and is_listen is not None and protocol_type:
            result.append((pid, socket_descriptor))
    return result
コード例 #4
0
def raise_on_none_resultset(result):
    if not result.result_set:
        raise command.ExecuteException(
            'Failed to execute sql query'
            'Result set is null', result)
    return result
コード例 #5
0
def raise_on_error(result):
    if result.exception:
        raise command.ExecuteException('Failed to execute sql query', result)
    return result
コード例 #6
0
def raise_on_exception(result):
    if result.exception:
        raise command.ExecuteException(result.exception.getMessage(), result)
    return result