예제 #1
0
def find(executor, alternatives=None):
    '''Finds lsdev binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lsdev command implementation
    @rtype: lsdev.Cmd
    @raise command.NotFoundException: in case if `lsdev` command is not available
    @raise service_loader.NoImplementationException: in case if no `lsdev` wrapper available
    '''
    alternatives = alternatives or bin_alternatives

    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException(
            'No lsdev binary found among provided path alternatives.')

    lsdev_impls = service_loader.global_lookup[Cmd]
    for lsdev_impl in lsdev_impls:
        if Sfn(lsdev_impl.is_applicable)(bin, executor):
            return partial(lsdev_impl, bin=bin)
    raise service_loader.NoImplementationException('No lsdev impl found')
예제 #2
0
def find(executor, alternatives=None):
    '''Finds vmkmgmt_keyval binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: vmkmgmt_keyval command implementation
    @rtype: vmkmgmt_keyval.Cmd
    @raise command.NotFoundException: in case if `vmkmgmt_keyval` command is not available
    @raise service_loader.NoImplementationException: in case if no `vmkmgmt_keyval` wrapper available
    '''
    alternatives = alternatives or bin_alternatives

    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException(
            'No vmkmgmt_keyval binary found among provided path alternatives')

    vmkmgmt_keyval_impls = (Cmd, )
    for vmkmgmt_keyval_impl in vmkmgmt_keyval_impls:
        if Sfn(vmkmgmt_keyval_impl.is_applicable)(bin, executor):
            return partial(vmkmgmt_keyval_impl, bin=bin)
    raise service_loader.NoImplementationException(
        'No vmkmgmt_keyval impl found')
예제 #3
0
def find(executor, alternatives=None):
    '''Finds lscfg binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lscfg command implementation
    @rtype: lscfg_aix.Cmd
    @raise command.NotFoundException: in case if `lscfg`
                                        command is not available
    @raise service_loader.NoImplementationException: in case if no
                                                    `lscfg` wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)
    if not bin:
        raise command.NotFoundException('No lscfg binary found')

    lscfg_impls = [Cmd, ]
    for lscfg_impl in lscfg_impls:
        if lscfg_impl.is_applicable(bin, executor):
            return partial(lscfg_impl, bin=bin)
    raise service_loader.NoImplementationException('No lscfg impl found')
예제 #4
0
def find_first(alternatives, executor):
    '''Finds first binary among provided alternatives that is available on
    target destination or None if no binary available

    @param alternatimes: sequence o binaries to search for availability
    @param alternatives: seq[basestring]
    @param executor: a command executor instance
    @type executor: command.Executor
    @return: first binary available on target destination
    @rtype: basestring or None
    @raise service_loader.NoImplementationException: in case if
        no is_command_available.Discoverer implementation found
        to perform a check
    '''
    def is_command_available(bin):
        is_available_cmd = Discoverer.find_impl(bin, executor)
        return is_available_cmd.is_available(bin, executor)

    has_at_least_one_implementation = False
    for alternative in alternatives:
        try:
            if is_command_available(alternative):
                return alternative
            has_at_least_one_implementation = True
        except service_loader.NoImplementationException:
            pass
    if not has_at_least_one_implementation:
        raise service_loader.NoImplementationException(
            'No is_command_available impl found')
예제 #5
0
def find(executor, alternatives=None):
    '''Finds lsdev binary and creates vio lsdev wrapper on success

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lsdev command implementation
    @rtype: lsdev_aix_vio_server_impl.Cmd
    @raise command.NotFoundException: in case if `lsdev` command
                                        is not available
    @raise service_loader.NoImplementationException: in case if no `lsdev`
                                                        wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException('No lsdev binary found')

    lsdev_impl = Cmd
    if lsdev_impl.is_applicable(bin, executor):
        return partial(lsdev_impl, bin=bin)
    raise service_loader.NoImplementationException('No lsdev impl found')
예제 #6
0
def find(executor, alternatives=None):
    '''Finds fcinfo binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: fcinfo command implementation
    @rtype: fcinfo_solaris.Cmd
    @raise command.NotFoundException: in case if `fcinfo`
                                        command is not available
    @raise service_loader.NoImplementationException: in case if no
                                                    `fcinfo` wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)
    if not bin:
        raise command.NotFoundException('No fcinfo binary found')

    fcinfo_impls = [
        Cmd,
    ]
    for fcinfo_impl in fcinfo_impls:
        if fcinfo_impl.is_applicable(bin, executor):
            return partial(fcinfo_impl, bin=bin)
    raise service_loader.NoImplementationException('No fcinfo impl found')
예제 #7
0
파일: pdadmin.py 프로젝트: deezeesms/dd-git
    def find(tools):
        impls = service_loader.global_lookup[Cmd]
        for impl in impls:
            is_applicable = webseal_wiring.wired()(impl.is_applicable)
            if Sfn(is_applicable)(**tools):
                return impl.create(**tools)

        raise service_loader.NoImplementationException('No pdadmin impl found')
예제 #8
0
    def find_impl(cls, executor):
        '''Finds implementation of vital_product_data.Discoverer for current
        destination

        @param param: a command executor instance
        @type executor: command.Executor
        @return: implementation of vpd discoverer applicable for current
                destination
        @rtype: vital_product_data.Discoverer
        @raise service_loader.NoImplementationException: if no implementation
                found
        '''
        p = os_platform_discoverer.discover_platform_by_shell(executor.shell)
        vpd_impls = service_loader.global_lookup[Discoverer]
        for vpd_impl in vpd_impls:
            if Sfn(vpd_impl.is_applicable)(p, executor):
                return vpd_impl
        raise service_loader.NoImplementationException('No lsdev impl found')
예제 #9
0
    def find_impl(bin, executor):
        '''Finds implementation of is_command_available.Discoverer for current
        destination

        @param bin: path to binary
        @type bin: basestring
        @param param: a command executor instance
        @type executor: command.Executor
        @return: implementation of discoverer applicable for current
                destination
        @rtype: is_command_available.Discoverer
        @raise service_loader.NoImplementationException: if no implementation
                found
        '''
        impls = service_loader.global_lookup[Discoverer]
        executor = executor(useCache=1)
        for impl in impls:
            if Sfn(impl.is_applicable)(bin, executor):
                return impl
        raise service_loader.NoImplementationException(
            'No is_command_available impl found')
예제 #10
0
def find(executor, alternatives=None):
    '''Finds fcstat binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: fcstat command implementation
    @rtype: fcstat.Cmd
    @raise command.NotFoundException: in case if `fcstat` command is not available
    @raise service_loader.NoImplementationException: in case if no `fcstat` wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)
    if not bin:
        raise command.NotFoundException(
            'No fcstat binary found among provided path alternatives.')

    if Sfn(Cmd.is_applicable)(bin, executor):
        return partial(Cmd, bin)
    else:
        raise service_loader.NoImplementationException('No fcstat impl found')