Beispiel #1
0
 def isUpToDate(self,imageSource):
   installedImage = imageSource.getLatestInstalledImage()
   if installedImage is None:
     return False
   if not installedImage.isDockerImageThere():
     return False
   targetLineage = getTargetLineage(imageSource)
   installedLineage = installedImage.getImageLineage()
   if not (len(targetLineage) == len(installedLineage)):
     return False
   sideBySideLineages = zip(installedLineage,targetLineage)
   for installed,target in sideBySideLineages:
     if target in self.__outOfDateImageSources:
       return False
     if not installed.getImageId() == target.getLatestInstalledImage().getImageId():
       return False
   if not installedImage.getImageSourceHash() == imageSource.getHash():
     return False
   if self.checkForUpdatesExternally and installedImage.checkForUpdates():
     return False
   return True
Beispiel #2
0
 def isUpToDate(self,imageSource):
   installedImage = imageSource.getLatestInstalledImage()
   if installedImage is None:
     return False
   if not installedImage.isDockerImageThere():
     return False
   targetLineage = getTargetLineage(imageSource)
   installedLineage = installedImage.getImageLineage()
   if not (len(targetLineage) == len(installedLineage)):
     return False
   sideBySideLineages = zip(installedLineage,targetLineage)
   for installed,target in sideBySideLineages:
     if target in self.__outOfDateImageSources:
       return False
     if not installed.getImageId() == target.getLatestInstalledImage().getImageId():
       return False
   if not installedImage.getImageSourceHash() == imageSource.getHash():
     return False
   if self.checkForUpdatesExternally and installedImage.checkForUpdates():
     return False
   return True
Beispiel #3
0
    def save(self):
        """ Save attributes of the installed images to disk. """
        # Build a dictionary of installed images.
        installedImagesDict = {}
        for _, installedImage in self.items():
            imageAttributes = {}
            imageAttributes[
                "image-source-hash"] = installedImage.getImageSourceHash()
            imageAttributes[
                "image-source"] = installedImage.getImageSourceName()
            imageAttributes["source-repo"] = installedImage.getSourceRepoId()
            installedImagesDict[installedImage.getImageId()] = imageAttributes

        # Write that dictionary to disk.
        installedImagesPath = self.getUser().getConfig(
        )["installed-images-list"]
        with open(installedImagesPath, 'w') as file_f:
            json.dump(installedImagesDict,
                      file_f,
                      indent=1,
                      separators=(',', ': '))
Beispiel #4
0
def compareSourceLineageAndInstalledImageLineage(user, sourceLineage,
                                                 installedImageLineage):
    if not len(list(sourceLineage)) == len(installedImageLineage):
        user.getRegistry().log("Number of dependencies changed from " +
                               str(len(installedImageLineage)) + " to " +
                               str(len(sourceLineage)))
        print("Image sources:")
        for imageSource in sourceLineage:
            print(imageSource.getName())
        print("Installed images:")
        for installedImage in installedImageLineage:
            print(installedImage.getImageSourceName())
        return False
    lineage = zip(sourceLineage, installedImageLineage)
    for imageSource, installedImage in lineage:
        imagesMatch = doImagesMatch(installedImage, imageSource)
        imageSourceHashesMatch = doImageSourceHashesMatch(
            installedImage, imageSource)
        if not (imagesMatch and imageSourceHashesMatch):
            if not imagesMatch:
                user.getRegistry().log("Dependency changed for image from " +
                                       installedImage.getImageSourceName() +
                                       "@" + installedImage.getSourceRepoId() +
                                       " to " + imageSource.getName() + "@" +
                                       imageSource.getRepository().getName())
            elif not imageSourceHashesMatch:
                user.getRegistry().log(
                    "Installed image " + installedImage.getImageSourceName() +
                    "@" + installedImage.getSourceRepoId() +
                    " is out of date.\nCurrently installed from image source:\n "
                    + installedImage.getImageSourceHash() +
                    "\nCurrent version:\n " +
                    str(imageSource.getPermissions()["last-update-time"]) +
                    "\n")
            return False
    return True
Beispiel #5
0
def compareSourceLineageAndInstalledImageLineage(user,sourceLineage,installedImageLineage):
  if not len(sourceLineage) == len(installedImageLineage):
    user.getRegistry().log("Number of dependencies changed from "+str(len(installedImageLineage))+" to "+str(len(sourceLineage)))
    print("Image sources:")
    for imageSource in sourceLineage:
      print(imageSource.getName())
    print("Installed images:")
    for installedImage in installedImageLineage:
      print(installedImage.getImageSourceName())
    return False

  lineage = zip(sourceLineage,installedImageLineage)
  for imageSource,installedImage in lineage:
    imagesMatch =  doImagesMatch(installedImage,imageSource)
    imageSourceHashesMatch = doImageSourceHashesMatch(installedImage,imageSource)
    if not (imagesMatch and imageSourceHashesMatch):
      if not imagesMatch:
        user.getRegistry().log("Dependency changed for image from "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId()+" to "+imageSource.getName()+"@"+imageSource.getRepository().getName())
      elif not imageSourceHashesMatch:
        user.getRegistry().log("Installed image "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId()+" is out of date.\nCurrently installed from image source:\n "+installedImage.getImageSourceHash()+"\nCurrent version:\n "+str(imageSource.getPermissions()["last-update-time"])+"\n")
      return False
  return True
Beispiel #6
0
def doImageSourceHashesMatch(installedImage,imageSource):
  return installedImage.getImageSourceHash() == imageSource.getHash()
Beispiel #7
0
def doImageSourceHashesMatch(installedImage,imageSource):
  return installedImage.getImageSourceHash() == imageSource.getHash()