Exemplo n.º 1
0
    def register_node(self, name):
        """
        Registers a node to the Kubernetes Container Manager.

        :param name: The name of the node.
        :type name: str
        :raises: commissaire.bus.ContainerManagerError
        """
        part = '/nodes'

        payload = {
            "kind": "Node",
            "apiVersion": "v1",
            "metadata": {
                "name": name,
            }
        }

        resp = self._post(part, payload)
        if resp.status_code != 201:
            error_msg = (
                'Non-created response when trying to register the node {}. '
                'Status: "{}", Data: "{}"'.format(name, resp.status_code,
                                                  resp.text))
            self.logger.error(error_msg)
            raise ContainerManagerError(error_msg, resp.status_code)
Exemplo n.º 2
0
    def remove_all_nodes(self):
        """
        Removes all nodes from the Kubernetes Container Manager.

        :raises: commissaire.bus.ContainerManagerError
        """
        resp = self._delete('/nodes')
        if resp.status_code != 200:
            error_msg = (
                'Unexpected response when trying to remove all nodes. '
                'Status: {}, Data: {}'.format(resp.status_code, resp.text))
            self.logger.error(error_msg)
            raise ContainerManagerError(error_msg, resp.status_code)
Exemplo n.º 3
0
    def node_registered(self, address):
        """
        Checks if a node is registered to the container manager.

        Raises ContainerManagerError if the node is NOT registered.

        :param address: Address of the node
        :type address: str
        :raises: commissaire.containermgr.ContainerManagerError
        """
        if address not in self.nodes:
            message = 'Node {} is not registered'.format(address)
            self.logger.error(message)
            raise ContainerManagerError(message)
Exemplo n.º 4
0
    def node_registered(self, name):
        """
        Checks is a node was registered.

        :param name: The name of the node.
        :type name: str
        :raises: commissaire.bus.ContainerManagerError
        """
        part = '/nodes/{}'.format(name)
        resp = self._get(part)
        if resp.status_code != 200:
            error_msg = 'Node {} is not registered. Status: {}'.format(
                name, resp.status_code)
            self.logger.error(error_msg)
            raise ContainerManagerError(error_msg, resp.status_code)
Exemplo n.º 5
0
    def remove_node(self, name):
        """
        Removes a node from the Kubernetes Container Manager.

        :param name: The name of the node.
        :type name: str
        :raises: commissaire.bus.ContainerManagerError
        """
        part = '/nodes/{}'.format(name)

        resp = self._delete(part)
        if resp.status_code != 200:
            error_msg = (
                'Unexpected response when trying to remove the node {}. '
                'Status: {}, Data: {}'.format(name, resp.status_code,
                                              resp.text))
            self.logger.error(error_msg)
            raise ContainerManagerError(error_msg, resp.status_code)
Exemplo n.º 6
0
    def get_node_status(self, address):
        """
        Gets a node's status from the container manager.

        For this trivial container manager, the returned dictionary contains
        two keys: 'node' (the node's address) and 'status' (always 'ok').

        :param address: Address of the node
        :type address: str
        :returns: Status of the node according to the container manager
        :rtype: dict
        :raises: commissaire.containermgr.ContainerManagerError
        """
        if address in self.nodes:
            status = {'node': address, 'status': 'ok'}
            self.logger.debug('Node status: %s', status)
            return status
        else:
            message = 'Node {} is not registered'.format(address)
            self.logger.error(message)
            raise ContainerManagerError(message)
Exemplo n.º 7
0
    def get_node_status(self, name, raw=False):
        """
        Returns the node status.

        :param name: The name of the node.
        :type name: str
        :param raw: If the result should be limited to its own status.
        :type raw: bool
        :returns: The response back from kubernetes.
        :rtype: dict
        :raises: commissaire.bus.ContainerManagerError
        """
        part = '/nodes/{}'.format(name)
        resp = self._get(part)
        if resp.status_code != 200:
            error_msg = ('No status for {} returned. Status: {}'.format(
                name, resp.status_code))
            self.logger.error(error_msg)
            raise ContainerManagerError(error_msg, resp.status_code)

        data = resp.json()
        if raw:
            data = data['status']
        return data