Exemplo n.º 1
0
def _build_default_email_group(
    group_name,
    email_subject,
    email_from,
    email_reply,
    email_template,
    email_html_template,
):
    email_group = groups.ConfigGroup(group_name)
    email_group.register_child_config(
        fields.StrConfig(
            "subject",
            help_text="Default email subject for this stage",
            default=email_subject,
        ))
    email_group.register_child_config(
        fields.StrConfig("from",
                         help_text="Default from email for this stage",
                         default=email_from))
    email_group.register_child_config(
        fields.StrConfig(
            "reply",
            help_text="Default reply-to email for this stage",
            default=email_reply,
        ))
    email_group.register_child_config(
        fields.StrConfig(
            "template",
            help_text="Default email template for this stage",
            default=email_template,
        ))
    email_group.register_child_config(
        fields.StrConfig(
            "html_template",
            help_text="Default email html template for this stage",
            default=email_html_template,
        ))
    return email_group
Exemplo n.º 2
0
#    under the License.

import os
import sys

import confspirator
from confspirator import groups

from adjutant.config import api
from adjutant.config import django
from adjutant.config import identity
from adjutant.config import notification
from adjutant.config import quota
from adjutant.config import workflow

_root_config = groups.ConfigGroup("adjutant")
_root_config.register_child_config(django.config_group)
_root_config.register_child_config(identity.config_group)
_root_config.register_child_config(api.config_group)
_root_config.register_child_config(notification.config_group)
_root_config.register_child_config(workflow.config_group)
_root_config.register_child_config(quota.config_group)

_config_files = [
    "/etc/adjutant/adjutant.yaml",
    "/etc/adjutant/adjutant.toml",
]
_old_config_file = "/etc/adjutant/conf.yaml"

