From fcdc67b819b79522324c2e67cdb99527ad43dc86 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Thu, 11 Apr 2019 08:47:44 +0900 Subject: [PATCH] Define default settings explicitly (openstack_dashboard 3/5) This commit mainly covers settings in openstack_dashboard/dashboards/project/. Part of blueprint ini-based-configuration Change-Id: I22413d2fe20576a507634dc4e2d0354c7db8800a --- .../dashboards/project/api_access/views.py | 15 +- .../dashboards/project/floating_ips/panel.py | 4 +- .../dashboards/project/images/images/forms.py | 6 +- .../project/images/images/tables.py | 6 +- .../dashboards/project/images/images/tabs.py | 5 +- .../dashboards/project/images/images/views.py | 4 +- .../dashboards/project/instances/tables.py | 14 +- .../dashboards/project/instances/tabs.py | 4 +- .../dashboards/project/instances/tests.py | 6 +- .../dashboards/project/instances/utils.py | 2 +- .../dashboards/project/instances/views.py | 9 +- .../project/network_topology/utils.py | 10 +- .../project/network_topology/views.py | 6 +- .../project/networks/ports/workflows.py | 11 +- .../dashboards/project/networks/views.py | 4 +- .../dashboards/project/networks/workflows.py | 8 +- .../dashboards/project/routers/panel.py | 4 +- .../project/security_groups/forms.py | 5 +- .../project/security_groups/tables.py | 2 +- .../dashboards/project/snapshots/tables.py | 4 +- .../dashboards/project/volumes/forms.py | 4 +- .../dashboards/project/volumes/tables.py | 4 +- openstack_dashboard/defaults.py | 151 ++++++++++++++++++ .../local/local_settings.py.example | 111 ------------- openstack_dashboard/settings.py | 54 +------ openstack_dashboard/test/settings.py | 19 --- 26 files changed, 213 insertions(+), 259 deletions(-) diff --git a/openstack_dashboard/dashboards/project/api_access/views.py b/openstack_dashboard/dashboards/project/api_access/views.py index 7b80eeac5e..eae441d9c4 100644 --- a/openstack_dashboard/dashboards/project/api_access/views.py +++ b/openstack_dashboard/dashboards/project/api_access/views.py @@ -119,8 +119,7 @@ def download_ec2_bundle(request): def download_rc_file(request): - template = getattr(settings, 'OPENRC_CUSTOM_TEMPLATE', - 'project/api_access/openrc.sh.template') + template = settings.OPENRC_CUSTOM_TEMPLATE context = _get_openrc_credentials(request) # make v3 specific changes @@ -139,17 +138,13 @@ def download_rc_file(request): def download_clouds_yaml_file(request): - template = getattr(settings, 'OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE', - 'project/api_access/clouds.yaml.template') + template = settings.OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE context = _get_openrc_credentials(request) - context['cloud_name'] = getattr( - settings, "OPENSTACK_CLOUDS_YAML_NAME", 'openstack') - context['profile'] = getattr( - settings, "OPENSTACK_CLOUDS_YAML_PROFILE", None) + context['cloud_name'] = settings.OPENSTACK_CLOUDS_YAML_NAME + context['profile'] = settings.OPENSTACK_CLOUDS_YAML_PROFILE context['regions'] = [ - region_tuple[1] for region_tuple in getattr( - settings, "AVAILABLE_REGIONS", []) + region_tuple[1] for region_tuple in settings.AVAILABLE_REGIONS ] if utils.get_keystone_version() >= 3: diff --git a/openstack_dashboard/dashboards/project/floating_ips/panel.py b/openstack_dashboard/dashboards/project/floating_ips/panel.py index 307a563de4..267532caaf 100644 --- a/openstack_dashboard/dashboards/project/floating_ips/panel.py +++ b/openstack_dashboard/dashboards/project/floating_ips/panel.py @@ -25,5 +25,5 @@ class FloatingIps(horizon.Panel): @staticmethod def can_register(): - network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {}) - return network_config.get('enable_router', True) + network_config = settings.OPENSTACK_NEUTRON_NETWORK + return network_config['enable_router'] diff --git a/openstack_dashboard/dashboards/project/images/images/forms.py b/openstack_dashboard/dashboards/project/images/images/forms.py index 09a00cf483..063f850843 100644 --- a/openstack_dashboard/dashboards/project/images/images/forms.py +++ b/openstack_dashboard/dashboards/project/images/images/forms.py @@ -36,8 +36,8 @@ from openstack_dashboard import api from openstack_dashboard import policy -IMAGE_BACKEND_SETTINGS = getattr(settings, 'OPENSTACK_IMAGE_BACKEND', {}) -IMAGE_FORMAT_CHOICES = IMAGE_BACKEND_SETTINGS.get('image_formats', []) +IMAGE_BACKEND_SETTINGS = settings.OPENSTACK_IMAGE_BACKEND +IMAGE_FORMAT_CHOICES = IMAGE_BACKEND_SETTINGS['image_formats'] class ImageURLField(forms.URLField): @@ -158,7 +158,7 @@ class CreateImageForm(CreateParent): if api.glance.VERSIONS.active >= 2: # NOTE: GlanceV2 doesn't support copy-from feature, sorry! self._hide_is_copying() - if not getattr(settings, 'IMAGES_ALLOW_LOCATION', False): + if not settings.IMAGES_ALLOW_LOCATION: self._hide_url_source_type() if (api.glance.get_image_upload_mode() == 'off' or not policy.check((("image", "upload_image"),), request)): diff --git a/openstack_dashboard/dashboards/project/images/images/tables.py b/openstack_dashboard/dashboards/project/images/images/tables.py index 983c444bda..5ad1b0c4da 100644 --- a/openstack_dashboard/dashboards/project/images/images/tables.py +++ b/openstack_dashboard/dashboards/project/images/images/tables.py @@ -190,7 +190,7 @@ class UpdateMetadata(tables.LinkAction): def filter_tenants(): - return getattr(settings, 'IMAGES_LIST_FILTER_TENANTS', []) + return settings.IMAGES_LIST_FILTER_TENANTS def filter_tenant_ids(): @@ -347,9 +347,9 @@ class ImagesTable(tables.DataTable): verbose_name = _("Images") table_actions = (OwnerFilter, CreateImage, DeleteImage,) launch_actions = () - if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False): + if settings.LAUNCH_INSTANCE_LEGACY_ENABLED: launch_actions = (LaunchImage,) + launch_actions - if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True): + if settings.LAUNCH_INSTANCE_NG_ENABLED: launch_actions = (LaunchImageNG,) + launch_actions row_actions = launch_actions + (CreateVolumeFromImage, EditImage, UpdateMetadata, diff --git a/openstack_dashboard/dashboards/project/images/images/tabs.py b/openstack_dashboard/dashboards/project/images/images/tabs.py index c3340edf79..1dbd9682d9 100644 --- a/openstack_dashboard/dashboards/project/images/images/tabs.py +++ b/openstack_dashboard/dashboards/project/images/images/tabs.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from django import conf +from django.conf import settings from django.utils.translation import ugettext_lazy as _ from horizon import tabs @@ -25,8 +25,7 @@ class OverviewTab(tabs.Tab): def get_context_data(self, request): image = self.tab_group.kwargs['image'] - custom_titles = getattr(conf.settings, - 'IMAGE_CUSTOM_PROPERTY_TITLES', {}) + custom_titles = settings.IMAGE_CUSTOM_PROPERTY_TITLES image_props = [] for prop, val in image.properties.items(): if prop == 'description': diff --git a/openstack_dashboard/dashboards/project/images/images/views.py b/openstack_dashboard/dashboards/project/images/images/views.py index 25e87d5903..9dc258ead7 100644 --- a/openstack_dashboard/dashboards/project/images/images/views.py +++ b/openstack_dashboard/dashboards/project/images/images/views.py @@ -71,9 +71,7 @@ class CreateView(forms.ModalFormView): context = super(CreateView, self).get_context_data(**kwargs) upload_mode = api.glance.get_image_upload_mode() context['image_upload_enabled'] = upload_mode != 'off' - context['images_allow_location'] = getattr(settings, - 'IMAGES_ALLOW_LOCATION', - False) + context['images_allow_location'] = settings.IMAGES_ALLOW_LOCATION return context diff --git a/openstack_dashboard/dashboards/project/instances/tables.py b/openstack_dashboard/dashboards/project/instances/tables.py index 5faf71270b..db81278a38 100644 --- a/openstack_dashboard/dashboards/project/instances/tables.py +++ b/openstack_dashboard/dashboards/project/instances/tables.py @@ -557,8 +557,9 @@ class ConsoleLink(policy.PolicyTargetMixin, tables.LinkAction): def allowed(self, request, instance=None): # We check if ConsoleLink is allowed only if settings.CONSOLE_TYPE is # not set at all, or if it's set to any value other than None or False. - return bool(getattr(settings, 'CONSOLE_TYPE', True)) and \ - instance.status in ACTIVE_STATES and not is_deleting(instance) + return (bool(settings.CONSOLE_TYPE) and + instance.status in ACTIVE_STATES and + not is_deleting(instance)) def get_link_url(self, datum): base_url = super(ConsoleLink, self).get_link_url(datum) @@ -660,10 +661,7 @@ class DecryptInstancePassword(tables.LinkAction): url = "horizon:project:instances:decryptpassword" def allowed(self, request, instance): - enable = getattr(settings, - 'OPENSTACK_ENABLE_PASSWORD_RETRIEVE', - False) - return (enable and + return (settings.OPENSTACK_ENABLE_PASSWORD_RETRIEVE and (instance.status in ACTIVE_STATES or instance.status == 'SHUTOFF') and not is_deleting(instance) and @@ -1293,9 +1291,9 @@ class InstancesTable(tables.DataTable): row_class = UpdateRow table_actions_menu = (StartInstance, StopInstance, SoftRebootInstance) launch_actions = () - if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False): + if settings.LAUNCH_INSTANCE_LEGACY_ENABLED: launch_actions = (LaunchLink,) + launch_actions - if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True): + if settings.LAUNCH_INSTANCE_NG_ENABLED: launch_actions = (LaunchLinkNG,) + launch_actions table_actions = launch_actions + (DeleteInstance, InstancesFilterAction) diff --git a/openstack_dashboard/dashboards/project/instances/tabs.py b/openstack_dashboard/dashboards/project/instances/tabs.py index e33ecde8c9..a339a93bca 100644 --- a/openstack_dashboard/dashboards/project/instances/tabs.py +++ b/openstack_dashboard/dashboards/project/instances/tabs.py @@ -93,7 +93,7 @@ class ConsoleTab(tabs.Tab): def get_context_data(self, request): instance = self.tab_group.kwargs['instance'] - console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO') + console_type = settings.CONSOLE_TYPE console_url = None try: console_type, console_url = console.get_console( @@ -112,7 +112,7 @@ class ConsoleTab(tabs.Tab): def allowed(self, request): # The ConsoleTab is available if settings.CONSOLE_TYPE is not set at # all, or if it's set to any value other than None or False. - return bool(getattr(settings, 'CONSOLE_TYPE', True)) + return bool(settings.CONSOLE_TYPE) class AuditTab(tabs.TableTab): diff --git a/openstack_dashboard/dashboards/project/instances/tests.py b/openstack_dashboard/dashboards/project/instances/tests.py index 227af9715f..31beb1ee5b 100644 --- a/openstack_dashboard/dashboards/project/instances/tests.py +++ b/openstack_dashboard/dashboards/project/instances/tests.py @@ -890,7 +890,7 @@ class InstanceTableTests(InstanceTestBase, InstanceTableTestMixin): api.network: ('servers_update_addresses',), api.cinder: ('volume_list',)}) def test_suspend_instance_if_placed_on_2nd_page(self): - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 2) + page_size = settings.API_RESULT_PAGE_SIZE servers = self.servers.list()[:3] self.mock_extension_supported.return_value = True @@ -4992,7 +4992,7 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin): # The form action on the next page should have marker # object from the previous page last element. - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 2) + page_size = settings.API_RESULT_PAGE_SIZE servers = self.servers.list()[:3] self._mock_extension_supported({'AdminActions': True, @@ -5076,7 +5076,7 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin): def test_delete_instance_with_pagination(self): # Instance should be deleted from the next page. - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 2) + page_size = settings.API_RESULT_PAGE_SIZE servers = self.servers.list()[:3] server = servers[-1] diff --git a/openstack_dashboard/dashboards/project/instances/utils.py b/openstack_dashboard/dashboards/project/instances/utils.py index 6246e88080..2b2352ef1f 100644 --- a/openstack_dashboard/dashboards/project/instances/utils.py +++ b/openstack_dashboard/dashboards/project/instances/utils.py @@ -49,7 +49,7 @@ def sort_flavor_list(request, flavors, with_menu_label=True): '"ram" instead.', sort_key) return getattr(flavor, 'ram') try: - flavor_sort = getattr(settings, 'CREATE_INSTANCE_FLAVOR_SORT', {}) + flavor_sort = settings.CREATE_INSTANCE_FLAVOR_SORT sort_key = flavor_sort.get('key', 'ram') rev = flavor_sort.get('reverse', False) if not callable(sort_key): diff --git a/openstack_dashboard/dashboards/project/instances/views.py b/openstack_dashboard/dashboards/project/instances/views.py index c43a4501c8..61dcab0378 100644 --- a/openstack_dashboard/dashboards/project/instances/views.py +++ b/openstack_dashboard/dashboards/project/instances/views.py @@ -125,8 +125,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView): # nova network info cache is not synced. Precisely there is no # need to check IP addresses of all servers. It is sufficient to # fetch IP address information for servers recently updated. - if not getattr(settings, - 'OPENSTACK_INSTANCE_RETRIEVE_IP_ADDRESSES', True): + if not settings.OPENSTACK_INSTANCE_RETRIEVE_IP_ADDRESSES: return instances try: api.network.servers_update_addresses(self.request, instances) @@ -263,8 +262,8 @@ class LaunchInstanceView(workflows.WorkflowView): initial = super(LaunchInstanceView, self).get_initial() initial['project_id'] = self.request.user.tenant_id initial['user_id'] = self.request.user.id - defaults = getattr(settings, 'LAUNCH_INSTANCE_DEFAULTS', {}) - initial['config_drive'] = defaults.get('config_drive', False) + defaults = settings.LAUNCH_INSTANCE_DEFAULTS + initial['config_drive'] = defaults['config_drive'] return initial @@ -285,7 +284,7 @@ def console(request, instance_id): def auto_console(request, instance_id): - console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO') + console_type = settings.CONSOLE_TYPE try: instance = api.nova.server_get(request, instance_id) console_url = project_console.get_console(request, console_type, diff --git a/openstack_dashboard/dashboards/project/network_topology/utils.py b/openstack_dashboard/dashboards/project/network_topology/utils.py index fbd670afae..e9ae6a4f86 100644 --- a/openstack_dashboard/dashboards/project/network_topology/utils.py +++ b/openstack_dashboard/dashboards/project/network_topology/utils.py @@ -28,7 +28,7 @@ def get_context(request, context=None): if context is None: context = {} - network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {}) + network_config = settings.OPENSTACK_NEUTRON_NETWORK context['launch_instance_allowed'] = policy.check( (("compute", "os_compute_api:servers:create"),), request) @@ -37,14 +37,14 @@ def get_context(request, context=None): (("network", "create_network"),), request) context['network_quota_exceeded'] = _quota_exceeded(request, 'network') context['create_router_allowed'] = ( - network_config.get('enable_router', True) and + network_config['enable_router'] and policy.check((("network", "create_router"),), request)) context['router_quota_exceeded'] = _quota_exceeded(request, 'router') - context['console_type'] = getattr(settings, 'CONSOLE_TYPE', 'AUTO') + context['console_type'] = settings.CONSOLE_TYPE context['show_ng_launch'] = ( base.is_service_enabled(request, 'compute') and - getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True)) + settings.LAUNCH_INSTANCE_NG_ENABLED) context['show_legacy_launch'] = ( base.is_service_enabled(request, 'compute') and - getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False)) + settings.LAUNCH_INSTANCE_LEGACY_ENABLED) return context diff --git a/openstack_dashboard/dashboards/project/network_topology/views.py b/openstack_dashboard/dashboards/project/network_topology/views.py index 74ead4623a..53c9224e28 100644 --- a/openstack_dashboard/dashboards/project/network_topology/views.py +++ b/openstack_dashboard/dashboards/project/network_topology/views.py @@ -214,8 +214,8 @@ class JSONView(View): @property def is_router_enabled(self): - network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {}) - return network_config.get('enable_router', True) + network_config = settings.OPENSTACK_NEUTRON_NETWORK + return network_config['enable_router'] def add_resource_url(self, view, resources): tenant_id = self.request.user.tenant_id @@ -239,7 +239,7 @@ class JSONView(View): except Exception: servers = [] data = [] - console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO') + console_type = settings.CONSOLE_TYPE # lowercase of the keys will be used at the end of the console URL. for server in servers: server_data = {'name': server.name, diff --git a/openstack_dashboard/dashboards/project/networks/ports/workflows.py b/openstack_dashboard/dashboards/project/networks/ports/workflows.py index 8a483ffd04..32dcc12aae 100644 --- a/openstack_dashboard/dashboards/project/networks/ports/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/ports/workflows.py @@ -160,9 +160,8 @@ class CreatePortInfoAction(workflows.Action): return is_supproted def _populate_vnic_type_choices(self, request): - neutron_settings = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {}) - supported_vnic_types = neutron_settings.get('supported_vnic_types', - ['*']) + neutron_settings = settings.OPENSTACK_NEUTRON_NETWORK + supported_vnic_types = neutron_settings['supported_vnic_types'] # When a list of VNIC types is empty, hide the corresponding field. if not supported_vnic_types: del self.fields['binding__vnic_type'] @@ -315,10 +314,8 @@ class UpdatePortInfoAction(workflows.Action): super(UpdatePortInfoAction, self).__init__(request, *args, **kwargs) try: if api.neutron.is_extension_supported(request, 'binding'): - neutron_settings = getattr(settings, - 'OPENSTACK_NEUTRON_NETWORK', {}) - supported_vnic_types = neutron_settings.get( - 'supported_vnic_types', ['*']) + neutron_settings = settings.OPENSTACK_NEUTRON_NETWORK + supported_vnic_types = neutron_settings['supported_vnic_types'] if supported_vnic_types: if supported_vnic_types == ['*']: vnic_type_choices = api.neutron.VNIC_TYPES diff --git a/openstack_dashboard/dashboards/project/networks/views.py b/openstack_dashboard/dashboards/project/networks/views.py index 7a402c6ecf..1daad9de82 100644 --- a/openstack_dashboard/dashboards/project/networks/views.py +++ b/openstack_dashboard/dashboards/project/networks/views.py @@ -67,8 +67,8 @@ class DefaultSubnetWorkflowMixin(object): def get_default_dns_servers(self): # this returns the default dns servers to be used for new subnets - dns_default = "\n".join(getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', - {}).get('default_dns_nameservers', '')) + dns_default = "\n".join( + settings.OPENSTACK_NEUTRON_NETWORK['default_dns_nameservers']) return dns_default diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py index 4e85d739a1..ed365fef8d 100644 --- a/openstack_dashboard/dashboards/project/networks/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/workflows.py @@ -205,8 +205,7 @@ class CreateSubnetInfoAction(workflows.Action): def __init__(self, request, context, *args, **kwargs): super(CreateSubnetInfoAction, self).__init__(request, context, *args, **kwargs) - if not getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', - {}).get('enable_ipv6', True): + if not settings.OPENSTACK_NEUTRON_NETWORK['enable_ipv6']: self.fields['ip_version'].widget = forms.HiddenInput() self.fields['ip_version'].initial = 4 @@ -261,7 +260,7 @@ class CreateSubnetInfoAction(workflows.Action): if not self.check_subnet_range: return - allowed_cidr = getattr(settings, "ALLOWED_PRIVATE_SUBNET_CIDR", {}) + allowed_cidr = settings.ALLOWED_PRIVATE_SUBNET_CIDR version_str = 'ipv%s' % ip_version allowed_ranges = allowed_cidr.get(version_str, []) if allowed_ranges: @@ -381,8 +380,7 @@ class CreateSubnetDetailAction(workflows.Action): def __init__(self, request, context, *args, **kwargs): super(CreateSubnetDetailAction, self).__init__(request, context, *args, **kwargs) - if not getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', - {}).get('enable_ipv6', True): + if not settings.OPENSTACK_NEUTRON_NETWORK['enable_ipv6']: self.fields['ipv6_modes'].widget = forms.HiddenInput() def populate_ipv6_modes_choices(self, request, context): diff --git a/openstack_dashboard/dashboards/project/routers/panel.py b/openstack_dashboard/dashboards/project/routers/panel.py index fa7b159c42..d41558aee9 100644 --- a/openstack_dashboard/dashboards/project/routers/panel.py +++ b/openstack_dashboard/dashboards/project/routers/panel.py @@ -25,5 +25,5 @@ class Routers(horizon.Panel): @staticmethod def can_register(): - network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {}) - return network_config.get('enable_router', True) + network_config = settings.OPENSTACK_NEUTRON_NETWORK + return network_config['enable_router'] diff --git a/openstack_dashboard/dashboards/project/security_groups/forms.py b/openstack_dashboard/dashboards/project/security_groups/forms.py index 5d640b36da..7e3f5801e8 100644 --- a/openstack_dashboard/dashboards/project/security_groups/forms.py +++ b/openstack_dashboard/dashboards/project/security_groups/forms.py @@ -269,7 +269,7 @@ class AddRule(forms.SelfHandlingForm): # parameter. If 'backend' is used, error message should be emitted. backend = 'neutron' - rules_dict = getattr(settings, 'SECURITY_GROUP_RULES', []) + rules_dict = settings.SECURITY_GROUP_RULES common_rules = [ (k, rules_dict[k]['name']) for k in rules_dict @@ -296,8 +296,7 @@ class AddRule(forms.SelfHandlingForm): ('all', _('All ports')), ] - if not getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', - {}).get('enable_ipv6', True): + if not settings.OPENSTACK_NEUTRON_NETWORK['enable_ipv6']: self.fields['cidr'].version = forms.IPv4 self.fields['ethertype'].widget = forms.TextInput( attrs={'readonly': 'readonly'}) diff --git a/openstack_dashboard/dashboards/project/security_groups/tables.py b/openstack_dashboard/dashboards/project/security_groups/tables.py index 2b83372c43..d04abfaaae 100644 --- a/openstack_dashboard/dashboards/project/security_groups/tables.py +++ b/openstack_dashboard/dashboards/project/security_groups/tables.py @@ -217,7 +217,7 @@ def filter_protocol(protocol): def check_rule_template(port, ip_proto): - rules_dict = getattr(settings, 'SECURITY_GROUP_RULES', {}) + rules_dict = settings.SECURITY_GROUP_RULES if not rules_dict: return port templ_rule = [rule for rule in rules_dict.values() diff --git a/openstack_dashboard/dashboards/project/snapshots/tables.py b/openstack_dashboard/dashboards/project/snapshots/tables.py index de91926e41..2c66dd2c41 100644 --- a/openstack_dashboard/dashboards/project/snapshots/tables.py +++ b/openstack_dashboard/dashboards/project/snapshots/tables.py @@ -224,9 +224,9 @@ class VolumeDetailsSnapshotsTable(volume_tables.VolumesTableBase): table_actions = (VolumeSnapshotsFilterAction, DeleteVolumeSnapshot,) launch_actions = () - if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False): + if settings.LAUNCH_INSTANCE_LEGACY_ENABLED: launch_actions = (LaunchSnapshot,) + launch_actions - if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True): + if settings.LAUNCH_INSTANCE_NG_ENABLED: launch_actions = (LaunchSnapshotNG,) + launch_actions row_actions = ((CreateVolumeFromSnapshot,) + launch_actions + diff --git a/openstack_dashboard/dashboards/project/volumes/forms.py b/openstack_dashboard/dashboards/project/volumes/forms.py index 12683361a5..8f14bbd45e 100644 --- a/openstack_dashboard/dashboards/project/volumes/forms.py +++ b/openstack_dashboard/dashboards/project/volumes/forms.py @@ -40,8 +40,8 @@ from openstack_dashboard.dashboards.project.images import utils from openstack_dashboard.dashboards.project.instances import tables from openstack_dashboard.usage import quotas -IMAGE_BACKEND_SETTINGS = getattr(settings, 'OPENSTACK_IMAGE_BACKEND', {}) -IMAGE_FORMAT_CHOICES = IMAGE_BACKEND_SETTINGS.get('image_formats', []) +IMAGE_BACKEND_SETTINGS = settings.OPENSTACK_IMAGE_BACKEND +IMAGE_FORMAT_CHOICES = IMAGE_BACKEND_SETTINGS['image_formats'] VALID_DISK_FORMATS = ('raw', 'vmdk', 'vdi', 'qcow2', 'vhd', 'vhdx') DEFAULT_CONTAINER_FORMAT = 'bare' diff --git a/openstack_dashboard/dashboards/project/volumes/tables.py b/openstack_dashboard/dashboards/project/volumes/tables.py index 314cfa25ff..d64f8c5d83 100644 --- a/openstack_dashboard/dashboards/project/volumes/tables.py +++ b/openstack_dashboard/dashboards/project/volumes/tables.py @@ -567,9 +567,9 @@ class VolumesTable(VolumesTableBase): VolumesFilterAction) launch_actions = () - if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False): + if settings.LAUNCH_INSTANCE_LEGACY_ENABLED: launch_actions = (LaunchVolume,) + launch_actions - if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True): + if settings.LAUNCH_INSTANCE_NG_ENABLED: launch_actions = (LaunchVolumeNG,) + launch_actions row_actions = ((EditVolume, ExtendVolume,) + diff --git a/openstack_dashboard/defaults.py b/openstack_dashboard/defaults.py index 8e22f1a8c4..f93c0f8130 100644 --- a/openstack_dashboard/defaults.py +++ b/openstack_dashboard/defaults.py @@ -12,15 +12,55 @@ """Default settings for openstack_dashboard""" +from django.utils.translation import ugettext_lazy as _ + # This must be configured # OPENSTACK_KEYSTONE_URL = 'http://localhost/identity/v3' +# Dict used to restrict user private subnet cidr range. +# An empty list means that user input will not be restricted +# for a corresponding IP version. By default, there is +# no restriction for IPv4 or IPv6. To restrict +# user private subnet cidr range set ALLOWED_PRIVATE_SUBNET_CIDR +# to something like +# ALLOWED_PRIVATE_SUBNET_CIDR = { +# 'ipv4': ['10.0.0.0/8', '192.168.0.0/16'], +# 'ipv6': ['fc00::/7'] +# } +ALLOWED_PRIVATE_SUBNET_CIDR = {'ipv4': [], 'ipv6': []} + # The number of objects (Swift containers/objects or images) to display # on a single page before providing a paging element (a "more" link) # to paginate results. API_RESULT_LIMIT = 1000 API_RESULT_PAGE_SIZE = 20 +# For multiple regions uncomment this configuration, and add (endpoint, title). +# AVAILABLE_REGIONS = [ +# ('http://cluster1.example.com:5000/v3', 'cluster1'), +# ('http://cluster2.example.com:5000/v3', 'cluster2'), +# ] +AVAILABLE_REGIONS = [] + +# Set Console type: +# valid options are "AUTO"(default), "VNC", "SPICE", "RDP", "SERIAL", "MKS" +# or None. Set to None explicitly if you want to deactivate the console. +CONSOLE_TYPE = "AUTO" + +# When launching an instance, the menu of available flavors is +# sorted by RAM usage, ascending. If you would like a different sort order, +# you can provide another flavor attribute as sorting key. Alternatively, you +# can provide a custom callback method to use for sorting. You can also provide +# a flag for reverse sort. For more info, see +# http://docs.python.org/2/library/functions.html#sorted +# CREATE_INSTANCE_FLAVOR_SORT = { +# 'key': 'name', +# # or +# 'key': my_awesome_callback_method, +# 'reverse': False, +# } +CREATE_INSTANCE_FLAVOR_SORT = {} + ENABLE_CLIENT_TOKEN = True # Set this to True to display an 'Admin Password' field on the Change Password # form to verify that it is indeed the admin logged-in who wants to change @@ -56,6 +96,78 @@ HORIZON_IMAGES_UPLOAD_MODE = 'legacy' # configuration and policies allow setting locations. IMAGES_ALLOW_LOCATION = False +# The IMAGE_CUSTOM_PROPERTY_TITLES settings is used to customize the titles for +# image custom property attributes that appear on image detail pages. +IMAGE_CUSTOM_PROPERTY_TITLES = { + "architecture": _("Architecture"), + "kernel_id": _("Kernel ID"), + "ramdisk_id": _("Ramdisk ID"), + "image_state": _("Euca2ools state"), + "project_id": _("Project ID"), + "image_type": _("Image Type"), +} + +IMAGES_LIST_FILTER_TENANTS = [] + +# The Launch Instance user experience has been significantly enhanced. +# You can choose whether to enable the new launch instance experience, +# the legacy experience, or both. The legacy experience will be removed +# in a future release, but is available as a temporary backup setting to ensure +# compatibility with existing deployments. Further development will not be +# done on the legacy experience. Please report any problems with the new +# experience via the Launchpad tracking system. +# +# Toggle LAUNCH_INSTANCE_LEGACY_ENABLED and LAUNCH_INSTANCE_NG_ENABLED to +# determine the experience to enable. Set them both to true to enable +# both. +LAUNCH_INSTANCE_LEGACY_ENABLED = False +LAUNCH_INSTANCE_NG_ENABLED = True + +# A dictionary of settings which can be used to provide the default values for +# properties found in the Launch Instance modal. +LAUNCH_INSTANCE_DEFAULTS = { + 'config_drive': False, + 'create_volume': True, + 'hide_create_volume': False, + 'disable_image': False, + 'disable_instance_snapshot': False, + 'disable_volume': False, + 'disable_volume_snapshot': False, + 'enable_scheduler_hints': True, +} + +OPENRC_CUSTOM_TEMPLATE = 'project/api_access/openrc.sh.template' +OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE = ('project/api_access/' + 'clouds.yaml.template') + +SECURITY_GROUP_RULES = { + 'all_tcp': { + 'name': _('All TCP'), + 'ip_protocol': 'tcp', + 'from_port': '1', + 'to_port': '65535', + }, + 'all_udp': { + 'name': _('All UDP'), + 'ip_protocol': 'udp', + 'from_port': '1', + 'to_port': '65535', + }, + 'all_icmp': { + 'name': _('All ICMP'), + 'ip_protocol': 'icmp', + 'from_port': '-1', + 'to_port': '-1', + }, +} + +# Controls whether the keystone openrc file is accesible from the user +# menu and the api access panel. +SHOW_OPENRC_FILE = True +# Controls whether clouds.yaml is accesible from the user +# menu and the api access panel. +SHOW_OPENSTACK_CLOUDS_YAML = True + # The size of chunk in bytes for downloading objects from Swift SWIFT_FILE_TRANSFER_CHUNK_SIZE = 512 * 1024 @@ -146,6 +258,7 @@ OPENSTACK_NEUTRON_NETWORK = { # The entries below are examples only, and are not appropriate for # real deployments # 'default_dns_nameservers': ["8.8.8.8", "8.8.4.4", "208.67.222.222"], + 'default_dns_nameservers': [], # Set which provider network types are supported. Only the network types # in this list will be available to choose from when creating a network. @@ -184,6 +297,12 @@ OPENSTACK_NEUTRON_NETWORK = { # e.g. ['default', 'test'] 'physical_networks': [], } + +# This settings controls whether IP addresses of servers are retrieved from +# neutron in the project instance table. Setting this to ``False`` may mitigate +# a performance issue in the project instance table in large deployments. +OPENSTACK_INSTANCE_RETRIEVE_IP_ADDRESSES = True + OPENSTACK_NOVA_EXTENSIONS_BLACKLIST = [] # The Xen Hypervisor has the ability to set the mount point for volumes # attached to instances (other Hypervisors currently do not). Setting @@ -196,6 +315,38 @@ OPENSTACK_HYPERVISOR_FEATURES = { 'requires_keypair': False, } +# Setting this to True, will add a new "Retrieve Password" action on instance, +# allowing Admin session password retrieval/decryption. +OPENSTACK_ENABLE_PASSWORD_RETRIEVE = False + +# The OPENSTACK_IMAGE_BACKEND settings can be used to customize features +# in the OpenStack Dashboard related to the Image service, such as the list +# of supported image formats. +OPENSTACK_IMAGE_BACKEND = { + 'image_formats': [ + ('', _('Select format')), + ('aki', _('AKI - Amazon Kernel Image')), + ('ami', _('AMI - Amazon Machine Image')), + ('ari', _('ARI - Amazon Ramdisk Image')), + ('docker', _('Docker')), + ('iso', _('ISO - Optical Disk Image')), + ('ova', _('OVA - Open Virtual Appliance')), + ('ploop', _('PLOOP - Virtuozzo/Parallels Loopback Disk')), + ('qcow2', _('QCOW2 - QEMU Emulator')), + ('raw', _('Raw')), + ('vdi', _('VDI - Virtual Disk Image')), + ('vhd', _('VHD - Virtual Hard Disk')), + ('vhdx', _('VHDX - Large Virtual Hard Disk')), + ('vmdk', _('VMDK - Virtual Machine Disk')), + ] +} + +# Set OPENSTACK_CLOUDS_YAML_NAME to provide a nicer name for this cloud for +# the clouds.yaml file than "openstack". +OPENSTACK_CLOUDS_YAML_NAME = 'openstack' +# If this cloud has a vendor profile in os-client-config, put it's name here. +OPENSTACK_CLOUDS_YAML_PROFILE = '' + # AngularJS requires some settings to be made available to # the client side. Some settings are required by in-tree / built-in horizon # features. These settings must be added to REST_API_REQUIRED_SETTINGS in the diff --git a/openstack_dashboard/local/local_settings.py.example b/openstack_dashboard/local/local_settings.py.example index c0a0e50136..5676b3a27c 100644 --- a/openstack_dashboard/local/local_settings.py.example +++ b/openstack_dashboard/local/local_settings.py.example @@ -70,19 +70,6 @@ WEBROOT = '/' # ('Default', 'Default'), #) -# Set Console type: -# valid options are "AUTO"(default), "VNC", "SPICE", "RDP", "SERIAL", "MKS" -# or None. Set to None explicitly if you want to deactivate the console. -#CONSOLE_TYPE = "AUTO" - -# Controls whether the keystone openrc file is accesible from the user -# menu and the api access panel. -SHOW_OPENRC_FILE = True - -# Controls whether clouds.yaml is accesible from the user -# menu and the api access panel. -SHOW_OPENSTACK_CLOUDS_YAML = True - # If provided, a "Report Bug" link will be displayed in the site header # which links to the value of this setting (ideally a URL containing # information on how to report issues). @@ -149,12 +136,6 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' #EMAIL_HOST_USER = 'djangomail' #EMAIL_HOST_PASSWORD = 'top-secret!' -# For multiple regions uncomment this configuration, and add (endpoint, title). -#AVAILABLE_REGIONS = [ -# ('http://cluster1.example.com:5000/v3', 'cluster1'), -# ('http://cluster2.example.com:5000/v3', 'cluster2'), -#] - OPENSTACK_HOST = "127.0.0.1" OPENSTACK_KEYSTONE_URL = "http://%s:5000/v3" % OPENSTACK_HOST @@ -233,41 +214,6 @@ OPENSTACK_KEYSTONE_URL = "http://%s:5000/v3" % OPENSTACK_HOST # should not match any service provider IDs. #KEYSTONE_PROVIDER_IDP_ID = "localkeystone" -# Setting this to True, will add a new "Retrieve Password" action on instance, -# allowing Admin session password retrieval/decryption. -#OPENSTACK_ENABLE_PASSWORD_RETRIEVE = False - -# The Launch Instance user experience has been significantly enhanced. -# You can choose whether to enable the new launch instance experience, -# the legacy experience, or both. The legacy experience will be removed -# in a future release, but is available as a temporary backup setting to ensure -# compatibility with existing deployments. Further development will not be -# done on the legacy experience. Please report any problems with the new -# experience via the Launchpad tracking system. -# -# Toggle LAUNCH_INSTANCE_LEGACY_ENABLED and LAUNCH_INSTANCE_NG_ENABLED to -# determine the experience to enable. Set them both to true to enable -# both. -#LAUNCH_INSTANCE_LEGACY_ENABLED = True -#LAUNCH_INSTANCE_NG_ENABLED = False - -# A dictionary of settings which can be used to provide the default values for -# properties found in the Launch Instance modal. -#LAUNCH_INSTANCE_DEFAULTS = { -# 'config_drive': False, -# 'enable_scheduler_hints': True, -# 'disable_image': False, -# 'disable_instance_snapshot': False, -# 'disable_volume': False, -# 'disable_volume_snapshot': False, -# 'create_volume': True, -#} - -# This settings controls whether IP addresses of servers are retrieved from -# neutron in the project instance table. Setting this to ``False`` may mitigate -# a performance issue in the project instance table in large deployments. -#OPENSTACK_INSTANCE_RETRIEVE_IP_ADDRESSES = True - # The OPENSTACK_NEUTRON_NETWORK settings can be used to enable optional # services provided by neutron. Options currently available are load # balancer service, security groups, quotas, VPN service. @@ -298,38 +244,6 @@ OPENSTACK_HEAT_STACK = { 'enable_user_pass': True, } -# The OPENSTACK_IMAGE_BACKEND settings can be used to customize features -# in the OpenStack Dashboard related to the Image service, such as the list -# of supported image formats. -#OPENSTACK_IMAGE_BACKEND = { -# 'image_formats': [ -# ('', _('Select format')), -# ('aki', _('AKI - Amazon Kernel Image')), -# ('ami', _('AMI - Amazon Machine Image')), -# ('ari', _('ARI - Amazon Ramdisk Image')), -# ('docker', _('Docker')), -# ('iso', _('ISO - Optical Disk Image')), -# ('ova', _('OVA - Open Virtual Appliance')), -# ('qcow2', _('QCOW2 - QEMU Emulator')), -# ('raw', _('Raw')), -# ('vdi', _('VDI - Virtual Disk Image')), -# ('vhd', _('VHD - Virtual Hard Disk')), -# ('vhdx', _('VHDX - Large Virtual Hard Disk')), -# ('vmdk', _('VMDK - Virtual Machine Disk')), -# ], -#} - -# The IMAGE_CUSTOM_PROPERTY_TITLES settings is used to customize the titles for -# image custom property attributes that appear on image detail pages. -IMAGE_CUSTOM_PROPERTY_TITLES = { - "architecture": _("Architecture"), - "kernel_id": _("Kernel ID"), - "ramdisk_id": _("Ramdisk ID"), - "image_state": _("Euca2ools state"), - "project_id": _("Project ID"), - "image_type": _("Image Type"), -} - # The IMAGE_RESERVED_CUSTOM_PROPERTIES setting is used to specify which image # custom properties should not be displayed in the Image Custom Properties # table. @@ -350,19 +264,6 @@ DROPDOWN_MAX_ITEMS = 30 # of your entire OpenStack installation, and hopefully be in UTC. TIME_ZONE = "UTC" -# When launching an instance, the menu of available flavors is -# sorted by RAM usage, ascending. If you would like a different sort order, -# you can provide another flavor attribute as sorting key. Alternatively, you -# can provide a custom callback method to use for sorting. You can also provide -# a flag for reverse sort. For more info, see -# http://docs.python.org/2/library/functions.html#sorted -#CREATE_INSTANCE_FLAVOR_SORT = { -# 'key': 'name', -# # or -# 'key': my_awesome_callback_method, -# 'reverse': False, -#} - # Modules that provide /auth routes that can be used to handle different types # of user authentication. Add auth plugins that require extra route handling to # this list. @@ -696,18 +597,6 @@ SECURITY_GROUP_RULES = { # of data fetched by default when rendering the Overview panel. #OVERVIEW_DAYS_RANGE = 1 -# Dict used to restrict user private subnet cidr range. -# An empty list means that user input will not be restricted -# for a corresponding IP version. By default, there is -# no restriction for IPv4 or IPv6. To restrict -# user private subnet cidr range set ALLOWED_PRIVATE_SUBNET_CIDR -# to something like -#ALLOWED_PRIVATE_SUBNET_CIDR = { -# 'ipv4': ['10.0.0.0/8', '192.168.0.0/16'], -# 'ipv6': ['fc00::/7'] -#} -ALLOWED_PRIVATE_SUBNET_CIDR = {'ipv4': [], 'ipv6': []} - # Projects and users can have extra attributes as defined by keystone v3. # Horizon has the ability to display these extra attributes via this setting. # If you'd like to display extra data in the project or user tables, set the diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index 9d963ea7de..ee0499987f 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -91,28 +91,6 @@ HORIZON_CONFIG = { 'integration_tests_support': INTEGRATION_TESTS_SUPPORT } -# The OPENSTACK_IMAGE_BACKEND settings can be used to customize features -# in the OpenStack Dashboard related to the Image service, such as the list -# of supported image formats. -OPENSTACK_IMAGE_BACKEND = { - 'image_formats': [ - ('', _('Select format')), - ('aki', _('AKI - Amazon Kernel Image')), - ('ami', _('AMI - Amazon Machine Image')), - ('ari', _('ARI - Amazon Ramdisk Image')), - ('docker', _('Docker')), - ('iso', _('ISO - Optical Disk Image')), - ('ova', _('OVA - Open Virtual Appliance')), - ('ploop', _('PLOOP - Virtuozzo/Parallels Loopback Disk')), - ('qcow2', _('QCOW2 - QEMU Emulator')), - ('raw', _('Raw')), - ('vdi', _('VDI - Virtual Disk Image')), - ('vhd', _('VHD - Virtual Hard Disk')), - ('vhdx', _('VHDX - Large Virtual Hard Disk')), - ('vmdk', _('VMDK - Virtual Machine Disk')), - ] -} - MIDDLEWARE = ( 'openstack_auth.middleware.OpenstackAuthMonkeyPatchMiddleware', 'debreach.middleware.RandomCommentMiddleware', @@ -270,12 +248,6 @@ USE_I18N = True USE_L10N = True USE_TZ = True -# Set OPENSTACK_CLOUDS_YAML_NAME to provide a nicer name for this cloud for -# the clouds.yaml file than "openstack". -OPENSTACK_CLOUDS_YAML_NAME = 'openstack' -# If this cloud has a vendor profile in os-client-config, put it's name here. -OPENSTACK_CLOUDS_YAML_PROFILE = '' - DEFAULT_EXCEPTION_REPORTER_FILTER = 'horizon.exceptions.HorizonReporterFilter' POLICY_FILES_PATH = os.path.join(ROOT_PATH, "conf") @@ -296,27 +268,6 @@ POLICY_DIRS = { SECRET_KEY = None LOCAL_PATH = None -SECURITY_GROUP_RULES = { - 'all_tcp': { - 'name': _('All TCP'), - 'ip_protocol': 'tcp', - 'from_port': '1', - 'to_port': '65535', - }, - 'all_udp': { - 'name': _('All UDP'), - 'ip_protocol': 'udp', - 'from_port': '1', - 'to_port': '65535', - }, - 'all_icmp': { - 'name': _('All ICMP'), - 'ip_protocol': 'icmp', - 'from_port': '-1', - 'to_port': '-1', - }, -} - ADD_INSTALLED_APPS = [] # NOTE: The default value of USER_MENU_LINKS will be set after loading @@ -351,9 +302,6 @@ CSRF_COOKIE_AGE = None COMPRESS_OFFLINE_CONTEXT = 'horizon.themes.offline_context' -SHOW_OPENRC_FILE = True -SHOW_OPENSTACK_CLOUDS_YAML = True - # Dictionary of currently available angular features ANGULAR_FEATURES = { 'images_panel': True, @@ -430,6 +378,8 @@ if os.path.exists(LOCAL_SETTINGS_DIR_PATH): # The purpose of OPENSTACK_IMAGE_FORMATS is to provide a simple object # that does not contain the lazy-loaded translations, so the list can # be sent as JSON to the client-side (Angular). +# TODO(amotoki): Do we really need this here? Can't we calculate this +# in openstack_dashboard.api.rest.config? OPENSTACK_IMAGE_FORMATS = [fmt for (fmt, name) in OPENSTACK_IMAGE_BACKEND['image_formats']] diff --git a/openstack_dashboard/test/settings.py b/openstack_dashboard/test/settings.py index 60beab9ae0..39ea21a89b 100644 --- a/openstack_dashboard/test/settings.py +++ b/openstack_dashboard/test/settings.py @@ -149,22 +149,6 @@ OPENSTACK_NEUTRON_NETWORK['enable_distributed_router'] = False OPENSTACK_HYPERVISOR_FEATURES['can_set_password'] = True -OPENSTACK_IMAGE_BACKEND = { - 'image_formats': [ - ('', 'Select format'), - ('aki', 'AKI - Amazon Kernel Image'), - ('ami', 'AMI - Amazon Machine Image'), - ('ari', 'ARI - Amazon Ramdisk Image'), - ('iso', 'ISO - Optical Disk Image'), - ('ploop', 'PLOOP - Virtuozzo/Parallels Loopback Disk'), - ('qcow2', 'QCOW2 - QEMU Emulator'), - ('raw', 'Raw'), - ('vdi', 'VDI'), - ('vhd', 'VHD'), - ('vmdk', 'VMDK') - ] -} - LOGGING['loggers'].update( { 'openstack_dashboard': { @@ -236,9 +220,6 @@ REST_API_SECURITY = 'SECURITY' REST_API_REQUIRED_SETTINGS = ['REST_API_SETTING_1'] REST_API_ADDITIONAL_SETTINGS = ['REST_API_SETTING_2'] -ALLOWED_PRIVATE_SUBNET_CIDR = {'ipv4': [], 'ipv6': []} - - # -------------------- # Test-only settings # --------------------