Beispiel #1
0
 def get_data(self, oper):
     lcollect = []
     lcollect.append('{"node_id" : "%s", "operation" : "%s"}' \
                     % (self.node.id, oper)
                     )
     results = AgentOperation(lcollect)
     results.run()
Beispiel #2
0
    def post(self):
        username = self.get_current_user()
        resultjson = []
        node = {}
        result = []
        nodes = self.get_arguments('node')
        print self.request.arguments
        if len(nodes) <1:
            nodes = None
        tags = self.get_arguments('tag')
        if len(tags) <1:
            tags = None
        params = self.get_argument('params', None)
        time = self.get_argument('time', None)
        schedule = self.get_argument('schedule', None)
        label = self.get_argument('label', None)
        throttle = self.get_argument('throttle', None)
        operation = self.get_argument('operation', None)
        patches = self.get_arguments('patches')
        if len(patches) <1:
            patches = None
        if nodes or tags:
            if time:
                node['schedule'] = schedule
                node['time'] = time
                node['label'] = label
            if throttle:
                node['cpu_throttle'] = throttle
            if operation == 'install' or operation == 'uninstall':
                if nodes:
                    for node_id in nodes:
                        node['node_id'] = node_id.encode('utf8')
                        node['operation'] = operation
                        node['data'] = patches
                        resultjson.append(encode(node))
                elif tags:
                    for tag_id in tags:
                        node['tag_id'] = tag_id.encode('utf8')
                        node['operation'] = operation
                        node['data'] = patches
                        resultjson.append(encode(node))
                if time:
                    result = job_scheduler(resultjson,
                            self.application.scheduler,
                            username=username
                            )
                else:
                    operation_runner = AgentOperation(resultjson,
                            username=username)
                    operation_runner.run()
                    while not operation_runner.json_out:
                        sleep(.50)
                    result = operation_runner.json_out
            elif operation == 'reboot' or operation == 'restart' or\
                    operation == 'stop' or operation == 'start':
                for node_id in nodes:
                    node['operation'] = operation
                    node['node_id'] = node_id.encode('utf8')
                    resultjson.append(encode(node))
                if time:
                    result = job_scheduler(resultjson,
                            self.application.scheduler,
                            username=username
                            )
                else:
                    operation_runner = AgentOperation(resultjson,
                            username=username
                            )
                    operation_runner.run()
                    while not operation_runner.json_out:
                        sleep(.50)
                    result = operation_runner.json_out
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(result))
            print json.dumps(result)

        if params:
            resultjson = json.loads(params)
            operation_runner = AgentOperation(resultjson,
                    username=username)
            operation_runner.run()
            while not operation_runner.json_out:
                sleep(.50)
            result = operation_runner.json_out
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(result))
            print json.dumps(result)
Beispiel #3
0
def call_agent_operation(job, username):
    operation_runner = AgentOperation(job, username=username)
    operation_runner.run()