def svResume(self,req,id,sv_inst_id,body=None):
		res = Response(None,200)
		try:
			self.svinstanc_mgr.resume(sv_inst_id)
		except NUllResourceIDException,e:
			Logger.error(e.message)
			res.status=404
	def buildSvInst(self,req,id,body=None):
		#启动一个服务后,这个服务才能被调用
		#url Post http://ip:port/v1/sv_id/start
		#body:user_id,sv_inst_id,type
# 		if body['svtype']==utils.SYN:
		res =Response(None,200)
# 		sv_inst_id = body['sv_inst_id']
		sv_inst_id = str(body.get('sv_inst_id'))
		if not sv_inst_id:
			Logger.debug("The args 'sv_inst_id' can not be null!")
			res.status=505
		sv_id = id
		
		user_id = body.get('user_id')
		if not user_id:
			Logger.debug("The args 'user_id' can not be null!")
			res.status=505
		svtype = body.get('svtype')
		if svtype is None:
			svtype = ServiceCtrlBlock.UNDAEM
		if svtype not in ServiceCtrlBlock.TYPES:
			res.status=412
		try:
			self.svinstanc_mgr.build_svinstance(sv_inst_id, user_id, sv_id, svtype)
			self.svinstanc_mgr.start(sv_inst_id)
		except Exception,e:
			Logger.error(e.msg)
			res.status=505
			res.body=e.msg
    def buildSvInst(self, req, id, body=None):
        #启动一个服务后,这个服务才能被调用
        #url Post http://ip:port/v1/sv_id/start
        #body:user_id,sv_inst_id,type
        # 		if body['svtype']==utils.SYN:
        res = Response(None, 200)
        # 		sv_inst_id = body['sv_inst_id']
        sv_inst_id = str(body.get('sv_inst_id'))
        if not sv_inst_id:
            Logger.debug("The args 'sv_inst_id' can not be null!")
            res.status = 505
        sv_id = id

        user_id = body.get('user_id')
        if not user_id:
            Logger.debug("The args 'user_id' can not be null!")
            res.status = 505
        svtype = body.get('svtype')
        if svtype is None:
            svtype = ServiceCtrlBlock.UNDAEM
        if svtype not in ServiceCtrlBlock.TYPES:
            res.status = 412
        try:
            self.svinstanc_mgr.build_svinstance(sv_inst_id, user_id, sv_id,
                                                svtype)
            self.svinstanc_mgr.start(sv_inst_id)
        except Exception, e:
            Logger.error(e.msg)
            res.status = 505
            res.body = e.msg
 def svResume(self, req, id, sv_inst_id, body=None):
     res = Response(None, 200)
     try:
         self.svinstanc_mgr.resume(sv_inst_id)
     except NUllResourceIDException, e:
         Logger.error(e.message)
         res.status = 404
	def svSuspend(self,req,id,sv_inst_id,body=None):
		#UPDATE http://ip:port/v1/sv_id/sv_inst_id
		res =Response(None,200)
		try:
			self.svinstanc_mgr.suspend(sv_inst_id)
		except NUllResourceIDException,e:
			Logger.error(e.message)
			res.status=404
	def closeAll(self,req):
		res =Response(None,200)
		try:
			self.svinstanc_mgr.close_all()
		except Exception,e:
			Logger.error(e.message)
			res.status=505
			res.body=e.messag
 def closeAll(self, req):
     res = Response(None, 200)
     try:
         self.svinstanc_mgr.close_all()
     except Exception, e:
         Logger.error(e.message)
         res.status = 505
         res.body = e.messag
 def svClose(self, req, id, sv_inst_id):
     #DELETE http://ip:port/v1/sv_id/sv_inst_id
     res = Response(None, 200)
     try:
         self.svinstanc_mgr.close(sv_inst_id)
     except NUllResourceIDException, e:
         Logger.error(e.message)
         res.status = 404
 def svSuspend(self, req, id, sv_inst_id, body=None):
     #UPDATE http://ip:port/v1/sv_id/sv_inst_id
     res = Response(None, 200)
     try:
         self.svinstanc_mgr.suspend(sv_inst_id)
     except NUllResourceIDException, e:
         Logger.error(e.message)
         res.status = 404
	def svClose(self,req,id,sv_inst_id):
		#DELETE http://ip:port/v1/sv_id/sv_inst_id
		res =Response(None,200)
		try:
			self.svinstanc_mgr.close(sv_inst_id)
		except NUllResourceIDException,e:
			Logger.error(e.message)
			res.status=404
	def svCall(self,req,id,sv_inst_id,body=None):
		#将通过请求体发送的json格式的数据和通过url发送的数据保存到字典中
		res =Response(None,200)
		kwargs=(dict(body) if body else dict())
		if req:
			kwargs.update(req.GET.dict_of_lists())
		try:
			rs=self.svinstanc_mgr.service_call(sv_inst_id, kwargs)
			rs = json.dumps(rs)
			res.body=rs
		except NUllResourceIDException,e:
			Logger.error(e.msg)
			res.status=404
 def svCall(self, req, id, sv_inst_id, body=None):
     #将通过请求体发送的json格式的数据和通过url发送的数据保存到字典中
     res = Response(None, 200)
     kwargs = (dict(body) if body else dict())
     if req:
         kwargs.update(req.GET.dict_of_lists())
     try:
         rs = self.svinstanc_mgr.service_call(sv_inst_id, kwargs)
         rs = json.dumps(rs)
         res.body = rs
     except NUllResourceIDException, e:
         Logger.error(e.msg)
         res.status = 404
	def svStatequery(self,req,id,sv_inst_id,body=None):
		#GET http://ip:port/v1/sv_id/sv_inst_id
		res =Response(None,200)
		state_msg={}
		try:
			rs = self.svinstanc_mgr.get_svinst_state(sv_inst_id)
			state_msg['state']=rs
			if rs==ServiceCtrlBlock.ERROR:
				state_msg['error_msg']=self.svinstanc_mgr.get_svinst_error_msg(sv_inst_id)
			state_msg = json.dumps(state_msg)
			res.body = state_msg
		except NUllResourceIDException,e:
			Logger.error(e.message)
			res.status=404
 def svStatequery(self, req, id, sv_inst_id, body=None):
     #GET http://ip:port/v1/sv_id/sv_inst_id
     res = Response(None, 200)
     state_msg = {}
     try:
         rs = self.svinstanc_mgr.get_svinst_state(sv_inst_id)
         state_msg['state'] = rs
         if rs == ServiceCtrlBlock.ERROR:
             state_msg[
                 'error_msg'] = self.svinstanc_mgr.get_svinst_error_msg(
                     sv_inst_id)
         state_msg = json.dumps(state_msg)
         res.body = state_msg
     except NUllResourceIDException, e:
         Logger.error(e.message)
         res.status = 404
