コード例 #1
0
ファイル: guest_agent_logic.py プロジェクト: ly798/appmonitor
class AgentLogicBase:
    def __init__(self):
        self.wait_stop = Event()
        if (platform.system() == 'Windows') or (platform.system()
                                                == 'Microsoft'):
            vport_name = '\\\\.\\Global\\com.eayun.eayunstack.0'
        else:
            vport_name = '/dev/virtio-ports/com.eayun.eayunstack.0'
        self.vio = VirtIoChannel(vport_name)
        self.commandHandler = None

    def _send(self, name, arguments=None):
        self.vio.write(name, arguments or {})

    def run(self):
        thread.start_new_thread(self.doListen, ())
        while not self.wait_stop.isSet():
            self.wait_stop.wait(1)

    def stop(self):
        self.wait_stop.set()

    def doListen(self):
        if self.commandHandler is None:
            return
        while not self.wait_stop.isSet():
            try:
                cmd, args = self.vio.read()
                if cmd:
                    self.parseCommand(cmd, args)
            except:
                pass

    def parseCommand(self, command, args):
        if command == 'get_infomation':
            name = args.get('name')
            result = self.commandHandler.get_infomation(name)
            self._send('get_infomation', {'result': result})

        elif command == 'execute_script':
            path = args.get('path')
            type = args.get('type')
            result = self.commandHandler.execute_script(path, type)
            self._send('execute_script', {'result': result})

        elif command == 'execute_command':
            cmd = args.get('cmd')
            try:
                result = self.commandHandler.execute_command(cmd)
                self._send('execute_command', {'result': result})
            except:
                self._send('execute_command', {'result': '0e0r0r0o0r1'})

        elif command == 'echo':
            self._send('echo', args)

        else:
            self._send(command, {'result': '0e0r0r0o0r0'})
コード例 #2
0
ファイル: guest_agent_logic.py プロジェクト: ly798/appmonitor
 def __init__(self):
     self.wait_stop = Event()
     if (platform.system() == 'Windows') or (platform.system()
                                             == 'Microsoft'):
         vport_name = '\\\\.\\Global\\com.eayun.eayunstack.0'
     else:
         vport_name = '/dev/virtio-ports/com.eayun.eayunstack.0'
     self.vio = VirtIoChannel(vport_name)
     self.commandHandler = None
コード例 #3
0
class AgentLogicBase:
    def __init__(self):
        self.wait_stop = Event()
        if (platform.system() == 'Windows') or (platform.system() == 'Microsoft'):
            vport_name = '\\\\.\\Global\\com.eayun.eayunstack.0'
        else:
            vport_name = '/dev/virtio-ports/com.eayun.eayunstack.0'
        self.vio = VirtIoChannel(vport_name)
        self.commandHandler = None

    def _send(self, name, arguments=None):
        self.vio.write(name, arguments or {})

    def run(self):
        thread.start_new_thread(self.doListen, ())
        while not self.wait_stop.isSet():
            self.wait_stop.wait(1)

    def stop(self):
        self.wait_stop.set()

    def doListen(self):
        if self.commandHandler is None:
            return
        while not self.wait_stop.isSet():
            try:
                cmd, args = self.vio.read()
                if cmd:
                    self.parseCommand(cmd, args)
            except:
                pass

    def parseCommand(self, command, args):
        if command == 'get_infomation':
            name = args.get('name')
            result = self.commandHandler.get_infomation(name)
            self._send('get_infomation', {'result': result})

        elif command == 'execute_script':
            path = args.get('path')
            type = args.get('type')
            result = self.commandHandler.execute_script(path, type)
            self._send('execute_script', {'result': result})

        elif command == 'execute_command':
            cmd = args.get('cmd')
            try:
                result = self.commandHandler.execute_command(cmd)
                self._send('execute_command', {'result': result})
            except:
                self._send('execute_command', {'result': '0e0r0r0o0r1'})

        elif command == 'echo':
            self._send('echo', args)

        else:
            self._send(command, {'result': '0e0r0r0o0r0'})
コード例 #4
0
 def __init__(self):
     self.wait_stop = Event()
     if (platform.system() == 'Windows') or (platform.system() == 'Microsoft'):
         vport_name = '\\\\.\\Global\\com.eayun.eayunstack.0'
     else:
         vport_name = '/dev/virtio-ports/com.eayun.eayunstack.0'
     self.vio = VirtIoChannel(vport_name)
     self.commandHandler = None