Example #1
0
    def main(self, argv):
        self.parser = self.get_base_parser()
        (options, args) = self.parser.parse_known_args(argv)

        if options.help:
            self.do_help(options)
            return 0

        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        nodes = ['node1', 'node2']
        nodeinfo = {'node1':{'bmc':'10.0.0.1', 'bmcip':'10.0.0.1', 'username':'******', 'password': '******'},
                    'node2':{'bmc':'10.0.0.2', 'bmcip':'10.0.0.2', 'username':'******', 'password': '******'}}

        s.connect(options.sock)
        req = {'module': 'openbmc',
               'command': 'rpower',
               'args': ['state'],
               'cwd': os.getcwd(),
               'nodes': nodes,
               'nodeinfo': nodeinfo,
               'envs': {'debugmode': 1}}

        buf = json.dumps(req)
        s.send(utils.int2bytes(len(buf)))
        s.send(buf)
        while True:
            sz = s.recv(4)
            if len(sz) == 0:
                break
            sz = utils.bytes2int(sz)
            data = s.recv(sz)
            print(data)
Example #2
0
    def main(self, argv):
        self.parser = self.get_base_parser()
        (options, args) = self.parser.parse_known_args(argv)

        if options.help:
            self.do_help(options)
            return 0

        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        nodes = ['node1', 'node2']
        nodeinfo = {'node1':{'bmc':'10.0.0.1', 'bmcip':'10.0.0.1', 'username':'******', 'password': '******'},
                    'node2':{'bmc':'10.0.0.2', 'bmcip':'10.0.0.2', 'username':'******', 'password': '******'}}

        s.connect(options.sock)
        req = {'module': 'openbmc',
               'command': 'rpower',
               'args': ['state'],
               'cwd': os.getcwd(),
               'nodes': nodes,
               'nodeinfo': nodeinfo,
               'envs': {'debugmode': 1}}

        buf = json.dumps(req)
        s.send(utils.int2bytes(len(buf)))
        s.send(buf.encode('utf-8'))
        while True:
            sz = s.recv(4)
            if len(sz) == 0:
                break
            sz = utils.bytes2int(sz)
            data = s.recv(sz).decode('utf-8')
            print(data)
Example #3
0
 def _handle(self, sock, address):
     try:
         messager = XCATMessager(sock)
         buf = sock.recv(4)
         sz = utils.bytes2int(buf)
         buf = utils.recv_all(sock, sz)
         req = json.loads(buf)
         if not 'command' in req:
             messager.error("Could not find command")
             return
         if not 'module' in req:
             messager.error("Please specify the request module")
             return
         if not 'cwd' in req:
             messager.error("Please specify the cwd parameter")
             return
         manager_func = xcat_manager.BaseManager.get_manager_func(
             req['module'])
         if manager_func is None:
             messager.error("Could not find manager for %s" % req['module'])
             return
         nodes = req.get("nodes", None)
         manager = manager_func(messager, req['cwd'], nodes, req['envs'])
         if not hasattr(manager, req['command']):
             messager.error("command %s is not supported" % req['command'])
         func = getattr(manager, req['command'])
         # translate unicode string to normal string to avoid docopt error
         new_args = []
         if req['args']:
             for a in req['args']:
                 new_args.append(a.encode('utf-8'))
         # call the function in the specified manager
         func(req['nodeinfo'], new_args)
         # after the method returns, the request should be handled
         # completely, close the socket for client
         if not self.standalone:
             sock.close()
             self.server.stop()
             os._exit(0)
     except ImportError:
         messager.error(
             "OpenBMC management is using a Python framework and some dependency libraries could not be imported."
         )
         print(traceback.format_exc(), file=sys.stderr)
         self.server.stop()
         os._exit(1)
     except Exception:
         print(traceback.format_exc(), file=sys.stderr)
         self.server.stop()
         os._exit(1)
Example #4
0
 def _handle(self, sock, address):
     try:
         messager = XCATMessager(sock)
         buf = sock.recv(4)
         sz = utils.bytes2int(buf)
         buf = utils.recv_all(sock, sz)
         req = json.loads(buf)
         if not 'command' in req:
             messager.error("Could not find command")
             return
         if not 'module' in req:
             messager.error("Please specify the request module")
             return
         if not 'cwd' in req:
             messager.error("Please specify the cwd parameter")
             return
         manager_func = xcat_manager.BaseManager.get_manager_func(
             req['module'])
         if manager_func is None:
             messager.error("Could not find manager for %s" % req['module'])
             return
         nodes = req.get("nodes", None)
         manager = manager_func(messager, req['cwd'], nodes, req['envs'])
         if not hasattr(manager, req['command']):
             messager.error("command %s is not supported" % req['command'])
         func = getattr(manager, req['command'])
         # translate unicode string to normal string to avoid docopt error
         new_args=[]
         if req['args']:
             for a in req['args']:
                 new_args.append(str(a))
         # call the function in the specified manager
         func(req['nodeinfo'], new_args)
         # after the method returns, the request should be handled
         # completely, close the socket for client
         if not self.standalone:
             sock.close()
             self.server.stop()
             os._exit(0)
     except ImportError:
         messager.error("OpenBMC management is using a Python framework and some dependency libraries could not be imported.")
         print(traceback.format_exc(), file=sys.stderr)
         self.server.stop()
         os._exit(1)
     except Exception:
         print(traceback.format_exc(), file=sys.stderr)
         self.server.stop()
         os._exit(1)
Example #5
0
 def _handle(self, sock, address):
     try:
         messager = XCATMessager(sock)
         buf = sock.recv(4)
         sz = utils.bytes2int(buf)
         buf = utils.recv_all(sock, sz)
         req = json.loads(buf)
         if not 'command' in req:
             messager.error("Could not find command")
             return
         if not 'module' in req:
             messager.error("Please specify the request module")
             return
         if not 'cwd' in req:
             messager.error("Please specify the cwd parameter")
             return
         manager_func = xcat_manager.BaseManager.get_manager_func(
             req['module'])
         if manager_func is None:
             messager.error("Could not find manager for %s" % req['module'])
             return
         nodes = req.get("nodes", None)
         manager = manager_func(messager, req['cwd'], nodes, req['envs'])
         if not hasattr(manager, req['command']):
             messager.error("command %s is not supported" % req['command'])
         func = getattr(manager, req['command'])
         # call the function in the specified manager
         func(req['nodeinfo'], req['args'])
         # after the method returns, the request should be handled
         # completely, close the socket for client
         if not self.standalone:
             sock.close()
             self.server.stop()
             os._exit(0)
     except Exception:
         print(traceback.format_exc(), file=sys.stderr)
         self.server.stop()
         os._exit(1)