Пример #1
0
    def create_configuration_settings(self):
        """
        Generate the configuration settings.

        This is a one-time thing, because configuration_settings, like all AppServer fields, is
        immutable once this AppServer is saved.
        """
        confvars = self._get_configuration_variables()
        for attr_name in self.CONFIGURATION_EXTRA_FIELDS:
            additional_vars = getattr(self, attr_name)
            additional_vars = yaml.load(additional_vars, Loader=yaml.SafeLoader) if additional_vars else {}
            confvars = ansible.dict_merge(confvars, additional_vars)
        vars_str = yaml.dump(confvars, default_flow_style=False)
        self.logger.debug('Vars.yml:\n%s', vars_str)
        return vars_str
Пример #2
0
def production_instance_factory(**kwargs):
    """
    Factory function for creating production instances.

    Returns a newly created OpenEdXInstance.

    Callers can use keyword arguments to pass in non-default values
    for any field that is defined on the OpenEdXInstance model.

    The only mandatory argument is `sub_domain`.

    When called without any additional arguments, the instance that is returned
    will have its fields set to default values that are appropriate
    for *production* instances.

    To create an instance with default settings that are suitable for sandboxes,
    use `instance_factory`.
    """
    # NOTE: The long-term goal is to eliminate differences between sandboxes
    # and production instances, and for this function to disappear.
    # Please do not add behavior that is specific to production instances here.

    # Ensure caller provided required arguments
    assert "sub_domain" in kwargs

    # Check environment and report potential problems
    environment_ready = _check_environment()

    if not environment_ready:
        logger.warning(
            "Environment not ready. Please fix the problems above, then try again. Aborting."
        )
        return

    # Gather settings
    production_settings = {
        # Don't create default users on production instances
        "DEMO_CREATE_STAFF_USER": False,
        "demo_test_users": [],
        # Disable certificates process to reduce load on RabbitMQ and MySQL
        "SANDBOX_ENABLE_CERTIFICATES": False,
    }
    configuration_extra_settings = kwargs.pop("configuration_extra_settings",
                                              "")
    configuration_extra_settings = yaml.load(
        configuration_extra_settings) if configuration_extra_settings else {}
    extra_settings = yaml.dump(ansible.dict_merge(
        production_settings, configuration_extra_settings),
                               default_flow_style=False)
    instance_kwargs = dict(
        edx_platform_repository_url=settings.STABLE_EDX_PLATFORM_REPO_URL,
        edx_platform_commit=settings.STABLE_EDX_PLATFORM_COMMIT,
        configuration_source_repo_url=settings.STABLE_CONFIGURATION_REPO_URL,
        configuration_version=settings.STABLE_CONFIGURATION_VERSION,
        openedx_release=settings.OPENEDX_RELEASE_STABLE_REF,
        configuration_extra_settings=extra_settings,
        # Allow production instances to use a different OpenStack instance flavor by default.
        # This allows using a larger instance flavor for production instances.
        openstack_server_flavor=settings.OPENSTACK_PRODUCTION_INSTANCE_FLAVOR,
    )
    instance_kwargs.update(kwargs)

    # Create instance
    production_instance = OpenEdXInstance.objects.create(**instance_kwargs)
    return production_instance