예제 #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)
예제 #3
0
 def load_config(self, uuid):
     """
     This function loads a domain's configuration by its UUID.  A
     DomainConfig object is returned.
     """
     return DomainConfig(self.__path, uuid)
예제 #4
0
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

import sys
sys.path.append("/usr/share/rhn")
from virtualization.domain_config import DomainConfig

fieldname = sys.argv[1]
filename = sys.argv[2]
dc = DomainConfig('/usr/share/rhn/virt/auto', filename)

fields = {
            'name'          :   DomainConfig.NAME,
            'uuid'          :   DomainConfig.UUID,
            'memory'        :   DomainConfig.MEMORY,
            'vcpu'          :   DomainConfig.VCPU,
            'root_device'   :   DomainConfig.ROOT_DEVICE,
            'cmdline'       :   DomainConfig.COMMAND_LINE,
            'os_kernel'     :   DomainConfig.KERNEL_PATH,
            'os_initrd'     :   DomainConfig.RAMDISK_PATH,
            'disk_source'   :   DomainConfig.DISK_IMAGE_PATH
         }

if fieldname not in fields:
    sys.stdout.write("Unknown configuration element %s \n" % fieldname)
예제 #5
0
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

import sys
sys.path.append("/usr/share/rhn")
from virtualization.domain_config import DomainConfig

fieldname = sys.argv[1]
filename = sys.argv[2]
dc = DomainConfig('/usr/share/rhn/virt/auto', filename)

fields = {
    'name': DomainConfig.NAME,
    'uuid': DomainConfig.UUID,
    'memory': DomainConfig.MEMORY,
    'vcpu': DomainConfig.VCPU,
    'root_device': DomainConfig.ROOT_DEVICE,
    'cmdline': DomainConfig.COMMAND_LINE,
    'os_kernel': DomainConfig.KERNEL_PATH,
    'os_initrd': DomainConfig.RAMDISK_PATH,
    'disk_source': DomainConfig.DISK_IMAGE_PATH
}

if fieldname not in fields:
    sys.stdout.write("Unknown configuration element %s \n" % fieldname)