def ensureFileDownloaded(self): if self._finishedDownloading: return True self._localLocation = downloadLocally(self.fullSrcPath, integrityChecker=self.integrityChecker) self._finishedDownloading = True return True
def ensureFileDownloaded(self): if self._finishedDownloading: return True self._localLocation = downloadLocally( self.fullSrcPath, integrityChecker=self.integrityChecker) self._finishedDownloading = True return True
def _getLocalPath(self, baseLocation): baseLocation = URLify(baseLocation) placesToTry = [urljoin(baseLocation, 'packageData.pkl')] for place in placesToTry: log.debug('Looking for %s' % place) try: filename = downloadLocally(place) return filename except (HTTPError, URLError, IOError, RemoteFileError): continue raise ValueError('Could not find packageData.pkl file under %s' % baseLocation)
def getPackagesXML(supportedPackageGroups): mediaLocation = userchoices.getMediaLocation() if mediaLocation: mediaRoot = mediaLocation['mediaLocation'] url = urljoin(mediaRoot, 'packages.xml') else: mediaRoot = consts.MEDIA_DEVICE_MOUNT_POINT url = urljoin(URLify(os.path.join(mediaRoot, '')), 'packages.xml') try: packagesXMLPath = downloadLocally(url, maxAttempts=3) except RemoteFileError: msg = 'packages.xml was not found on the remote server.' log.error(msg) raise return PackagesXML(supportedPackageGroups, packagesXMLPath, mediaRoot)
def hostActionUpdateEsxupdateDatabase(_context): '''Updates the esxudpate database with any meta-data on the source image.''' # In a nutshell: # 1. Copy metadata.zip from source image to host root (/mnt/sysimage). # 2. Run esxupdate syncdb command in /mnt/sysimage chroot. # 3. Remove metadata.zip from host root. # It would be nice if we could just import an esxupdate module and call a # function or method to do this. Unfortunately, esxupdate has a lot of # dependencies on configuration files and a database being in a certain # place, so it's just easier to call the esxupdate command line from a # chroot environment. mediaroot = userchoices.getMediaLocation().get( 'mediaLocation', 'file://' + consts.MEDIA_DEVICE_MOUNT_POINT ) if not mediaroot.endswith('/'): mediaroot += '/' metasrc = urlparse.urljoin(mediaroot, 'metadata.zip') # Squelching any metadata.zip errors/warnings. See PR:428781 # We increase the log level required to print to tty6 to a ridiculous level, # then return it to normal. import scui err = None if scui.tty6Handler: prevLevel = scui.tty6Handler.level scui.tty6Handler.setLevel(9001) try: metadst = remote_files.downloadLocally(metasrc, clobberCache = True) if os.path.getsize(metadst) == 0: log.warn("The server gave '%s' as an empty file" % metadst) os.unlink(metadst) err = True except Exception, err: # downloadLocally() function doesn't distinguish between not found and # transfer or other error. log.warn('Esxupdate meta-data not present or not retrievable: %s' % err)
def hostActionUpdateEsxupdateDatabase(_context): '''Updates the esxudpate database with any meta-data on the source image.''' # In a nutshell: # 1. Copy metadata.zip from source image to host root (/mnt/sysimage). # 2. Run esxupdate syncdb command in /mnt/sysimage chroot. # 3. Remove metadata.zip from host root. # It would be nice if we could just import an esxupdate module and call a # function or method to do this. Unfortunately, esxupdate has a lot of # dependencies on configuration files and a database being in a certain # place, so it's just easier to call the esxupdate command line from a # chroot environment. mediaroot = userchoices.getMediaLocation().get( 'mediaLocation', 'file://' + consts.MEDIA_DEVICE_MOUNT_POINT) if not mediaroot.endswith('/'): mediaroot += '/' metasrc = urlparse.urljoin(mediaroot, 'metadata.zip') # Squelching any metadata.zip errors/warnings. See PR:428781 # We increase the log level required to print to tty6 to a ridiculous level, # then return it to normal. import scui err = None if scui.tty6Handler: prevLevel = scui.tty6Handler.level scui.tty6Handler.setLevel(9001) try: metadst = remote_files.downloadLocally(metasrc, clobberCache=True) if os.path.getsize(metadst) == 0: log.warn("The server gave '%s' as an empty file" % metadst) os.unlink(metadst) err = True except Exception, err: # downloadLocally() function doesn't distinguish between not found and # transfer or other error. log.warn('Esxupdate meta-data not present or not retrievable: %s' % err)
def _downloadHeaderFragment(self): self._localLocation = downloadLocally(self.fullSrcPath, self._headerLength) self._header = self.readRPMHeader(self.localLocation)
def __init__(self, supportedPackageGroups, fullPath="packages.xml", mediaRoot="."): '''Warning: the constructor can potentially raise remote_files exceptions. ''' log.debug("Reading packages.xml...") getTagText = XMLGetTextInUniqueElement # handy alias if isURL(fullPath): # this can potentially raise HTTPError or URLError log.debug('Downloading the packages.xml file') fullPath = downloadLocally(fullPath, integrityChecker=self.parse) doc = self.parse(fullPath, shouldRaise=True) products = doc.getElementsByTagName("product") if len(products) != 1: log.warn('Expected to find only one <product> in packages.xml') product = products[0] self.name = getTagText(product, 'name') self.esxVersion = getTagText(product, 'esx_version') self.esxThirdPartyVersion = getTagText(product, 'esx_tp_version') self.esxThirdPartyCompatVersion = getTagText(product, 'esx_tp_compat_version') self.release = '%s.%s' % (getTagText(product, 'esx_release'), getTagText(product, 'release')) # bootloader.py needs these two self.kernLabel = getTagText(product, "kernel_name") self.kernVersion = getTagText(product, "kernel_version") self.installDepot = getTagText(product, 'install_depot') if isURL(mediaRoot): self.fullInstallDepot = urljoin(mediaRoot, self.installDepot) else: self.fullInstallDepot = os.path.join(mediaRoot, self.installDepot) log.info("Full install depot is %s" % (self.fullInstallDepot)) self.rpmBasenames = [] for depot in doc.getElementsByTagName("depot"): element = depot.getAttribute("name") if supportedPackageGroups != None: #NOTE: [] != None if element not in supportedPackageGroups: log.debug("Skipping depot %s" % (element)) continue for rpmlist in depot.getElementsByTagName("rpmlist"): repo = rpmlist.getAttribute('repo') for node in rpmlist.getElementsByTagName("rpm"): archOpt = node.getAttribute("arch") #TODO: at some point 'both' should be 'i386,x86_64' and we # should split on ',' if archOpt == "both": archList = ['i386', 'x86_64'] else: archList = [getTagText(depot, 'arch')] reqOpt = node.getAttribute("requirement").lower() if reqOpt not in REQUIREMENT_OPTIONS: reqOpt = "required" package = node.getAttribute('package') changeset = node.getAttribute('changeset') for arch in archList: basename = XMLGetText(node) basename = basename.replace("${esx_version}", self.esxVersion) basename = basename.replace("${esx_tp_version}", self.esxThirdPartyVersion) basename = basename.replace("${esx_tp_compat_version}", self.esxThirdPartyCompatVersion) basename = basename.replace("${release}", self.release) basename = basename.replace("${driver_release}", self.release) basename = basename.replace("${arch}", arch) basename = basename.replace('${repo}', repo) basename = basename.replace('${package}', package) basename = basename.replace('${changeset}', changeset) self.rpmBasenames.append((basename, reqOpt))
packagesXMLLocation = mediaRootURL +'/packages.xml' def integrityChecker(localPath): try: xml.dom.minidom.parse(localPath) except ExpatError, ex: log.warn('XML parsing error on file: %s' % packagesXMLLocation) return False return True oldTimeout = socket.getdefaulttimeout() socket.setdefaulttimeout(30) # 30 seconds success = False try: downloadLocally(packagesXMLLocation, clobberCache=True, integrityChecker=integrityChecker, maxAttempts=1) success = True except Exception, ex: log.info('Media Root invalid. Got exception: %s (%s)' % (ex.__class__.__name__,str(ex))) socket.setdefaulttimeout(oldTimeout) return success # ----------------------------------------------------------------------------- class PackageData(object): '''Container class for package header files and sizes of the unpacked directories. This replaces the Primary.xml file. Accessible attributes: .fileDict : dictionary of unpacked directory sizes .headerSizes : dictionary of begin/end/header sizes for each pkg
def __init__(self, supportedPackageGroups, fullPath="packages.xml", mediaRoot="."): '''Warning: the constructor can potentially raise remote_files exceptions. ''' log.debug("Reading packages.xml...") getTagText = XMLGetTextInUniqueElement # handy alias if isURL(fullPath): # this can potentially raise HTTPError or URLError log.debug('Downloading the packages.xml file') fullPath = downloadLocally(fullPath, integrityChecker=self.parse) doc = self.parse(fullPath, shouldRaise=True) products = doc.getElementsByTagName("product") if len(products) != 1: log.warn('Expected to find only one <product> in packages.xml') product = products[0] self.name = getTagText(product, 'name') self.esxVersion = getTagText(product, 'esx_version') self.esxThirdPartyVersion = getTagText(product, 'esx_tp_version') self.esxThirdPartyCompatVersion = getTagText(product, 'esx_tp_compat_version') self.release = '%s.%s' % (getTagText( product, 'esx_release'), getTagText(product, 'release')) # bootloader.py needs these two self.kernLabel = getTagText(product, "kernel_name") self.kernVersion = getTagText(product, "kernel_version") self.installDepot = getTagText(product, 'install_depot') if isURL(mediaRoot): self.fullInstallDepot = urljoin(mediaRoot, self.installDepot) else: self.fullInstallDepot = os.path.join(mediaRoot, self.installDepot) log.info("Full install depot is %s" % (self.fullInstallDepot)) self.rpmBasenames = [] for depot in doc.getElementsByTagName("depot"): element = depot.getAttribute("name") if supportedPackageGroups != None: #NOTE: [] != None if element not in supportedPackageGroups: log.debug("Skipping depot %s" % (element)) continue for rpmlist in depot.getElementsByTagName("rpmlist"): repo = rpmlist.getAttribute('repo') for node in rpmlist.getElementsByTagName("rpm"): archOpt = node.getAttribute("arch") #TODO: at some point 'both' should be 'i386,x86_64' and we # should split on ',' if archOpt == "both": archList = ['i386', 'x86_64'] else: archList = [getTagText(depot, 'arch')] reqOpt = node.getAttribute("requirement").lower() if reqOpt not in REQUIREMENT_OPTIONS: reqOpt = "required" package = node.getAttribute('package') changeset = node.getAttribute('changeset') for arch in archList: basename = XMLGetText(node) basename = basename.replace("${esx_version}", self.esxVersion) basename = basename.replace("${esx_tp_version}", self.esxThirdPartyVersion) basename = basename.replace( "${esx_tp_compat_version}", self.esxThirdPartyCompatVersion) basename = basename.replace("${release}", self.release) basename = basename.replace("${driver_release}", self.release) basename = basename.replace("${arch}", arch) basename = basename.replace('${repo}', repo) basename = basename.replace('${package}', package) basename = basename.replace('${changeset}', changeset) self.rpmBasenames.append((basename, reqOpt))
packagesXMLLocation = mediaRootURL + '/packages.xml' def integrityChecker(localPath): try: xml.dom.minidom.parse(localPath) except ExpatError, ex: log.warn('XML parsing error on file: %s' % packagesXMLLocation) return False return True oldTimeout = socket.getdefaulttimeout() socket.setdefaulttimeout(30) # 30 seconds success = False try: downloadLocally(packagesXMLLocation, clobberCache=True, integrityChecker=integrityChecker, maxAttempts=1) success = True except Exception, ex: log.info('Media Root invalid. Got exception: %s (%s)' % (ex.__class__.__name__, str(ex))) socket.setdefaulttimeout(oldTimeout) return success # ----------------------------------------------------------------------------- class PackageData(object): '''Container class for package header files and sizes of the unpacked directories. This replaces the Primary.xml file. Accessible attributes: .fileDict : dictionary of unpacked directory sizes