Beispiel #1
0
    def execute(self):
        """
        migrate storage
        """
        repo = repository.PickleRepository(self.params.storage_path)

        clusters = [
            i[:-7] for i in os.listdir(self.params.storage_path)
            if i.endswith('.pickle')
        ]

        if self.params.cluster:
            clusters = filter(lambda x: x in self.params.cluster, clusters)

        if not clusters:
            print("No clusters")
            sys.exit(0)

        patch_cluster()
        for cluster in clusters:
            print("Cluster `%s`" % cluster)
            print("path: %s" % repo.storage_path + '/%s.pickle' % cluster)
            cl = repo.get(cluster)
            if cl._patches:
                print("Attributes changed: ")
                for attr, val in cl._patches.items():
                    print("  %s: %s -> %s" % (attr, val[0], val[1]))
            else:
                print("No upgrade needed")

            print("")
            if not self.params.dry_run:
                if cl._patches:
                    del cl._patches
                    print("Changes saved to disk")
                    cl.repository.save_or_update(cl)
Beispiel #2
0
    if 'known_hosts_file' not in state:
        self.known_hosts_file = None
    if 'template' not in state:
        self.template = self.extra['template']
    if 'thread_pool_max_size' not in state:
        self.thread_pool_max_size = 10

cluster.Cluster.__setstate__ = __fix_setstate__

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("""This script is used to migrate clusters created with older version of Elasticluster to the latest one.""")
        print("Usage: %s storagepath [clustername]" % sys.argv[0])
        sys.exit(1)    

    storage_path = os.path.expanduser(sys.argv[1])
    repository = repository.PickleRepository(storage_path)
    clusters = repository.get_all()

    for cluster in clusters:
        # Fix known_hosts file missing attribute
        known_hosts_file = "%s/%s.known_hosts" % (storage_path, cluster.name)
        if os.path.isfile(known_hosts_file) and known_hosts_file != cluster.known_hosts_file:
            cluster.known_hosts_file = known_hosts_file
            
    for cl in clusters:
        print("Saving cluster %s" % cl.name)
        cl.repository.save_or_update(cl)