_test_mode_commands = [
    # Adjutant commands:
Exemplo n.º 3
0
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups
from confspirator import fields

config_group = groups.ConfigGroup("api")

config_group.register_child_config(
    fields.ListConfig(
        "active_delegate_apis",
        help_text="List of Active Delegate APIs.",
        required=True,
        default=[
            "UserRoles",
            "UserDetail",
            "UserResetPassword",
            "UserList",
            "RoleList",
        ],
        # NOTE(adriant): for testing purposes we include ALL default APIs
        test_default=[
Exemplo n.º 4
0
class NewDefaultNetworkAction(BaseAction, ProjectMixin):
    """
    This action will setup all required basic networking
    resources so that a new user can launch instances
    right away.
    """

    required = [
        "setup_network",
        "project_id",
        "region",
    ]

    serializer = serializers.NewDefaultNetworkSerializer

    config_group = groups.DynamicNameConfigGroup(
        children=[
            groups.ConfigGroup(
                "region_defaults",
                children=[
                    fields.StrConfig(
                        "network_name",
                        help_text="Name to be given to the default network.",
                        default="default_network",
                    ),
                    fields.StrConfig(
                        "subnet_name",
                        help_text="Name to be given to the default subnet.",
                        default="default_subnet",
                    ),
                    fields.StrConfig(
                        "router_name",
                        help_text="Name to be given to the default router.",
                        default="default_router",
                    ),
                    fields.StrConfig(
                        "public_network",
                        help_text="ID of the public network.",
                    ),
                    fields.StrConfig(
                        "subnet_cidr",
                        help_text="CIDR for the default subnet.",
                    ),
                    fields.ListConfig(
                        "dns_nameservers",
                        help_text="DNS nameservers for the subnet.",
                    ),
                ],
            ),
            fields.DictConfig(
                "regions",
                help_text="Specific per region config for default network. "
                "See 'region_defaults'.",
                default={},
            ),
        ]
    )

    def __init__(self, *args, **kwargs):
        super(NewDefaultNetworkAction, self).__init__(*args, **kwargs)

    def _validate_region(self):
        if not self.region:
            self.add_note("ERROR: No region given.")
            return False

        id_manager = user_store.IdentityManager()
        region = id_manager.get_region(self.region)
        if not region:
            self.add_note("ERROR: Region does not exist.")
            return False

        self.add_note("Region: %s exists." % self.region)
        return True

    def _validate(self):
        self.action.valid = validate_steps(
            [
                self._validate_region,
                self._validate_project_id,
                self._validate_keystone_user_project_id,
            ]
        )
        self.action.save()

    def _create_network(self):
        neutron = openstack_clients.get_neutronclient(region=self.region)
        try:
            region_config = self.config.regions[self.region]
            network_config = self.config.region_defaults.overlay(region_config)
        except KeyError:
            network_config = self.config.region_defaults

        if not self.get_cache("network_id"):
            try:
                network_body = {
                    "network": {
                        "name": network_config.network_name,
                        "tenant_id": self.project_id,
                        "admin_state_up": True,
                    }
                }
                network = neutron.create_network(body=network_body)
            except Exception as e:
                self.add_note(
                    "Error: '%s' while creating network: %s"
                    % (e, network_config.network_name)
                )
                raise
            self.set_cache("network_id", network["network"]["id"])
            self.add_note(
                "Network %s created for project %s"
                % (network_config.network_name, self.project_id)
            )
        else:
            self.add_note(
                "Network %s already created for project %s"
                % (network_config.network_name, self.project_id)
            )

        if not self.get_cache("subnet_id"):
            try:
                subnet_body = {
                    "subnet": {
                        "network_id": self.get_cache("network_id"),
                        "ip_version": 4,
                        "tenant_id": self.project_id,
                        "dns_nameservers": network_config.dns_nameservers,
                        "cidr": network_config.subnet_cidr,
                    }
                }
                subnet = neutron.create_subnet(body=subnet_body)
            except Exception as e:
                self.add_note("Error: '%s' while creating subnet" % e)
                raise
            self.set_cache("subnet_id", subnet["subnet"]["id"])
            self.add_note("Subnet created for network %s" % network_config.network_name)
        else:
            self.add_note(
                "Subnet already created for network %s" % network_config.network_name
            )

        if not self.get_cache("router_id"):
            try:
                router_body = {
                    "router": {
                        "name": network_config.router_name,
                        "external_gateway_info": {
                            "network_id": network_config.public_network
                        },
                        "tenant_id": self.project_id,
                        "admin_state_up": True,
                    }
                }
                router = neutron.create_router(body=router_body)
            except Exception as e:
                self.add_note(
                    "Error: '%s' while creating router: %s"
                    % (e, network_config.router_name)
                )
                raise
            self.set_cache("router_id", router["router"]["id"])
            self.add_note("Router created for project %s" % self.project_id)
        else:
            self.add_note("Router already created for project %s" % self.project_id)

        if not self.get_cache("port_id"):
            try:
                interface_body = {"subnet_id": self.get_cache("subnet_id")}
                interface = neutron.add_interface_router(
                    self.get_cache("router_id"), body=interface_body
                )
            except Exception as e:
                self.add_note("Error: '%s' while attaching interface" % e)
                raise
            self.set_cache("port_id", interface["port_id"])
            self.add_note("Interface added to router for subnet")
        else:
            self.add_note("Interface added to router for project %s" % self.project_id)

    def _prepare(self):
        # Note: Do we need to get this from cache? it is a required setting
        # self.project_id = self.action.task.cache.get('project_id', None)
        self._validate()

    def _approve(self):
        self._validate()

        if self.setup_network and self.valid:
            self._create_network()

    def _submit(self, token_data, keystone_user=None):
        pass
Exemplo n.º 5
0
# Copyright (C) 2019 Catalyst Cloud Ltd
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups

config_group = groups.ConfigGroup("feature_sets")
Exemplo n.º 6
0
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups
from confspirator import fields

config_group = groups.ConfigGroup("workflow")

config_group.register_child_config(
    fields.URIConfig(
        "horizon_url",
        help_text=
        "The base Horizon url for Adjutant to use when producing links to Horizon.",
        schemes=["https", "http"],
        required=True,
        sample_default="http://localhost/",
        test_default="http://localhost/",
    ))
config_group.register_child_config(
    fields.IntConfig(
        "default_token_expiry",
        help_text="The default token expiry time for Task tokens.",
Exemplo n.º 7
0
def _build_default_email_group(group_name):
    email_group = groups.ConfigGroup(group_name)
    email_group.register_child_config(
        fields.StrConfig(
            "subject",
            help_text="Email subject for this stage.",
            default="Openstack Email Notification",
        ))
    email_group.register_child_config(
        fields.StrConfig(
            "from",
            help_text="From email for this stage.",
            regex=constants.EMAIL_WITH_TEMPLATE_REGEX,
            default="bounce+%(task_uuid)[email protected]",
        ))
    email_group.register_child_config(
        fields.StrConfig(
            "reply",
            help_text="Reply-to email for this stage.",
            regex=constants.EMAIL_WITH_TEMPLATE_REGEX,
            default="*****@*****.**",
        ))
    email_group.register_child_config(
        fields.StrConfig(
            "template",
            help_text="Email template for this stage. "
            "No template will cause the email not to send.",
            default=None,
        ))
    email_group.register_child_config(
        fields.StrConfig(
            "html_template",
            help_text="Email html template for this stage. "
            "No template will cause the email not to send.",
            default=None,
        ))
    email_group.register_child_config(
        fields.BoolConfig(
            "email_current_user",
            help_text="Email the user who started the task.",
            default=False,
        ))
    email_group.register_child_config(
        fields.BoolConfig(
            "email_task_cache",
            help_text="Send to an email set in the task cache.",
            default=False,
        ))
    email_group.register_child_config(
        fields.ListConfig(
            "email_roles",
            help_text="Send emails to the given roles on the project.",
            default=[],
        ))
    email_group.register_child_config(
        fields.ListConfig(
            "email_additional_addresses",
            help_text="Send emails to an arbitrary admin emails",
            item_type=types.String(regex=constants.EMAIL_WITH_TEMPLATE_REGEX),
            default=[],
        ))
    return email_group
Exemplo n.º 8
0
        "octavia": {
            "health_monitor": 100,
            "listener": 10,
            "load_balancer": 10,
            "member": 10,
            "pool": 10,
        },
        "trove": {
            "instances": 20,
            "volumes": 20,
            "backups": 100,
        },
    },
}

config_group = groups.ConfigGroup("quota")

config_group.register_child_config(
    fields.DictConfig(
        "sizes",
        help_text=
        "A definition of the quota size groups that Adjutant should use.",
        value_type=types.Dict(value_type=types.Dict()),
        check_value_type=True,
        is_json=True,
        default=DEFAULT_QUOTA_SIZES,
    ))
config_group.register_child_config(
    fields.ListConfig(
        "sizes_ascending",
        help_text="An ascending list of all the quota size names, "
Exemplo n.º 9
0
# limitations under the License.

import os
import sys

import confspirator
from confspirator import groups as config_groups
from confspirator import fields as config_fields
import yaml

TESTING = sys.argv[1:2] == ['test']
SERVICES_CONFIG_LOCATION = '/etc/adjutant/services.yaml'
if os.environ.get('ADJUTANT_SERVICES_FILE'):
    SERVICES_CONFIG_LOCATION = os.environ.get('ADJUTANT_SERVICES_FILE')

moc = config_groups.ConfigGroup("moc")
services = config_fields.DictConfig(
    'services',
    default={'openshift': {
        'type': 'openshift',
        'url': 'https://example.com'
    }})
moc.register_child_config(services)

conf_dict = None
try:
    with open(SERVICES_CONFIG_LOCATION, 'r') as f:
        conf_dict = yaml.load(f, Loader=yaml.FullLoader)
except FileNotFoundError:
    pass
Exemplo n.º 10
0
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups
from confspirator import fields

config_group = groups.ConfigGroup("django")

config_group.register_child_config(
    fields.StrConfig(
        "secret_key",
        help_text="The Django secret key.",
        required=True,
        default="Do not ever use this awful secret in prod!!!!",
        secret=True,
        unsafe_default=True,
    ))
config_group.register_child_config(
    fields.BoolConfig(
        "debug",
        help_text="Django debug mode is turned on.",
        default=False,
Exemplo n.º 11
0
# Copyright (C) 2019 Catalyst Cloud Ltd
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups


config_group = groups.ConfigGroup("notifications")

handler_defaults_group = groups.ConfigGroup("handler_defaults", lazy_load=True)
config_group.register_child_config(handler_defaults_group)
Exemplo n.º 12
0
# Copyright (C) 2019 Catalyst Cloud Ltd
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups

config_group = groups.ConfigGroup("feature_sets", lazy_load=True)
Exemplo n.º 13
0
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from confspirator import groups
from confspirator import fields
from confspirator import types


config_group = groups.ConfigGroup("identity")

config_group.register_child_config(
    fields.IntConfig(
        "token_cache_time",
        help_text="Cache time for Keystone Tokens in the Keystone Middleware.",
        default=-1,
        required=True,
        required_for_tests=False,
    )
)
config_group.register_child_config(
    fields.BoolConfig(
        "can_edit_users",
        help_text="Is Adjutant allowed (or able) to edit users in Keystone.",
        default=True,