コード例 #1
0
    def test_do_ping_error(self):
        """
        Perform a ping against a host that doesn't exist
        """

        output, return_code, _ = ping("doesnotexist", count=3)

        self.assertNotEqual(return_code, 0)
        self.assertGreater(len(output), 0)
コード例 #2
0
    def test_do_ping(self):
        """
        Perform a ping against a host that is known to exist.
        """

        output, return_code, parsed = ping("127.0.0.1", count=3)

        self.assertEqual(return_code, 0)
        self.assertGreater(len(output), 0)
        self.assertEqual(int(parsed['received']), 3)
コード例 #3
0
    def do_lookup(self, host):
        """
        Perform a ping against the given host.
        """

        self.logger.info("Running ping against host=%s", host)
        raw_output, return_code, output = ping(host=host, index=None)

        output['return_code'] = return_code
        output['raw_output'] = raw_output
        return output
コード例 #4
0
    def get_ping(self, request_info, host=None, **kwargs):
        """
        Perform a ping.
        """

        if host is None:
            return self.render_error_json(
                "Unable to perform network operation: no host argument provided"
            )

        result = {}

        try:
            output, return_code, data = ping(host,
                                             source="network_tools_controller",
                                             logger=logger)

            result = {
                'success': True,
                'output': output,
                'return_code': return_code
            }

            # Add the data we got
            result.update(data)

            # Everything worked, return accordingly
            return {
                'payload': result,  # Payload of the request.
                'status': 200  # HTTP status code
            }

        except:
            self.logger.exception(
                "Exception generated when attempting to perform an operation")
            return self.render_error_json(
                "Unable to perform network operation")
コード例 #5
0
    def ping(self, host):
        result = {}

        try:
            output, return_code, data = ping(host, source="network_tools_controller", logger=logger)
               
            result = {
                'success': True,
                'output' : output,
                'return_code': return_code
            }

            # Add the data we got
            result.update(data)

        except Exception as e:
            result = {
                'success': False,
                'message': str(e)
            }

            logger.exception("Wake-on-lan request failed")

        return self.render_json(result)