Beispiel #1
0
    def collect_observation(self, context, observation, trace=True):
        args = context.eval(self.__args)
        dcos_response = self.__dcoscli.run(args, trace=trace)
        if not dcos_response.ok():
            observation.add_error(
                cli_agent.CliAgentRunError(self.__dcoscli, dcos_response))
            return []

        decoder = json.JSONDecoder()
        try:
            doc = decoder.decode(dcos_response.output)
            if not isinstance(doc, list):
                doc = [doc]
            self.filter_all_objects_to_observation(context, doc, observation)
        except ValueError as vex:
            error = 'Invalid JSON in response: %s' % str(dcos_response)
            logging.getLogger(__name__).info('%s\n%s\n----------------\n',
                                             error, traceback.format_exc())
            observation.add_error(jp.JsonError(error, vex))
            return []

        return observation.objects
Beispiel #2
0
    def collect_observation(self, context, observation):
        args = context.eval(self.__args)
        aws_response = self.__aws.run(args)
        if not aws_response.ok():
            observation.add_error(
                cli_agent.CliAgentRunError(self.__aws, aws_response))
            return []

        decoder = json.JSONDecoder()
        try:
            doc = decoder.decode(aws_response.output)
        except (ValueError, UnicodeError) as e:
            error = 'Invalid JSON in response: %s' % str(aws_response)
            print 'ERROR:' + error
            observation.add_error(JsonError(error, e))
            return []

        if not isinstance(doc, list):
            doc = [doc]
        self.filter_all_objects_to_observation(context, doc, observation)

        return observation.objects
Beispiel #3
0
    def collect_observation(self, context, observation):
        args = context.eval(self.__args)
        gcloud_response = self.__gcloud.run(args)
        if not gcloud_response.ok():
            observation.add_error(
                cli_agent.CliAgentRunError(self.__gcloud, gcloud_response))
            return []

        decoder = json.JSONDecoder()
        try:
            doc = decoder.decode(gcloud_response.output)
            if not isinstance(doc, list):
                doc = [doc]
            observation.add_all_objects(doc)
        except ValueError as vex:
            error = 'Invalid JSON in response: %s' % str(gcloud_response)
            logging.getLogger(__name__).info('%s\n%s\n----------------\n',
                                             error, traceback.format_exc())
            observation.add_error(JsonError(error, vex))
            return []

        return observation.objects