コード例 #1
0
    def process(self, reqstring):
        reppayload = {}
        result = 'OK'
        id = None
        name = None
        try:
            # deserialize req string
            reqmsg = dss_msg.Msg()
            reqmsg.deserialize(reqstring)
            name = reqmsg.get_name()

            logging.info("Processing %s" % name)

            id = reqmsg.get_id()

            # find suitable handler
            handler = self.get_handler(name)

            # process message
            reppayload = handler.handle(reqmsg.get_payload())
        except Exception as exp:
            logging.warning('Failed when processing %s' % reqstring)
            result = str(exp)

        repmsg = dss_msg.Msg(name, id, reppayload, result)

        return repmsg.serialize()
コード例 #2
0
 def get_domain(self, domain):
     reqpayload = dss_get_domain_rpc.GetDomainRPC.create_req_payload(domain)
     reqmsg = dss_msg.Msg(dss_get_domain_rpc.GetDomainRPC.get_name(), self.id, reqpayload)
     repmsg = self._call_rpc(reqmsg)
     reppayload = repmsg.get_payload()
     attrs = dss_get_domain_rpc.GetDomainRPC.get_data_from_rep_payload(reppayload)
     return attrs
コード例 #3
0
 def get(self, domain, name):
     reqpayload = dss_get_rpc.GetRPC.create_req_payload(domain, name)
     reqmsg = dss_msg.Msg(dss_get_rpc.GetRPC.get_name(), self.id, reqpayload)
     repmsg = self._call_rpc(reqmsg)
     reppayload = repmsg.get_payload()
     value = dss_get_rpc.GetRPC.get_value_from_rep_payload(reppayload)
     return value
コード例 #4
0
 def _call_rpc(self, msg):
     self.id += 1
     repmsg = dss_msg.Msg()
     try:
         self._connect()
         req = msg.serialize()
         self.sock.sendall(req+'\n')
         rep = self.fd.readline()
     except Exception as exp:
         try:
             self.sock.close()
         except:
             pass
         self.connect = True
         raise dss_error.Error(str(exp))
     repmsg.deserialize(rep)
     return repmsg
コード例 #5
0
 def delete_domain(self, domain):
     reqpayload = dss_delete_domain_rpc.DeleteDomainRPC.create_req_payload(domain)
     reqmsg = dss_msg.Msg(dss_delete_domain_rpc.DeleteDomainRPC.get_name(), self.id, reqpayload)
     repmsg = self._call_rpc(reqmsg)
コード例 #6
0
 def get_domains(self):
     reqmsg = dss_msg.Msg(dss_get_domains_rpc.GetDomainsRPC.get_name(), self.id, None)
     repmsg = self._call_rpc(reqmsg)
     reppayload = repmsg.get_payload()
     domains = dss_get_domains_rpc.GetDomainsRPC.get_data_from_rep_payload(reppayload)
     return domains
コード例 #7
0
 def set(self, domain, name, value):
     reqpayload = dss_set_rpc.SetRPC.create_req_payload(domain, name, value)
     reqmsg = dss_msg.Msg(dss_set_rpc.SetRPC.get_name(), self.id, reqpayload)
     repmsg = self._call_rpc(reqmsg)