Ejemplo n.º 1
0
class OpenEdXAppConfiguration(models.Model):
    """
    Configuration fields used by OpenEdX Instance and AppServer.

    Mutable on the instance but immutable on the AppServer.
    """
    class Meta:
        abstract = True

    email = models.EmailField(
        default='*****@*****.**',
        help_text=
        ('The default contact email for this instance; also used as the from address for emails '
         'sent by the server.'))

    openedx_release = models.CharField(
        max_length=128,
        blank=False,
        default=default_setting('DEFAULT_OPENEDX_RELEASE'),
        help_text=format_help_text("""
            Set this to a release tag like "named-release/dogwood" to build a specific release of
            Open edX. This setting becomes the default value for edx_platform_version,
            forum_version, notifier_version, xqueue_version, and certs_version so it should be a git
            branch that exists in all of those repositories.

            Note: to build a specific branch of edx-platform, you should just override
            edx_platform_commit rather than changing this setting.

            Note 2: This value does not affect the default value of configuration_version.
            """),
    )

    # Ansible-specific settings:
    configuration_source_repo_url = models.URLField(
        max_length=256,
        blank=False,
        default=default_setting('DEFAULT_CONFIGURATION_REPO_URL'),
    )
    configuration_version = models.CharField(
        max_length=50,
        blank=False,
        default=default_setting('DEFAULT_CONFIGURATION_VERSION'),
    )
    configuration_extra_settings = models.TextField(
        blank=True, help_text="YAML config vars that override all others")

    edx_platform_repository_url = models.CharField(
        max_length=256,
        blank=False,
        default=default_setting('DEFAULT_EDX_PLATFORM_REPO_URL'),
        help_text=
        ('URL to the edx-platform repository to use. Leave blank for default.'
         ),
    )
    edx_platform_commit = models.CharField(
        max_length=256,
        blank=False,
        help_text=
        ('edx-platform commit hash or branch or tag to use. Leave blank to use the default, '
         'which is equal to the value of "openedx_release".'))

    # OpenStack VM settings
    openstack_server_flavor = JSONField(
        null=True,
        blank=True,
        default=default_setting('OPENSTACK_SANDBOX_FLAVOR'),
        help_text='JSON openstack flavor selector, e.g. {"name": "vps-ssd-1"}.'
        ' Defaults to settings.OPENSTACK_SANDBOX_FLAVOR on server creation.',
    )
    openstack_server_base_image = JSONField(
        null=True,
        blank=True,
        default=default_setting('OPENSTACK_SANDBOX_BASE_IMAGE'),
        help_text=
        'JSON openstack base image selector, e.g. {"name": "xenial-16.04-unmodified"}'
        ' Defaults to settings.OPENSTACK_SANDBOX_BASE_IMAGE on server creation.',
    )
    openstack_server_ssh_keyname = models.CharField(
        max_length=256,
        null=True,
        blank=True,
        default=default_setting('OPENSTACK_SANDBOX_SSH_KEYNAME'),
        help_text=
        'SSH key name used when setting up access to the openstack project.'
        ' Defaults to settings.OPENSTACK_SANDBOX_SSH_KEYNAME on server creation.',
    )

    # Misc settings:
    lms_users = models.ManyToManyField(
        settings.AUTH_USER_MODEL,
        blank=True,
        help_text=
        'Instance manager users that should be made staff users on the instance.',
    )
    additional_security_groups = ArrayField(
        models.CharField(max_length=200),
        default=list,
        blank=True,
        help_text=
        ("Optional: A list of extra OpenStack security group names to use for this instance's VMs. "
         "A typical use case is to grant this instance access to a private database server that is "
         "behind a firewall. (In the django admin, separate group names with a comma.)"
         ))
    additional_monitoring_emails = ArrayField(
        models.CharField(max_length=200),
        default=list,
        blank=True,
        help_text=
        ("Optional: A list of additional email addresses other than settings.ADMINS "
         "who should receive alerts from New Relic Synthetics Monitors when this instance "
         "becomes unavailable."))

    @classmethod
    def get_config_fields(cls):
        """
        Get the names of each field declared on this model (except the automatic ID field).

        This is used to copy the current values from an Instance to an AppServer when creating
        a new AppServer.
        """
        return [
            field.name for field in cls._meta.fields
            if field.name not in ('id', )
        ]
