Send our information to a remote nago instance

    Arguments:
        node -- node_name or token for the node this data belongs to
962627
def send(node_name):
    
    my_data = nago.core.get_my_info()
    if not node_name:
        node_name = nago.settings.get('server')
    node = nago.core.get_node(node_name)
    json_params = {}
    json_params['node_name'] = node_name
    json_params['key'] = "node_info"
    for k, v in my_data.items():
        nago.core.log("sending %s to %s" % (k, node['host_name']), level="notice")
        json_params[k] = v
    return node.send_command('info', 'post', node_name=node.token, key="node_info", **my_data)
1317088
async def send_cluster_commands(self, stack, raise_on_error=True, allow_redirections=True):
        
        # the first time sending the commands we send all of the commands that were queued up.
        # if we have to run through it again, we only retry the commands that failed.
        attempt = sorted(stack, key=lambda x: x.position)

        # build a list of node objects based on node names we need to
        nodes = {}

        # as we move through each command that still needs to be processed,
        # we figure out the slot number that command maps to, then from the slot determine the node.
        for c in attempt:
            # refer to our internal node -> slot table that tells us where a given
            # command should route to.
            slot = self._determine_slot(*c.args)
            node = self.connection_pool.get_node_by_slot(slot)

            # little hack to make sure the node name is populated. probably could clean this up.
            self.connection_pool.nodes.set_node_name(node)

            # now that we know the name of the node ( it's just a string in the form of host:port )
            # we can build a list of commands for each node.
            node_name = node['name']
            if node_name not in nodes:
                nodes[node_name] = NodeCommands(self.parse_response, self.connection_pool.get_connection_by_node(node))

            nodes[node_name].append(c)

        # send the commands in sequence.
        # we  write to all the open sockets for each node first, before reading anything
        # this allows us to flush all the requests out across the network essentially in parallel
        # so that we can read them all in parallel as they come back.
        # we dont' multiplex on the sockets as they come available, but that shouldn't make too much difference.
        node_commands = nodes.values()
        for n in node_commands:
            await n.write()

        for n in node_commands:
            await n.read()

        # release all of the redis connections we allocated earlier back into the connection pool.
        # we used to do this step as part of a try/finally block, but it is really dangerous to
        # release connections back into the pool if for some reason the socket has data still left in it
        # from a previous operation. The write and read operations already have try/catch around them for
        # all known types of errors including connection and socket level errors.
        # So if we hit an exception, something really bad happened and putting any of
        # these connections back into the pool is a very bad idea.
        # the socket might have unread buffer still sitting in it, and then the
        # next time we read from it we pass the buffered result back from a previous
        # command and every single request after to that connection will always get
        # a mismatched result. (not just theoretical, I saw this happen on production x.x).
        for n in nodes.values():
            self.connection_pool.release(n.connection)

        # if the response isn't an exception it is a valid response from the node
        # we're all done with that command, YAY!
        # if we have more commands to attempt, we've run into problems.
        # collect all the commands we are allowed to retry.
        # (MOVED, ASK, or connection errors or timeout errors)
        attempt = sorted([c for c in attempt if isinstance(c.result, ERRORS_ALLOW_RETRY)], key=lambda x: x.position)
        if attempt and allow_redirections:
            # RETRY MAGIC HAPPENS HERE!
            # send these remaing comamnds one at a time using `execute_command`
            # in the main client. This keeps our retry logic in one place mostly,
            # and allows us to be more confident in correctness of behavior.
            # at this point any speed gains from pipelining have been lost
            # anyway, so we might as well make the best attempt to get the correct
            # behavior.
            #
            # The client command will handle retries for each individual command
            # sequentially as we pass each one into `execute_command`. Any exceptions
            # that bubble out should only appear once all retries have been exhausted.
            #
            # If a lot of commands have failed, we'll be setting the
            # flag to rebuild the slots table from scratch. So MOVED errors should
            # correct themselves fairly quickly.
            await self.connection_pool.nodes.increment_reinitialize_counter(len(attempt))
            for c in attempt:
                try:
                    # send each command individually like we do in the main client.
                    c.result = await super(StrictClusterPipeline, self).execute_command(*c.args, **c.options)
                except RedisError as e:
                    c.result = e

        # turn the response back into a simple flat array that corresponds
        # to the sequence of commands issued in the stack in pipeline.execute()
        response = [c.result for c in sorted(stack, key=lambda x: x.position)]

        if raise_on_error:
            self.raise_first_error(stack)

        return response
1016794
def enable_node(self, service_name, node_name):
        
        logger.info("Enabling server %s/%s", service_name, node_name)
        return self.send_command(
            "enable server %s/%s" % (service_name, node_name)
        )
