Exemple #1
0
def rename(profile_source, plugin, new_name):
    """Rename the plugin"""
    old_location = Path(profile_source.location) / "plugins" / (plugin + ".py")
    new_location = Path(
        profile_source.location) / "plugins" / (new_name + ".py")
    move(old_location, new_location)
    LOGGER.status(f"Moved {old_location} into {new_location}")
Exemple #2
0
def install_dependencies():
    """Install the dependencies needed to setup the stack"""
    download(k3d_url, outdir=bindir, outfilename="k3d", mode=0o755)
    with tempdir() as d:
        extract(helm_url, d)
        move(Path(d) / "linux-amd64" / "helm", bindir / "helm")
        (bindir / "helm").chmod(0o755)
    download(kubectl_url, outdir=bindir, outfilename="kubectl", mode=0o755)
Exemple #3
0
def rename(old, new):
    """Rename a recipe"""
    if "/" not in new:
        new = "{}/{}".format(old.name.split("/")[0], new)
    new_loc = config.recipe_location(new)
    if os.path.exists(new_loc):
        raise click.UsageError("{} already exists".format(new_loc))
    move(old.location, new_loc)
Exemple #4
0
    def recipes_instead_of_settings_level(self):
        if self.isrecipe:
            return True
        recipes_dir = self.location + "/recipes/"

        def migrate_settings_to_recipe(settings_level_file, name):
            if open(settings_level_file,
                    "rb").read().decode("utf-8").strip() == "{}":
                return False
            makedirs(recipes_dir + "/" + name)
            enabled = not json.load(open(settings_level_file)).get(
                "_self", {}).get("disabled", False)
            order = json.load(open(settings_level_file)).get("_self", {}).get(
                "order", 100)
            move(settings_level_file,
                 recipes_dir + "/" + name + "/{}.json".format(self.app_name))
            createfile(recipes_dir + "/" + name + "/version.txt",
                       str(self.version + 1))
            createfile(recipes_dir + "/" + name + ".json",
                       json.dumps({
                           "enabled": enabled,
                           "order": order,
                       }))
            return True

        migrate_something = False
        for settings_level_file in glob(self.location +
                                        "/{}-*.json".format(self.app_name)):
            name = re.sub(".+{}-([a-zA-Z-]+).json$".format(self.app_name),
                          r"\1", settings_level_file)
            name = name.replace("-", "_")
            if name == "private":
                continue
            migrate_something |= migrate_settings_to_recipe(
                settings_level_file, name + "_from_settings")
        private = self.location + "/{}-private.json".format(self.app_name)
        local = self.location + "/{}.json".format(self.app_name)
        if os.path.exists(private):
            if open(private, "rb").read().decode("utf-8").strip() != "{}":
                migrate_something = True
            else:
                rm(private)
        if migrate_something is True:
            name = "migrated_local"
            if os.path.exists(local) and not open(
                    local, "rb").read().decode("utf-8").strip() == "{}":
                migrate_settings_to_recipe(local, name)
            if os.path.exists(private):
                move(private, local)
            with json_file(local) as values:
                recipes = values.get("recipe", {})
                local_order = recipes.get(name, {})
                local_order["order"] = 0
                recipes[name] = local_order
                values["recipe"] = recipes
            self.computed_location = None
            self.compute_settings()
        return True
Exemple #5
0
def _move(customcommand, profile, force):
    """Move a custom commands"""
    new_location = Path(profile.location) / "bin" / Path(
        customcommand.customcommand_path).name
    if new_location.exists() and not force:
        raise click.UsageError(f"I won't overwrite {new_location},"
                               " unless called with --force")
    makedirs(new_location.parent)
    move(customcommand.customcommand_path, new_location)
    LOGGER.status(
        f"Moved {customcommand.customcommand_path} into {new_location}")
Exemple #6
0
def _move(profile_source, plugin, profile_destination, force):
    """Move a custom commands"""
    old_location = Path(profile_source.location) / "plugins" / (plugin + ".py")
    new_location = Path(
        profile_destination.location) / "plugins" / (plugin + ".py")
    if new_location.exists() and not force:
        raise click.UsageError(f"I won't overwrite {new_location},"
                               " unless called with --force")
    makedirs(new_location.parent)
    move(old_location, new_location)
    LOGGER.status(f"Moved {old_location} into {new_location}")
Exemple #7
0
 def recipes_instead_of_profiles(self):
     if self.isrecipe:
         return True
     recipes_dir = self.location + "/recipes/"
     warn = False
     for profile in glob(self.location + "/../.csm-*"):
         profile_name = re.sub("^.+csm-(.+)$", r"\1", profile)
         recipe_location = recipes_dir + "/" + profile_name + "_from_profile"
         move(profile, recipe_location)
         warn = True
     if warn:
         LOGGER.warning("The profiles were migrated as recipes."
                        " As we could not maintain backward compatibility,"
                        " please see with SLO or GLE to understand how"
                        " to make use of this new setup")
     return True
Exemple #8
0
 def migrate_settings_to_recipe(settings_level_file, name):
     if open(settings_level_file, "rb").read().decode("utf-8").strip() == "{}":
         return False
     makedirs(recipes_dir + "/" + name)
     enabled = not json.load(open(settings_level_file)).get("_self", {}).get("disabled", False)
     order = json.load(open(settings_level_file)).get("_self", {}).get("order", 100)
     move(settings_level_file, recipes_dir + "/" + name + "/{}.json".format(self.app_name))
     createfile(recipes_dir + "/" + name + "/version.txt", str(self.version + 1))
     createfile(recipes_dir + "/" + name + ".json", json.dumps(
         {
             "enabled": enabled,
             "order": order,
         }
     )
     )
     return True
Exemple #9
0
def _move(old, profile):
    """Move a recipe to another profile"""
    move(old.location,
         Path(profile.location) / "recipes" / Path(old.location).name)