Ejemplo n.º 2
0
class OpenEdXAppConfiguration(models.Model):
    """
    Configuration fields used by OpenEdX Instance and AppServer.

    Mutable on the instance but immutable on the AppServer.
    """
    class Meta:
        abstract = True

    email = models.EmailField(default='*****@*****.**', help_text=(
        'The default contact email for this instance; also used as the from address for emails '
        'sent by the server.'
    ))
    privacy_policy_url = models.URLField(
        verbose_name='URL to Privacy Policy',
        help_text=('URL to the privacy policy.'),
        blank=True,
        default='',
    )

    openedx_release = models.CharField(
        max_length=128,
        blank=False,
        default=default_setting('DEFAULT_OPENEDX_RELEASE'),
        help_text=format_help_text(
            """
            Set this to a release tag like "named-release/dogwood" to build a specific release of
            Open edX. This setting becomes the default value for edx_platform_version,
            forum_version, notifier_version, xqueue_version, and certs_version so it should be a git
            branch that exists in all of those repositories.

            Note: to build a specific branch of edx-platform, you should just override
            edx_platform_commit rather than changing this setting.

            Note 2: This value does not affect the default value of configuration_version.
            """
        ),
    )

    # Ansible-specific settings:
    configuration_source_repo_url = models.URLField(
        max_length=256,
        blank=False,
        default=default_setting('DEFAULT_CONFIGURATION_REPO_URL'),
    )
    configuration_version = models.CharField(
        max_length=50,
        blank=False,
        default=default_setting('DEFAULT_CONFIGURATION_VERSION'),
    )
    configuration_extra_settings = models.TextField(blank=True, help_text="YAML config vars that override all others")
    configuration_playbook_name = models.CharField(
        max_length=100,
        blank=True,
    )

    edx_platform_repository_url = models.CharField(
        max_length=256,
        blank=False,
        default=default_setting('DEFAULT_EDX_PLATFORM_REPO_URL'),
        help_text=(
            'URL to the edx-platform repository to use. Leave blank for default.'
        ),
    )
    edx_platform_commit = models.CharField(max_length=256, blank=False, help_text=(
        'edx-platform commit hash or branch or tag to use. Leave blank to use the default, '
        'which is equal to the value of "openedx_release".'
    ))

    # Settings related to default ansible playbook
    ansible_appserver_repo_url = models.URLField(
        max_length=256,
        blank=False,
        default=default_setting('ANSIBLE_APPSERVER_REPO'),
        help_text=('The repository to pull the default Ansible playbook from.')
    )
    ansible_appserver_playbook = models.CharField(
        max_length=256,
        blank=False,
        default=default_setting('ANSIBLE_APPSERVER_PLAYBOOK'),
        help_text=('The path to the common appserver playbook to run on all appservers.')
    )
    # pylint: disable=invalid-name
    ansible_appserver_requirements_path = models.CharField(
        max_length=256,
        blank=False,
        default=default_setting('ANSIBLE_APPSERVER_REQUIREMENTS_PATH'),
        help_text=('The path to the requirements file for the common appserver playbook.')
    )
    ansible_appserver_version = models.CharField(
        max_length=256,
        blank=False,
        default=default_setting('ANSIBLE_APPSERVER_VERSION'),
        help_text=('The version of the Ansible playbook repository to checkout.')
    )

    # OpenStack VM settings
    openstack_server_flavor = JSONField(
        null=True,
        blank=True,
        default=default_setting('OPENSTACK_SANDBOX_FLAVOR'),
        help_text='JSON openstack flavor selector, e.g. {"name": "vps-ssd-1"}.'
                  ' Defaults to settings.OPENSTACK_SANDBOX_FLAVOR on server creation.',
    )
    openstack_server_base_image = JSONField(
        null=True,
        blank=True,
        default=default_setting('OPENSTACK_SANDBOX_BASE_IMAGE'),
        help_text='JSON openstack base image selector, e.g. {"name": "focal-20.04-unmodified"}'
                  ' Defaults to settings.OPENSTACK_SANDBOX_BASE_IMAGE on server creation.',
    )
    openstack_server_ssh_keyname = models.CharField(
        max_length=256,
        null=True,
        blank=True,
        default=default_setting('OPENSTACK_SANDBOX_SSH_KEYNAME'),
        help_text='SSH key name used when setting up access to the openstack project.'
                  ' Defaults to settings.OPENSTACK_SANDBOX_SSH_KEYNAME on server creation.',
    )

    # Misc settings:
    lms_users = models.ManyToManyField(
        settings.AUTH_USER_MODEL,
        blank=True,
        help_text='Instance manager users that should be made staff users on the instance.',
    )
    additional_security_groups = ArrayField(
        models.CharField(max_length=200),
        default=list,
        blank=True,
        help_text=(
            "Optional: A list of extra OpenStack security group names to use for this instance's VMs. "
            "A typical use case is to grant this instance access to a private database server that is "
            "behind a firewall. (In the django admin, separate group names with a comma.)"
        )
    )
    additional_monitoring_emails = ArrayField(
        models.CharField(max_length=200),
        default=list,
        blank=True,
        help_text=(
            "Optional: A list of additional email addresses other than settings.ADMINS "
            "who should receive alerts from New Relic Synthetics Monitors when this instance "
            "becomes unavailable."
        )
    )
    provisioning_failure_notification_emails = ArrayField(  # pylint: disable=invalid-name
        models.CharField(max_length=200),
        default=list,
        blank=True,
        help_text=(
            "Optional: A list of additional email addresses other than settings.ADMINS "
            "who should receive alerts when an AppServer fails to provision."
        )
    )
    openedx_appserver_count = models.IntegerField(
        default=1,
        help_text=(
            "The number of Open edX AppServers to deploy for this instance."
        )
    )

    @property
    def public_contact_email(self):
        """ Helper to provide similar API to get email as BetaTestApplication """
        return self.email

    @property
    def base_playbook_name(self):
        """
        Get the correct base playbook name for the openedx_release

        Automatically fills the field if left empty
        """
        if not self.configuration_playbook_name:
            self.configuration_playbook_name = get_base_playbook_name(self.openedx_release)
            self.save()
        return self.configuration_playbook_name

    @classmethod
    def get_config_fields(cls):
        """
        Get the names of each field declared on this model (except the automatic ID field).

        This is used to copy the current values from an Instance to an AppServer when creating
        a new AppServer.
        """
        return [field.name for field in cls._meta.fields if field.name not in ('id', )]