Пример #1
0
def _create_boot_config_file(name,
                             mem_kb,
                             vcpus,
                             uuid,
                             disk_image_path,
                             disk_image_type,
                             mac):
    """
    Writes reboot-specific XML out to a config file in our directory.
    """

    if DEBUG:
        mac = DEBUG_MAC_ADDRESS

    # Now write the XML blob out to a file so it can be reused later.
    domain_dir = DomainDirectory()
    try:
        domain_dir.create_standard_config(uuid,
                                          name,
                                          mem_kb,
                                          vcpus,
                                          disk_image_path,
                                          mac)
    except Exception, e:
        raise VirtualizationKickstartException, \
              "Error occurred while attempting to store config file %s: %s" % \
                  (str(uuid), str(e)), sys.exc_info()[2]
Пример #2
0
def start_domain(uuid):
    """
    Boots the domain for the first time after installation is complete.
    """
    # Load the configuration file for this UUID.
    domain = DomainDirectory()
    config = domain.load_config(uuid)

    # Connect to the hypervisor.
    connection = libvirt.open(None)

    # We will attempt to determine if the domain is configured to use a
    # bootloader.  If not, we'll have to explicitly use the kernel and initrd
    # data provided in the config to start the domain.
    try:
        config.getConfigItem(DomainConfig.BOOTLOADER)
    except DomainConfigError:
        dce = sys.exc_info()[1]
        # No bootloader tag present.  Use pygrub to extract the kernel from
        # the disk image if its Xen. For fully virt we dont have pygrub, it
        # directly emulates the BIOS loading the first sector of the boot disk.
        if connection.getType() == 'Xen':
            # This uses pygrub which comes only with xen
            _prepare_guest_kernel_and_ramdisk(config)

    # Now, we'll restart the instance, this time using the re-create XML.
    try:
        domain = connection.createLinux(config.toXML(), 0)
    except Exception:
        e = sys.exc_info()[1]
        raise_with_tb(VirtualizationException("Error occurred while attempting to recreate domain %s: %s" %
                                              (uuid, str(e))), sys.exc_info()[2])
Пример #3
0
def setVCPUs(uuid, vcpus):
    """
    Sets the number of vcpus for the domain with the given UUID.
    """
    domain_dir = DomainDirectory()
    config = domain_dir.load_config(uuid)
    config.setConfigItem(DomainConfig.VCPU, vcpus)
    config.save()
    domain_control.setVCPUs(uuid, vcpus)
Пример #4
0
def setMemory(uuid, memory):
    """
    Sets the max memory usage for the domain with the given UUID.
    """
    domain_dir = DomainDirectory()
    config = domain_dir.load_config(uuid)
    config.setConfigItem(DomainConfig.MEMORY, memory)
    config.save()
    domain_control.setMemory(uuid, memory)
Пример #5
0
def setVCPUs(uuid, vcpus):
    """
    Sets the number of vcpus for the domain with the given UUID.
    """
    domain_dir = DomainDirectory()
    config = domain_dir.load_config(uuid)
    config.setConfigItem(DomainConfig.VCPU, vcpus)
    config.save()
    domain_control.setVCPUs(uuid, vcpus)
Пример #6
0
def setMemory(uuid, memory):
    """
    Sets the max memory usage for the domain with the given UUID.
    """
    domain_dir = DomainDirectory()
    config = domain_dir.load_config(uuid)
    config.setConfigItem(DomainConfig.MEMORY, memory)
    config.save()
    domain_control.setMemory(uuid, memory)
Пример #7
0
def refresh(fail_on_error=False):
    """
    Refreshes the virtualization info for this host and any subdomains on the
    server.
    """
    if _is_host_domain(fail_on_error):
        domain_identity = IdentityType.HOST
        my_uuid = _fetch_host_uuid()
    else:
        # Not a host.  No-op.
        return

    # Now that we've gathered some preliminary information, create a plan of
    # actions that we will eventually pass to the server.
    plan = Plan()

    # First, declare our own existence.
    plan.add(
        EventType.EXISTS,
        TargetType.SYSTEM,
        { PropertyType.IDENTITY : domain_identity,
          PropertyType.UUID     : my_uuid          })

    # Now, crawl each of the domains on this host.
    if vdsm_enabled:
        server = localvdsm.connect()
        domains = poller.poll_through_vdsm(server)
    else:
        domains = poller.poll_hypervisor()

        if not len(domains) and libvirt.openReadOnly(None).getType() == 'Xen':
           # On a KVM/QEMU host, libvirt reports no domain entry for host itself
           # On a Xen host, either there were no domains or xend might not be
           # running. Don't proceed further.
           return
    domain_list = list(domains.values())
    domain_uuids = list(domains.keys())

    if not vdsm_enabled:
        # We need this only for libvirt
        domain_dir = DomainDirectory()
        domain_dir.save_unknown_domain_configs(domain_uuids)

    plan.add(EventType.CRAWL_BEGAN, TargetType.SYSTEM)
    for domain_properties in domain_list:
        plan.add(EventType.EXISTS, TargetType.DOMAIN, domain_properties)
    plan.add(EventType.CRAWL_ENDED, TargetType.SYSTEM)

    # Finally, execute the actions queued up in the plan.
    plan.execute()
