Example #1
0
    def wrapper(target, msg):
        try:
            event_time = merge_time(msg['event_time'])
        except:
            log.error("Received message with malformed time: %s",
                      msg['event_time'])
            raise KeyError

        db_time = target.backendtime

        if db_time and event_time <= db_time:
            format_ = "%d/%m/%y %H:%M:%S:%f"
            log.debug(
                "Ignoring message %s.\nevent_timestamp: %s"
                " db_timestamp: %s", msg, event_time.strftime(format_),
                db_time.strftime(format_))
            return
        # New message. Update the database!
        func(target, msg, event_time)
Example #2
0
    def wrapper(target, msg):
        try:
            event_time = merge_time(msg["event_time"])
        except:
            log.error("Received message with malformed time: %s", msg["event_time"])
            raise KeyError

        db_time = target.backendtime

        if db_time and event_time <= db_time:
            format_ = "%d/%m/%y %H:%M:%S:%f"
            log.debug(
                "Ignoring message %s.\nevent_timestamp: %s" " db_timestamp: %s",
                msg,
                event_time.strftime(format_),
                db_time.strftime(format_),
            )
            return
        # New message. Update the database!
        func(target, msg, event_time)
Example #3
0
    def get_build_status(self, db_server):
        """Return the status of the build job.

        Return whether the job is RUNNING, FINALIZED or ERROR, together
        with the timestamp that the job finished (if any).

        """
        job_id = db_server.backendjobid
        if job_id in self.gnt_jobs:
            job = self.gnt_jobs[job_id]
            gnt_job_status = job["status"]
            end_timestamp = job["end_ts"]
            if end_timestamp is not None:
                end_timestamp = merge_time(end_timestamp)
            if gnt_job_status == rapi.JOB_STATUS_ERROR:
                return "ERROR", end_timestamp
            elif gnt_job_status not in rapi.JOB_STATUS_FINALIZED:
                return "RUNNING", None
            else:
                return "FINALIZED", end_timestamp
        else:
            return "ERROR", None
Example #4
0
    def get_build_status(self, db_server):
        """Return the status of the build job.

        Return whether the job is RUNNING, FINALIZED or ERROR, together
        with the timestamp that the job finished (if any).

        """
        job_id = db_server.backendjobid
        if job_id in self.gnt_jobs:
            job = self.gnt_jobs[job_id]
            gnt_job_status = job["status"]
            end_timestamp = job["end_ts"]
            if end_timestamp is not None:
                end_timestamp = merge_time(end_timestamp)
            if gnt_job_status == rapi.JOB_STATUS_ERROR:
                return "ERROR", end_timestamp
            elif gnt_job_status not in rapi.JOB_STATUS_FINALIZED:
                return "RUNNING", None
            else:
                return "FINALIZED", end_timestamp
        else:
            return "ERROR", None
Example #5
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        vm = common.get_vm(args[0])

        displayname = options['displayname']

        ucache = UserCache(ASTAKOS_BASE_URL, ASTAKOS_TOKEN)

        try:
            image = common.get_image(vm.imageid, vm.userid)['name']
        except:
            image = vm.imageid

        sep = '-' * 80 + '\n'
        labels = filter(lambda x: x is not Omit,
                        ['name', 'owner_uuid',
                         'owner_name' if displayname else Omit,
                         'flavor', 'image', 'state', 'backend', 'deleted',
                         'action', 'backendjobid', 'backendopcode',
                         'backendjobstatus', 'backend_time'])

        uuid = vm.userid
        if displayname:
            dname = ucache.get_name(uuid)

        fields = filter(lambda x: x is not Omit,
                        [vm.name, uuid, dname if displayname else Omit,
                         vm.flavor.name, image, common.format_vm_state(vm),
                         str(vm.backend), str(vm.deleted), str(vm.action),
                         str(vm.backendjobid), str(vm.backendopcode),
                         str(vm.backendjobstatus), str(vm.backendtime)])

        self.stdout.write(sep)
        self.stdout.write('State of Server in DB\n')
        self.stdout.write(sep)
        for l, f in zip(labels, fields):
            self.stdout.write(l.ljust(18) + ': ' + f.ljust(20) + '\n')
        self.stdout.write('\n')
        for nic in vm.nics.all():
            params = (nic.index, nic.ipv4, nic.mac, nic.ipv6,  nic.network)
            self.stdout.write("nic/%d: IPv4: %s, MAC: %s, IPv6:%s,"
                              " Network: %s\n" % params)

        client = vm.get_client()
        try:
            g_vm = client.GetInstance(vm.backend_vm_id)
            self.stdout.write('\n')
            self.stdout.write(sep)
            self.stdout.write('State of Server in Ganeti\n')
            self.stdout.write(sep)
            for i in GANETI_INSTANCE_FIELDS:
                try:
                    value = g_vm[i]
                    if i.find('time') != -1:
                        value = datetime.fromtimestamp(value)
                    self.stdout.write(i.ljust(14) + ': ' + str(value) + '\n')
                except KeyError:
                    pass
        except GanetiApiError as e:
            if e.code == 404:
                self.stdout.write('Server does not exist in backend %s\n' %
                                  vm.backend.clustername)
            else:
                raise e

        if not options['jobs']:
            return

        self.stdout.write('\n')
        self.stdout.write(sep)
        self.stdout.write('Non-archived jobs concerning Server in Ganeti\n')
        self.stdout.write(sep)
        jobs = client.GetJobs()
        for j in jobs:
            info = client.GetJobStatus(j)
            summary = ' '.join(info['summary'])
            job_is_relevant = summary.startswith("INSTANCE") and\
                (summary.find(vm.backend_vm_id) != -1)
            if job_is_relevant:
                for i in GANETI_JOB_FIELDS:
                    value = info[i]
                    if i.find('_ts') != -1:
                        value = merge_time(value)
                    try:
                        self.stdout.write(i.ljust(14) + ': ' + str(value) +
                                          '\n')
                    except KeyError:
                        pass
                self.stdout.write('\n' + sep)
        # Return the RAPI client to pool
        vm.put_client(client)