def initiate(base, extra_append, static_device=None, preserve_files=[]): # XXX it's bad to hardcode each special case, but this is the only one I # can think of... if os.path.exists(ELILO_BOOT): base_dir = os.path.join(PREFIX, ELILO_BOOT, RHN_KS_DIR, base) else: base_dir = os.path.join(PREFIX, BOOT, RHN_KS_DIR, base) try: # First, download the kickstart file. kickstart_config = common.download_kickstart_file(extra_append) # This hack sucks, but it works around a race condition dealing with # the tiny url generation on the server. Basically, if we request # the download images too soon after receiving the ks config file, we # are served a 404. We'll remove this hack when we figure out what the # server-side issue is. time.sleep(5) # Download the kernel and initrd images. if os.path.exists(ZIPL_CONF): pxe_dir = "images" else: pxe_dir = "images/pxeboot" (kernel, initrd) = \ common.download_install_images(kickstart_config, pxe_dir, base_dir) except KickstartException, e: return (15, str(e), {})
def initiate_guest(name, mem_kb, vcpus, disk_gb, extra_append, log_notify_handler=None): files_to_cleanup = [] # We'll wrap this up in a try block so that we can clean up should an # exception occur. try: # First, download the kickstart file. kickstart_config = common.download_kickstart_file(extra_append) # This hack sucks, but it works around a race condition dealing with # the tiny url generation on the server. Basically, if we request # the download images too soon after receiving the ks config file, we # are served a 404. We'll remove this hack when we figure out what the # server-side issue is. time.sleep(5) # Download the kernel and initrd images. (install_kernel_path, install_initrd_path) = \ common.download_install_images(kickstart_config, "images/xen", XEN_INSTALL_IMAGE_DIR) files_to_cleanup.append(install_kernel_path) files_to_cleanup.append(install_initrd_path) # Create the disk image for the instance. disk_image_path = _create_disk_image(name, disk_gb) files_to_cleanup.append(disk_image_path) # Determine the type of disk image. disk_image_type = _determine_disk_image_type(disk_image_path) # Generate a UUID for this new instance. uuid = _generate_uuid() # Generate a MAC address for this new instance. if DEBUG: mac = DEBUG_MAC_ADDRESS else: mac = _generate_mac_address() # Connect to the hypervisor. connection = _connect_to_hypervisor() # Now we have enough information to actually create and install the # domain. domain = _begin_domain_installation( \ connection, name = name, install_kernel_path = install_kernel_path, install_initrd_path = install_initrd_path, extra_append = extra_append, mem_kb = mem_kb, vcpus = vcpus, uuid = uuid, disk_image_path = disk_image_path, disk_image_type = disk_image_type, mac = mac) # Wait for the domain's installation to complete. We must do this so # that we can restart the domain with a runnable configuration. _wait_for_domain_installation_completion(connection, domain) _check_guest_mbr(disk_image_path) # Write out the configuration file. config_file_path = _create_boot_config_file( \ name = name, mem_kb = mem_kb, vcpus = vcpus, uuid = uuid, disk_image_path = disk_image_path, disk_image_type = disk_image_type, mac = mac) files_to_cleanup.append(config_file_path) # Restart the domain with the new configuration. _boot_domain(uuid) # The domain is now started. Finally, refresh the current # virtualization state on the server. # VCPUs get plugged in one at a time, querying the hypervisor state # too soon was resulting in 1 always being returned. Sleep here # allows the hypervisor to plug in the VCPUs and us to get the correct # value reported back in RHN: time.sleep(5) virt_support.refresh() # If we got here, we know everything went ok. We'll only remove the # temporary installation kernel and initrd files. files_to_cleanup = [] files_to_cleanup.append(install_kernel_path) files_to_cleanup.append(install_initrd_path) finally: # If something went wrong, the logic will bounce out here before # returning to the caller. We'll use this opportunity to clean up # any files that we might have created so far. It would be quite rude # to leave multi-GB sized files laying around. for file in files_to_cleanup: if os.path.exists(file): os.unlink(file)