Ejemplo n.º 1
0
def nodes(hostname):
    end = datetime.utcnow()
    start = end - timedelta(minutes=60)

    node = Node.get_by_name(hostname)
    if node is None:
        raise APIError('Unknown node', 404)

    if node.state != NODE_STATUSES.completed:
        raise NodeNotRunning

    resources = node_utils.get_one_node(node.id)['resources']

    if resources:
        data = kubestat.get_node_stat(hostname, start, end)
        cpu_capacity = float(resources.get('cpu')) * 1000
        memory_capacity = float(resources.get('memory'))
    else:
        # We have checked that node is running, but no resources means
        # that node is not running
        raise InternalStatsError(
            'DBNode is running, but k8s says it does not. Unknown error')

    diagrams = [
        CpuDiagram(_get_cpu_points(data, cpu_capacity)).to_dict(),
        MemoryDiagram(_get_memory_points(data, memory_capacity)).to_dict(),
        NetworkDiagram(_get_network_points(data)).to_dict()
    ] + [
        FsDiagram(fs_data['points'], title=fs_data['device']).to_dict()
        for fs_data in _get_fs_points(data)
    ]
    return diagrams
Ejemplo n.º 2
0
def wait_for_nodes(nodes_list, timeout, verbose=False):
    timeout = timeout or WAIT_TIMEOUT

    def _print(msg):
        if verbose:
            print msg

    wait_end = time.time() + timeout
    host_list = list(set(nodes_list))
    nodes_in_trouble = {}

    while host_list:
        if time.time() > wait_end:
            remaining_nodes = [Node.get_by_name(nhost) for nhost in nodes_list]
            raise WaitTimeoutException(
                "These nodes did not become 'running' in a given "
                "timeout {}s:\n{}".format(timeout, remaining_nodes))

        time.sleep(WAIT_RETRY_DELAY)

        db.session.expire_all()
        for nhost in host_list[:]:  # Do not modify list while iterating it
            db_node = Node.get_by_name(nhost)
            if db_node is None:
                raise WaitTimeoutException("Node `%s` was not found." % nhost)
            k8s_node = get_one_node(db_node.id)
            state = k8s_node['status']
            if state == NODE_STATUSES.troubles:
                if nhost not in nodes_in_trouble:
                    nodes_in_trouble[nhost] = time.time() + WAIT_TROUBLE_TIMEOUT
                if time.time() > nodes_in_trouble[nhost]:
                    raise WaitTroubleException(
                        "Node '{}' went into troubles and still in troubles "
                        "state after '{}' seconds.".format(
                            nhost, WAIT_TROUBLE_TIMEOUT))
                else:
                    _print("Node '{}' state is 'troubles' but acceptable "
                           "troubles timeout '{}'s is not reached yet..".format(
                               nhost, WAIT_TROUBLE_TIMEOUT))
            elif state == NODE_STATUSES.running:
                host_list.remove(nhost)
            else:
                _print("Node '{}' state is '{}', continue waiting..".format(
                    nhost, state))
Ejemplo n.º 3
0
 def run(self, nodename, flagname, value, delete):
     node = Node.get_by_name(nodename)
     if not node:
         raise InvalidCommand(u'Node "{0}" not found'.format(nodename))
     if delete:
         NodeFlag.delete_by_name(node.id, flagname)
         print u'Node flag "{0}" was deleted'.format(flagname)
         return
     NodeFlag.save_flag(node.id, flagname, value)
     if flagname == NodeFlagNames.CEPH_INSTALLED:
         tasks.add_k8s_node_labels(
             node.hostname,
             {NODE_CEPH_AWARE_KUBERDOCK_LABEL: "True"}
         )
         check_namespace_exists(node.ip)
     print u'Node "{0}": flag "{1}" was set to "{2}"'.format(
         nodename, flagname, value)
Ejemplo n.º 4
0
 def run(self, nodename):
     node = Node.get_by_name(nodename)
     if not node:
         raise InvalidCommand(u'Node "{0}" not found'.format(nodename))
     print json.dumps(node.to_dict())