Exemple #1
0
def get_claymore_stats(ip):
    """
    Get the statistics for a Claymore Miner

    Returns:
        dict
    """

    port = flask_app.config.get("MINER_API_PORTS_CLAYMORE_PORT")
    cgminer = CgminerAPI(host=ip, port=port, payload_command="method")
    output = cgminer.miner_getstat1()
    output.update({"IP": ip})
    return dict(output)
Exemple #2
0
def get_pools(ip):
    """
    Get the output from miner "pools()" command.
    Works with most CGMiner miners.

    Returns:
        dict
    """

    cgminer = CgminerAPI(host=ip)
    output = cgminer.pools()
    output.update({"IP": ip})
    return dict(output)
Exemple #3
0
def get_baikal_devs(ip):
    """
    Get the board statistics for a Baikal Miner.

    Returns:
        dict
    """

    port = flask_app.config.get("MINER_API_PORTS_BAIKAL_PORT")
    cgminer = CgminerAPI(host=ip, port=port, payload_command="command")
    output = cgminer.devs()
    output.update({"IP": ip})
    return dict(output)
Exemple #4
0
def get_avalon_devs(ip):
    """
    Retrieves statistics for Avalon Miners attached to the controller

    Returns:
        dict
    """

    port = flask_app.config.get("MINER_API_PORTS_AVALON_PORT")
    cgminer = CgminerAPI(host=ip, port=port, payload_command="command")
    output = cgminer.devs()
    output.update({"IP": ip})
    return dict(output)
Exemple #5
0
def get_summary(ip):
    """
    Get the output from miner "summary()" command.

    Returns:
        dict
    """

    # works with most CGMiner Miners
    cgminer = CgminerAPI(host=ip)
    output = cgminer.summary()
    output.update({"IP": ip})
    return dict(output)
Exemple #6
0
def get_antminer_stats(ip):
    """
    Retrieves statistics for an Antminer Miner

    Returns:
        dict
    """

    port = flask_app.config.get("MINER_API_PORTS_ANTMINER_PORT")
    cgminer = CgminerAPI(host=ip, port=port, payload_command="command")
    output = cgminer.stats()
    output.update({"IP": ip})
    return dict(output)
Exemple #7
0
def get_cgminer_devs(ip):
    """
    Retrieves boards statistics for Miners using generic CGMiner API and Port

    Returns:
        dict
    """

    port = flask_app.config.get("MINER_API_PORTS_CGMINER_PORT")
    cgminer = CgminerAPI(host=ip, port=port, payload_command="command")
    output = cgminer.devs()
    output.update({"IP": ip})
    return dict(output)
Exemple #8
0
def restart_claymore_miner(ip):
    """
    Sends a command to restart a Claymore Miner

    Returns:
        dict - containing success or failure
    """

    port = flask_app.config.get("MINER_API_PORTS_CLAYMORE_PORT")
    cgminer = CgminerAPI(host=ip, port=port, payload_command="method")
    output = cgminer.miner_restart()
    output.update({"IP": ip})
    return dict(output)
Exemple #9
0
def get_claymore_configfile(ip, filename):
    """
    Get the configuration file for a Claymore Miner

    Returns:
        dict
    """

    port = flask_app.config.get("MINER_API_PORTS_CLAYMORE_PORT")
    cgminer = CgminerAPI(host=ip,
                         port=port,
                         payload_command="method",
                         parameter_argument="params",
                         encapsulate_args=True)
    output = cgminer.miner_getfile(filename)
    output.update({"IP": ip})
    return dict(output)
Exemple #10
0
def get_type(ip, port):
    """
    Attempts to try to get the type of miner from the stats command

    Returns:
        String - if miner type is found
        None - if command failed

    """

    cgminer = CgminerAPI(host=ip, port=port, payload_command="command")
    output = cgminer.stats()
    miner_type = None
    try:
        miner_type = output['STATS'][0]['Type']
    except:
        pass

    if miner_type is None:
        pass
    else:
        pass

    return miner_type
    def contact(self, passed_args):

        # init defaults
        ip = '127.0.0.1'
        port = 4028
        api_command = None
        payload_command = "command"
        has_summary = True
        has_devs = False
        has_pools = True
        has_stats = True
        has_getstat1 = False

        # build a parser
        parser = self.__build_arg_parser()

        # parse the args
        if passed_args is not None:
            args = parser.parse_args(passed_args)
        else:
            # will take sys.argv by default
            args = parser.parse_args()

        if args.ip:
            ip = args.ip

        if args.port:
            port = args.port

        if args.cmd:
            api_command = args.cmd

        if args.plcmd:
            payload_command = args.plcmd

        if args.antminer:
            # defaults should work
            pass

        if args.baikal:
            has_stats = False
            has_devs = True

        if args.avalon:
            has_stats = True
            has_summary = True
            has_devs = True
            has_pools = True

        if args.claymore:
            payload_command = "method"
            has_devs = False
            has_stats = False
            has_getstat1 = True
            has_pools = False
            has_summary = False
            port = 3333

        # now execute the API calls
        cgminer = CgminerAPI(host=ip,
                             port=port,
                             payload_command=payload_command)

        ts = time.time()
        st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')

        print(
            "---------- MINER DUMPER OUTPUT ON IP {} PORT {} at {} ----------".
            format(ip, port, st))

        if api_command is not None:

            # call only that one
            output = self.__do_miner_api_call(cgminer, api_command, None)

        else:

            if has_stats:
                try:
                    self.__do_miner_api_call(cgminer, 'stats', None)
                except:
                    pass

            if has_devs:
                try:
                    self.__do_miner_api_call(cgminer, 'devs', None)
                except:
                    pass

            if has_summary:
                try:
                    self.__do_miner_api_call(cgminer, 'summary', None)
                except:
                    pass

            if has_getstat1:
                try:
                    self.__do_miner_api_call(cgminer, 'miner_getstat1', None)
                except:
                    pass

            if has_pools:
                try:
                    self.__do_miner_api_call(cgminer, 'pools', None)
                except:
                    pass