Exemple #15
0
class SvcCall(service.Service):
    def call(self, svfilename, *args, **kwargs):
        #根据svfile获得相应服务组合描述性文件,并转换成json格式
        svcf = open(svfilename)
        svcj = json.loads(svcf.read())
        svcf.close()
        try:
            rs = xengin.exc(svcj, kwargs)
        except HydrogenException, e:
            return e.msg
        except Exception, e:
            logger.error(e.message)
            return e.message
    def run(self):
        try:
            while (True):
                if (self.svcb.is_running()):
                    self.svcb.running_to_ready()
                if (self.svcb.is_builed()):
                    self.svcb.builded_to_ready()
                data, output_queue = self.__conn_queue.get()
                if data is None and output_queue is None:
                    self.svcb.to_stop()
                    self.__conn_queue.task_done()
                    break

                self.svcb.ready_to_running()

                #一次服务运行服务运行
                #data = self.sv_call_mgr.svCall(self.svcb.sv_id, data)
                data = svcall.svCall(self.svcb.sv_id, data)
                output_queue.put(data)
                self.__conn_queue.task_done()
        except Exception, e:
            Logger.error(e.message)
            self.svcb.error_msg = e.message
	def run(self):
		try:
			while(True):
				if (self.svcb.is_running()):
					self.svcb.running_to_ready()
				if (self.svcb.is_builed()):
					self.svcb.builded_to_ready()
				data,output_queue = self.__conn_queue.get()
				if data is None and output_queue is None:
					self.svcb.to_stop()
					self.__conn_queue.task_done()
					break
			
				self.svcb.ready_to_running()
			
				#一次服务运行服务运行
					#data = self.sv_call_mgr.svCall(self.svcb.sv_id, data)
				data = svcall.svCall(self.svcb.sv_id, data)
				output_queue.put(data)
				self.__conn_queue.task_done()
		except Exception,e:
			Logger.error(e.message)
			self.svcb.error_msg = e.message
    def svCall(self, req, id, sv_inst_id, body=None):
        #将通过请求体发送的json格式的数据和通过url发送的数据保存到字典中
        res = Response(None, 200)
        kwargs = (dict(body) if body else dict())
        if req:
            kwargs.update(req.GET.dict_of_lists())
        try:
            rs = self.svinstanc_mgr.service_call(sv_inst_id, kwargs)
            rs = json.dumps(rs)
            res.body = rs
        except NUllResourceIDException, e:
            Logger.error(e.msg)
            res.status = 404
        except Exception, e:
            Logger.error(e.message)
            res.status = 505
        return res

    def buildSvInst(self, req, id, body=None):
        #启动一个服务后,这个服务才能被调用
        #url Post http://ip:port/v1/sv_id/start
        #body:user_id,sv_inst_id,type
        # 		if body['svtype']==utils.SYN:
        res = Response(None, 200)
        # 		sv_inst_id = body['sv_inst_id']
        sv_inst_id = str(body.get('sv_inst_id'))
        if not sv_inst_id:
            Logger.debug("The args 'sv_inst_id' can not be null!")
            res.status = 505
        sv_id = id
	
	def svCall(self,req,id,sv_inst_id,body=None):
		#将通过请求体发送的json格式的数据和通过url发送的数据保存到字典中
		res =Response(None,200)
		kwargs=(dict(body) if body else dict())
		if req:
			kwargs.update(req.GET.dict_of_lists())
		try:
			rs=self.svinstanc_mgr.service_call(sv_inst_id, kwargs)
			rs = json.dumps(rs)
			res.body=rs
		except NUllResourceIDException,e:
			Logger.error(e.msg)
			res.status=404
		except Exception,e:
			Logger.error(e.message)
			res.status=505
		return res
	
	def buildSvInst(self,req,id,body=None):
		#启动一个服务后,这个服务才能被调用
		#url Post http://ip:port/v1/sv_id/start
		#body:user_id,sv_inst_id,type
# 		if body['svtype']==utils.SYN:
		res =Response(None,200)
# 		sv_inst_id = body['sv_inst_id']
		sv_inst_id = str(body.get('sv_inst_id'))
		if not sv_inst_id:
			Logger.debug("The args 'sv_inst_id' can not be null!")
			res.status=505
		sv_id = id