Пример #8
0
def refresh(fail_on_error=False):
    """
    Refreshes the virtualization info for this host and any subdomains on the
    server.
    """
    if _is_host_domain(fail_on_error):
        domain_identity = IdentityType.HOST
        my_uuid = _fetch_host_uuid()
    else:
        # Not a host.  No-op.
        return

    # Now that we've gathered some preliminary information, create a plan of
    # actions that we will eventually pass to the server.
    plan = Plan()

    # First, declare our own existence.
    plan.add(
        EventType.EXISTS,
        TargetType.SYSTEM,
        { PropertyType.IDENTITY : domain_identity,
          PropertyType.UUID     : my_uuid          })

    # Now, crawl each of the domains on this host.
    if vdsm_enabled:
        server = localvdsm.connect()
        domains = poller.poll_through_vdsm(server)
    else:
        domains = poller.poll_hypervisor()

        if not len(domains) and libvirt.openReadOnly(None).getType() == 'Xen':
           # On a KVM/QEMU host, libvirt reports no domain entry for host itself
           # On a Xen host, either there were no domains or xend might not be
           # running. Don't proceed further.
           return
    domain_list = list(domains.values())
    domain_uuids = list(domains.keys())

    if not vdsm_enabled:
        # We need this only for libvirt
        domain_dir = DomainDirectory()
        domain_dir.save_unknown_domain_configs(domain_uuids)

    plan.add(EventType.CRAWL_BEGAN, TargetType.SYSTEM)
    for domain_properties in domain_list:
        plan.add(EventType.EXISTS, TargetType.DOMAIN, domain_properties)
    plan.add(EventType.CRAWL_ENDED, TargetType.SYSTEM)

    # Finally, execute the actions queued up in the plan.
    plan.execute()
Пример #9
0
def _create_boot_config_file(name, mem_kb, vcpus, uuid, disk_image_path,
                             disk_image_type, mac):
    """
    Writes reboot-specific XML out to a config file in our directory.
    """

    if DEBUG:
        mac = DEBUG_MAC_ADDRESS

    # Now write the XML blob out to a file so it can be reused later.
    domain_dir = DomainDirectory()
    try:
        domain_dir.create_standard_config(uuid, name, mem_kb, vcpus,
                                          disk_image_path, mac)
    except Exception, e:
        raise VirtualizationKickstartException, \
              "Error occurred while attempting to store config file %s: %s" % \
                  (str(uuid), str(e)), sys.exc_info()[2]
Пример #10
0
def start_domain(uuid):
    """
    Boots the domain for the first time after installation is complete.
    """
    # Load the configuration file for this UUID.
    domain = DomainDirectory()
    config = domain.load_config(uuid)

    # Connect to the hypervisor.
    connection = libvirt.open(None)

    # We will attempt to determine if the domain is configured to use a 
    # bootloader.  If not, we'll have to explicitly use the kernel and initrd 
    # data provided in the config to start the domain.
    try:
        config.getConfigItem(DomainConfig.BOOTLOADER)
    except DomainConfigError, dce:
        # No bootloader tag present.  Use pygrub to extract the kernel from
        # the disk image if its Xen. For fully virt we dont have pygrub, it
        # directly emulates the BIOS loading the first sector of the boot disk.
        if connection.getType() == 'Xen':
            # This uses pygrub which comes only with xen 
            _prepare_guest_kernel_and_ramdisk(config)
Пример #11
0
def start_domain(uuid):
    """
    Boots the domain for the first time after installation is complete.
    """
    # Load the configuration file for this UUID.
    domain = DomainDirectory()
    config = domain.load_config(uuid)

    # Connect to the hypervisor.
    connection = libvirt.open(None)

    # We will attempt to determine if the domain is configured to use a
    # bootloader.  If not, we'll have to explicitly use the kernel and initrd
    # data provided in the config to start the domain.
    try:
        config.getConfigItem(DomainConfig.BOOTLOADER)
    except DomainConfigError, dce:
        # No bootloader tag present.  Use pygrub to extract the kernel from
        # the disk image if its Xen. For fully virt we dont have pygrub, it
        # directly emulates the BIOS loading the first sector of the boot disk.
        if connection.getType() == 'Xen':
            # This uses pygrub which comes only with xen
            _prepare_guest_kernel_and_ramdisk(config)
Пример #12
0
        # will cause cron to email root with the output. It is not our
        # job to nag the user every two minutes if libvirt is not running.
        # The only way to avoid this is to shell out to check if libvirt
        # is running, and exit if it's not.
        # See if the libvirtd service is running, discarding all output.
        # Non-zero exit code means it's not running.
        if (subprocess.call(['/sbin/service','libvirtd','status'],
                stdout=open(os.devnull, 'wb'),
                stderr=subprocess.STDOUT) != 0):
            sys.exit(0)
        domain_list = poll_hypervisor()
    else:
        # If no libvirt nor vdsm is present, this program is pretty much
        # useless.  Just exit.
        sys.exit(0)

    # create the unkonwn domain config files (for libvirt only)
    if libvirt and not vdsm_enabled:
        uuid_list = list(domain_list.keys())
        domain = DomainDirectory()
        domain.save_unknown_domain_configs(uuid_list)

    cached_state = PollerStateCache(domain_list,
                                    debug = options and options.debug)

    # Send notifications, if necessary.
    _send_notifications(cached_state)

    # Save the new state.
    cached_state.save()