Exemple #1
0
def set(ctx, component, key, value):
    """
    Set a specific configuration attribute
    """
    mgr = ConfigManager(ctx.obj)
    mgr.set(component, key, value)
    mgr.commit(component)
Exemple #2
0
    def create_orc8r(
        self,
        constants: dict,
        cluster_uuid: str,
        template: ClusterTemplate = None,
        skip_certs=False,
        skip_precheck=False,
    ) -> Dict[str, Any]:
        """ Create an orc8r instance in the test cluster

        Args:
            constants (dict): Constants dictionary
            template (ClusterTemplate, optional): Cluster template definition. Defaults to None.
            skip_certs (bool, optional): Skip certs creation. Defaults to False.
            skip_precheck (bool, optional): Skip prechecks. Defaults to False.

        Raises:
            ClusterCreateError: Exception raised when cluster creation fails
        """
        # configure deployment
        template.orc8r.infra['magma_uuid'] = cluster_uuid
        template.orc8r.infra.update(get_aws_configs())

        # set elastic deploy role based on current state
        k = 'deploy_elasticsearch_service_linked_role'
        template.orc8r.platform[k] = check_elastic_role_not_exists()

        mgr = ConfigManager(constants)
        template_dict = template.orc8r.to_dict()
        for component, configs in template_dict.items():
            for k, v in configs.items():
                mgr.set(component, k, v)
            mgr.commit(component)

        # run playbooks in order
        if not skip_certs:
            logging.debug("Adding self signed and application certs")
            rc = run_playbook(certs_cmd(constants, self_signed=True))
            if rc != 0:
                raise ClusterCreateError(f"Failed running adding certs")

        if not skip_precheck:
            logging.debug("Running installation prechecks")
            rc = run_playbook(precheck_cmd(constants))
            if rc != 0:
                raise ClusterCreateError(f"Failed running prechecks")

        # create the orc8r cluster
        rc = tf_install(constants, warn=False)
        if rc != 0:
            raise ClusterCreateError(f"Failed installing cluster")

        # update dns record for parent domain
        dns_dict = {
            "domain_name": template.orc8r.infra["orc8r_domain_name"],
        }
        dns_dict.update(constants)
        rc = run_playbook(
            AnsiblePlay(
                playbook=f"{constants['playbooks']}/main.yml",
                tags=['update_dns_records'],
                extra_vars=dns_dict,
            ), )
        if rc != 0:
            raise ClusterCreateError(
                f"Failed updating dns records for parent domain", )

        cluster_config_dict = {
            "uuid": cluster_uuid,
            "cluster_type": ClusterType.AWS,
            "template": template,
        }
        return cluster_config_dict