27831
def node_cmd(cmd_name, node_dict):
    """"""
    sc = {"run": cmd_startstop, "stop": cmd_startstop,
          "connect": cmd_connect, "details": cmd_details}
    node_num = node_selection(cmd_name, len(node_dict))
    refresh_main = None
    if node_num != 0:
        (node_valid, node_info) = node_validate(node_dict, node_num, cmd_name)
        if node_valid:
            sub_cmd = sc[cmd_name]  # get sub-command
            refresh_main = sub_cmd(node_dict[node_num], cmd_name, node_info)
        else:  # invalid target
            ui_print_suffix(node_info, C_ERR)
            sleep(1.5)
    else:  # '0' entered - exit command but not program
        ui_print(" - Exit Command")
        sleep(0.5)
    return refresh_main
762539
def addNode(self, node):
        
        LOGGER.info('Adding node {}({})'.format(node.name, node.address))
        message = {
            'addnode': {
                'nodes': [{
                    'address': node.address,
                    'name': node.name,
                    'node_def_id': node.id,
                    'primary': node.primary,
                    'drivers': node.drivers,
                    'hint': node.hint
                }]
            }
        }
        self.send(message)
786217
def addNode(self, node: Node):
        
        self._nodes[node.id] = node
        req = node.ledgerRequest()
        if req:
            self.pendRequest(req, node.id)
        return len(self._pending)
315669
function getData(node, name) {
    var id = node[exp], store = id && data[id]
    if (name === undefined) return store || setData(node)
    else {
      if (store) {
        if (name in store) return store[name]
        var camelName = camelize(name)
        if (camelName in store) return store[camelName]
      }
      return dataAttr.call($(node), name)
    }
  }
785292
def _set_labels(node, apiserver_url, labels):
    ''''''
    # Prepare URL
    url = "{0}/api/v1/nodes/{1}".format(apiserver_url, node)
    # Prepare data
    data = [{"op": "replace", "path": "/metadata/labels", "value": labels}]
    # Make request
    ret = _kpatch(url, data)
    if ret.get("status") == 404:
        return "Node {0} doesn't exist".format(node)
    return ret
382237
def update_labels(self, node_name: str, labels: dict):
        
        # Raise an exception if we are not a manager
        if not self._manager:
            raise RuntimeError('Only the Swarm manager node can update '
                               'node details.')

        # Node specification
        node_spec = {'Availability': 'active',
                     'Name': node_name,
                     'Role': 'manager',
                     'Labels': labels}
        node = self._client.nodes.get(node_name)
        node.update(node_spec)
255731
def on_send(node)
      name     = node.children[1].to_s
      name     = SEND_MAPPING.fetch(name, name)
      callback = "on_send_#{name}"

      value_stack.add_stack

      execute_callback(callback, node)
    end
517597
def send_data(self, data=None):
        
        save_in_error = False
        if not data:
            if self.__data_lock.acquire():
                data = self.__data
                self.__data = []
                save_in_error = True
                self.__data_lock.release()
            else:
                return False
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        payload = pickle.dumps(data, protocol=2)
        header = struct.pack("!L", len(payload))
        message = header + payload
        s.settimeout(1)
        s.connect((self.host, self.port))
        try:
            s.send(message)
        except:
            # log.exception('Error when sending data to carbon')
            if save_in_error:
                self.__data.extend(data)
            return False
        else:
            # log.debug('Sent data to {host}:{port}: {0} metrics, {1} bytes'.format(len(data),
            #   len(message), host = self.host, port=self.port))
            return True
        finally:
            s.close()
1373219
def get(security_token=None, key=None):
    
    if security_token is None:
        security_token = nago.core.get_my_info()['host_name']
    data = node_data.get(security_token, {})
    if not key:
        return data
    else:
        return data.get(key)
909438
def send(remote_host=None):
    
    my_data = get()
    if not remote_host:
        remote_host = nago.extensions.settings.get('server')
    remote_node = nago.core.get_node(remote_host)
    remote_node.send_command('checkresults', 'post', **my_data)
    return "checkresults sent to %s" % remote_host
533002
def call(self, node, children):
        ''
        name, _, arguments, _ = children
        return name(*arguments)
38723
def add(node_name, **kwargs):
    
    result = {}
    kwargs = kwargs.copy()
    overwrite = kwargs.pop('overwrite', False)
    node = nago.core.get_node(node_name)
    if not node:
        node = nago.core.Node()
    elif not overwrite:
        result['status'] = 'error'
        result['message'] = "node %s already exists. add argument overwrite=1 to overwrite it." % (node_name)
        return result
    else:
        node.delete()
        node = nago.core.Node()
    node['host_name'] = node_name
    for k, v in kwargs.items():
        node[k] = v
    node.save()
    result['message'] = "node successfully saved"
    result['node_data'] = node.data
    return result
579077
def get_name(node):
  
  if isinstance(node, gast.Name):
    return node.id
  elif isinstance(node, (gast.Subscript, gast.Attribute)):
    return get_name(node.value)
  else:
    raise TypeError
59229
def listen_to_node(self, id_):
        """"""
        if r_client.get(id_) is None:
            return
        else:
            self.toredis.subscribe(_pubsub_key(id_), callback=self.callback)
            self._listening_to[_pubsub_key(id_)] = id_
            return id_