コード例 #1
0
    def save_unknown_domain_configs(self, domain_uuids):
        """
        This function saves the configuration for any domains whose UUIDs are
        passed in the domain_uuids list.  If the UUID is already known, it is
        skipped.
        """

        for uuid in domain_uuids:

            uuid = sstr(uuid)
            # If we already have a config for this uuid, skip it.  Also, don't
            # try to figure out a config for a host UUID.
            if not is_host_uuid(uuid) and not self.is_known_config(uuid):

                # The UUID is a formatted string.  Turn it back into a number,
                # since that's what libvirt wants.
                dehyphenized_uuid = dehyphenize_uuid(uuid)
                uuid_as_num = binascii.unhexlify(dehyphenized_uuid)

                # Lookup the domain by its uuid.
                try:
                    domain = self.conn.lookupByUUID(uuid_as_num)
                except libvirt.libvirtError:
                    lve = sys.exc_info()[1]
                    raise VirtualizationException(
                        "Failed to obtain handle to domain %s: %s" %
                        (uuid, repr(lve)))

                # Now grab the XML description of the configuration.
                xml = domain.XMLDesc(0)

                # Write the xml out to a file so that we can load it into our
                # abstract DomainConfig object and manipulate it easily.
                cfg_file_path = self.__write_xml_file(uuid, xml)
                new_config = DomainConfig(self.__path, uuid)

                # Don't record the config this time if the domain is
                # installing; we don't want to restart the domain later and
                # make it re-install itself.
                if not new_config.isInstallerConfig():

                    # Now we'll reformat the configuration object so that it's
                    # valid the next time this domain runs..
                    self.__fixup_config_for_restart(new_config)

                    # The config is now prepared.  Save it and move on to the
                    # next uuid.
                    new_config.save()

                else:
                    # Remove the config file we just wrote.
                    os.unlink(cfg_file_path)
コード例 #2
0
    def save_unknown_domain_configs(self, domain_uuids):
        """
        This function saves the configuration for any domains whose UUIDs are
        passed in the domain_uuids list.  If the UUID is already known, it is
        skipped.
        """

        for uuid in domain_uuids:

            # If we already have a config for this uuid, skip it.  Also, don't
            # try to figure out a config for a host UUID.
            if not is_host_uuid(uuid) and not self.is_known_config(uuid):

                # The UUID is a formatted string.  Turn it back into a number,
                # since that's what libvirt wants.
                dehyphenized_uuid = dehyphenize_uuid(uuid)
                uuid_as_num = binascii.unhexlify(dehyphenized_uuid)

                # Lookup the domain by its uuid.
                try:
                    domain = self.conn.lookupByUUID(uuid_as_num)
                except libvirt.libvirtError, lve:
                    raise VirtualizationException, \
                          "Failed to obtain handle to domain %s: %s" % \
                              (uuid, repr(lve))

                # Now grab the XML description of the configuration.
                xml = domain.XMLDesc(0)

                # Write the xml out to a file so that we can load it into our
                # abstract DomainConfig object and manipulate it easily.
                cfg_file_path = self.__write_xml_file(uuid, xml)
                new_config = DomainConfig(self.__path, uuid)

                # Don't record the config this time if the domain is
                # installing; we don't want to restart the domain later and
                # make it re-install itself.
                if not new_config.isInstallerConfig():

                    # Now we'll reformat the configuration object so that it's
                    # valid the next time this domain runs..
                    self.__fixup_config_for_restart(new_config)

                    # The config is now prepared.  Save it and move on to the
                    # next uuid.
                    new_config.save()

                else:
                    # Remove the config file we just wrote.
                    os.unlink(cfg_file_path)