@classmethod
    def for_domain(cls, dom):
        '''Get job info for the domain

        Query the libvirt job info for the domain (ie progress
        of migration, or snapshot operation)

        Returns: a DomainJobInfo instance
        '''

        if cls._have_job_stats:
            try:
                stats = dom.jobStats()
                return cls(**stats)
            except libvirt.libvirtError as ex:
                if ex.get_error_code() == libvirt.VIR_ERR_NO_SUPPORT:
                    # Remote libvirt doesn't support new API
                    LOG.debug("Missing remote virDomainGetJobStats: %s", ex)
                    cls._have_job_stats = False
                    return cls._get_job_stats_compat(dom)
                elif ex.get_error_code() in (
                        libvirt.VIR_ERR_NO_DOMAIN,
                        libvirt.VIR_ERR_OPERATION_INVALID):
                    # Transient guest finished migration, so it has gone
                    # away completely
                    LOG.debug("Domain has shutdown/gone away: %s", ex)
                    return cls(type=libvirt.VIR_DOMAIN_JOB_COMPLETED)
                else:
                    LOG.debug("Failed to get job stats: %s", ex)
                    raise
            except __HOLE__ as ex:
                # Local python binding doesn't support new API
                LOG.debug("Missing local virDomainGetJobStats: %s", ex)
                cls._have_job_stats = False
                return cls._get_job_stats_compat(dom)
        else:
            return cls._get_job_stats_compat(dom)
dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/virt/libvirt/host.py/DomainJobInfo.for_domain