Exemplo n.º 1
0
    def executeCmd(self, job):
        cmd = job.cmd

        jobstatus = jobStatus()
        jobId = None
        try:
            self.lock.acquire()

            if cmd.isAsync == "false":
                jobstatus.startTime = datetime.datetime.now()

                result = self.connection.make_request(cmd)
                jobstatus.result = result
                jobstatus.endTime = datetime.datetime.now()
                jobstatus.duration = time.mktime(
                    jobstatus.endTime.timetuple()) - time.mktime(
                        jobstatus.startTime.timetuple())
            else:
                result = self.connection.make_request(cmd, None, True)
                if result is None:
                    jobstatus.status = False
                else:
                    jobId = result.jobid
                    jobstatus.jobId = jobId
                    try:
                        responseName = cmd.__class__.__name__.replace(
                            "Cmd", "Response")
                        jobstatus.responsecls = jsonHelper.getclassFromName(
                            cmd, responseName)
                    except:
                        pass
                    jobstatus.status = True
        except cloudstackException.cloudstackAPIException, e:
            jobstatus.result = str(e)
            jobstatus.status = False
Exemplo n.º 2
0
    def executeCmd(self, job):
        cmd = job.cmd

        jobstatus = jobStatus()
        jobId = None
        try:
            self.lock.acquire()
            
            if cmd.isAsync == "false":
                jobstatus.startTime = datetime.datetime.now()
               
                result = self.connection.make_request(cmd)
                jobstatus.result = result
                jobstatus.endTime = datetime.datetime.now()
                jobstatus.duration = time.mktime(jobstatus.endTime.timetuple()) - time.mktime(jobstatus.startTime.timetuple())
            else:
                result = self.connection.make_request(cmd, None, True)
                if result is None:
                    jobstatus.status = False
                else:
                    jobId = result.jobid
                    jobstatus.jobId = jobId
                    try:
                        responseName = cmd.__class__.__name__.replace("Cmd", "Response")
                        jobstatus.responsecls = jsonHelper.getclassFromName(cmd, responseName)
                    except:
                        pass
                    jobstatus.status = True
        except cloudstackException.cloudstackAPIException, e:
            jobstatus.result = str(e)
            jobstatus.status = False