def check_location(self): if self._location_is_path: # We already mostly validated this return True else: # This will throw an error for us OSDistro.detectMediaDistro(location=self.location, arch=self.arch) return True
def _prepare_kernel_and_initrd(self, guest, meter): disk = None # If installing off a local path, map it through to a virtual CD/disk if (self.location is not None and self._location_is_path and not os.path.isdir(self.location)): device = VirtualDisk.DEVICE_CDROM # pylint: disable=W0212 # Access to protected member lookup_osdict_key can_cdrom = guest._lookup_osdict_key('pv_cdrom_install') # pylint: enable=W0212 if self.is_xenpv() and can_cdrom: device = VirtualDisk.DEVICE_DISK disk = VirtualDisk(conn=guest.conn, device=device, path=self.location, readOnly=True, transient=True) # Make sure we always fetch kernel here if required if self._install_bootconfig.kernel and not self.scratchdir_required(): return disk # Need to fetch the kernel & initrd from a remote site, or # out of a loopback mounted disk image/device ignore, os_type, os_variant, media = OSDistro.getKernel( guest, self.location, meter, self.scratchdir, self.os_type) (kernelfn, initrdfn, args) = media if guest.get_os_autodetect(): if os_type: logging.debug("Auto detected OS type as: %s", os_type) guest.os_type = os_type if (os_variant and guest.os_type == os_type): logging.debug("Auto detected OS variant as: %s", os_variant) guest.os_variant = os_variant self._tmpfiles.append(kernelfn) if initrdfn: self._tmpfiles.append(initrdfn) if self._initrd_injections: self._perform_initrd_injections(initrdfn) # If required, upload media to an accessible guest location kernelfn, initrdfn = self._upload_media(guest, meter, kernelfn, initrdfn) self._install_bootconfig.kernel = kernelfn self._install_bootconfig.initrd = initrdfn self._install_bootconfig.kernel_args = args return disk
def detect_distro(self): try: dist_info = OSDistro.detectMediaDistro(location=self.location, arch=self.arch) except: logging.exception("Error attempting to detect distro.") return (None, None) # detectMediaDistro should only return valid values dtype, dvariant = dist_info return (dtype, dvariant)
def _getStore(self, fetcher, url, _type, arch): for ignore in range(0, 10): try: return OSDistro._storeForDistro(fetcher=fetcher, baseuri=url, progresscb=self.meter, arch=arch, typ=_type) except Exception, e: if str(e).count("502"): logging.debug("Caught proxy error: %s", str(e)) time.sleep(.5) continue raise
def _prepare_kernel_and_initrd(self, guest, meter): disk = None # If installing off a local path, map it through to a virtual CD/disk if self.location is not None and self._location_is_path and not os.path.isdir(self.location): device = VirtualDisk.DEVICE_CDROM # pylint: disable=W0212 # Access to protected member lookup_osdict_key can_cdrom = guest._lookup_osdict_key("pv_cdrom_install") # pylint: enable=W0212 if self.is_xenpv() and can_cdrom: device = VirtualDisk.DEVICE_DISK disk = VirtualDisk(conn=guest.conn, device=device, path=self.location, readOnly=True, transient=True) # Make sure we always fetch kernel here if required if self._install_bootconfig.kernel and not self.scratchdir_required(): return disk # Need to fetch the kernel & initrd from a remote site, or # out of a loopback mounted disk image/device ignore, os_type, os_variant, media = OSDistro.getKernel( guest, self.location, meter, self.scratchdir, self.os_type ) (kernelfn, initrdfn, args) = media if guest.get_os_autodetect(): if os_type: logging.debug("Auto detected OS type as: %s", os_type) guest.os_type = os_type if os_variant and guest.os_type == os_type: logging.debug("Auto detected OS variant as: %s", os_variant) guest.os_variant = os_variant self._tmpfiles.append(kernelfn) if initrdfn: self._tmpfiles.append(initrdfn) if self._initrd_injections: self._perform_initrd_injections(initrdfn) # If required, upload media to an accessible guest location kernelfn, initrdfn = self._upload_media(guest, meter, kernelfn, initrdfn) self._install_bootconfig.kernel = kernelfn self._install_bootconfig.initrd = initrdfn self._install_bootconfig.kernel_args = args return disk
def _fetchFromURLDict(self, distname, url, arch, distro_info, check_xen): logging.debug("\nDistro='%s' arch='%s' url=%s", distname, arch, url) fetcher = OSDistro._fetcherForURI(url, "/tmp") try: fetcher.prepareLocation() except Exception, e: # Don't raise an error here: the site might be down atm logging.error("%s-%s: Couldn't access url %s: %s. Skipping.", distname, arch, fetcher.location, str(e)) fetcher.cleanupLocation() return
def _fetchLocalMedia(self, mediapath): arch = platform.machine() fetcher = OSDistro._fetcherForURI(mediapath, "/tmp") try: fetcher.prepareLocation() # Make sure we detect _a_ distro hvmstore = self._getStore(fetcher, mediapath, "hvm", arch) logging.debug("Local distro detected as: %s", hvmstore) finally: fetcher.cleanupLocation()
def _fetchLocalMedia(self, mediapath): arch = platform.machine() fetcher = OSDistro._fetcherForURI(mediapath, "/tmp") try: fetcher.prepareLocation() # Make sure we detect _a_ distro hvmstore = self._getStore(fetcher, mediapath, "hvm", arch) logging.debug("Local distro detected as: %s" % hvmstore) finally: fetcher.cleanupLocation()
def _prepare_cdrom(self, guest, meter): transient = not self.livecd if not self._location_is_path: # Xen needs a boot.iso if its a http://, ftp://, or nfs: url (store_ignore, os_type_ignore, os_variant_ignore, media) = OSDistro.getBootDisk( guest, self.location, meter, self.scratchdir ) cdrom = media self._tmpfiles.append(cdrom) transient = True else: cdrom = self.location disk = VirtualDisk( path=cdrom, conn=guest.conn, device=VirtualDisk.DEVICE_CDROM, readOnly=True, transient=transient ) self.install_devices.append(disk)
def _prepare_cdrom(self, guest, meter): transient = not self.livecd if not self._location_is_path: # Xen needs a boot.iso if its a http://, ftp://, or nfs: url (store_ignore, os_type_ignore, os_variant_ignore, media) = OSDistro.getBootDisk(guest, self.location, meter, self.scratchdir) cdrom = media self._tmpfiles.append(cdrom) transient = True else: cdrom = self.location disk = VirtualDisk(path=cdrom, conn=guest.conn, device=VirtualDisk.DEVICE_CDROM, readOnly=True, transient=transient) self.install_devices.append(disk)