def volume_backup_supported(request): """This method will determine if cinder supports backup.""" # TODO(lcheng) Cinder does not expose the information if cinder # backup is configured yet. This is a workaround until that # capability is available. # https://bugs.launchpad.net/cinder/+bug/1334856 return utils.get_dict_config('OPENSTACK_CINDER_FEATURES', 'enable_backup')
def get_initial(self): initial = super(LaunchInstanceView, self).get_initial() initial['project_id'] = self.request.user.tenant_id initial['user_id'] = self.request.user.id initial['config_drive'] = setting_utils.get_dict_config( 'LAUNCH_INSTANCE_DEFAULTS', 'config_drive') return initial
def get_data(self): roles = [] filters = self.get_filters() self._needs_filter_first = False if policy.check((("identity", "identity:list_roles"),), self.request): # If filter_first is set and if there are not other filters # selected, then search criteria must be provided # and return an empty list if (setting_utils.get_dict_config( 'FILTER_DATA_FIRST', 'identity.roles') and not filters): self._needs_filter_first = True return roles try: roles = api.keystone.role_list(self.request, filters=filters) except Exception: exceptions.handle(self.request, _('Unable to retrieve roles list.')) else: msg = _("Insufficient privilege level to view role information.") messages.info(self.request, msg) return roles
def get_data(self): try: search_opts = self.get_filters(filters_map=self.FILTERS_MAPPING) # If the tenant filter selected and the tenant does not exist. # We do not need to retrieve the list from neutron,just return # an empty list. if 'tenant_id' in search_opts and not search_opts['tenant_id']: return [] # If filter_first is set and if there are not other filters # selected, then search criteria must be provided and return an # empty list if (setting_utils.get_dict_config('FILTER_DATA_FIRST', 'admin.networks') and not search_opts): self._needs_filter_first = True return [] self._needs_filter_first = False networks = api.neutron.network_list(self.request, **search_opts) except Exception: networks = [] msg = _('Network list can not be retrieved.') exceptions.handle(self.request, msg) if networks: self.exception = False tenant_dict = self._get_tenant_list() for n in networks: # Set tenant name tenant = tenant_dict.get(n.tenant_id, None) n.tenant_name = getattr(tenant, 'name', None) n.num_agents = self._get_agents_data(n.id) return networks
def _get_routers(self): try: filters = self.get_filters(filters_map=self.FILTERS_MAPPING) # If the tenant filter selected and the tenant does not exist. # We do not need to retrieve the list from neutron,just return # an empty list. if 'tenant_id' in filters and not filters['tenant_id']: return [] # If admin_filter_first is set and if there are not other filters # selected, then search criteria must be provided and return an # empty list if (setting_utils.get_dict_config( 'FILTER_DATA_FIRST', 'admin.routers') and not filters): self._needs_filter_first = True return [] self._needs_filter_first = False routers = api.neutron.router_list(self.request, **filters) except Exception: routers = [] exceptions.handle(self.request, _('Unable to retrieve router list.')) self._set_router_tenant_info(routers) return routers
def get_data(self): groups = [] filters = self.get_filters() self._needs_filter_first = False if policy.check((("identity", "identity:list_groups"), ), self.request): # If filter_first is set and if there are not other filters # selected, then search criteria must be provided and # return an empty list if (setting_utils.get_dict_config( 'FILTER_DATA_FIRST', 'identity.groups') and not filters): self._needs_filter_first = True return groups domain_id = identity.get_domain_id_for_operation(self.request) try: groups = api.keystone.group_list(self.request, domain=domain_id, filters=filters) except Exception: exceptions.handle(self.request, _('Unable to retrieve group list.')) else: msg = _("Insufficient privilege level to view group information.") messages.info(self.request, msg) return groups
def __init__(self, *args, **kwargs): sg_list = kwargs.pop('sg_list', []) super(AddRule, self).__init__(*args, **kwargs) # Determine if there are security groups available for the # remote group option; add the choices and enable the option if so. if sg_list: security_groups_choices = sg_list else: security_groups_choices = [("", _("No security groups available"))] self.fields['security_group'].choices = security_groups_choices # TODO(amotoki): settings.SECURITY_GROUP_RULES may contains 'backend' # parameter. If 'backend' is used, error message should be emitted. backend = 'neutron' rules_dict = settings.SECURITY_GROUP_RULES common_rules = [ (k, rules_dict[k]['name']) for k in rules_dict if rules_dict[k].get('backend', backend) == backend ] common_rules.sort() custom_rules = [('tcp', _('Custom TCP Rule')), ('udp', _('Custom UDP Rule')), ('icmp', _('Custom ICMP Rule')), ('custom', _('Other Protocol'))] self.fields['rule_menu'].choices = custom_rules + common_rules self.rules = rules_dict self.fields['direction'].choices = [('ingress', _('Ingress')), ('egress', _('Egress'))] self.fields['ip_protocol'].help_text = _( "Enter an integer value between -1 and 255 " "(-1 means wild card)." ) self.fields['port_or_range'].choices = [ ('port', _('Port')), ('range', _('Port Range')), ('all', _('All ports')), ] if not setting_utils.get_dict_config('OPENSTACK_NEUTRON_NETWORK', 'enable_ipv6'): self.fields['cidr'].version = forms.IPv4 self.fields['ethertype'].widget = forms.TextInput( attrs={'readonly': 'readonly'}) self.fields['ethertype'].initial = 'IPv4' try: is_desc_supported = api.neutron.is_extension_supported( self.request, 'standard-attr-description') except Exception: exceptions.handle( self.request, _('Failed to check if description field is supported.')) is_desc_supported = False if not is_desc_supported: del self.fields['description']
def get_data(self): tenants = [] marker = self.request.GET.get( project_tables.TenantsTable._meta.pagination_param, None) self._more = False filters = self.get_filters() self._needs_filter_first = False if policy.check((("identity", "identity:list_projects"), ), self.request): # If filter_first is set and if there are not other filters # selected, then search criteria must be provided and # return an empty list if (setting_utils.get_dict_config( 'FILTER_DATA_FIRST', 'identity.projects') and not filters): self._needs_filter_first = True self._more = False return tenants domain_id = identity.get_domain_id_for_operation(self.request) try: tenants, self._more = api.keystone.tenant_list( self.request, domain=domain_id, paginate=True, filters=filters, marker=marker) except Exception: exceptions.handle(self.request, _("Unable to retrieve project list.")) elif policy.check((("identity", "identity:list_user_projects"), ), self.request): try: tenants, self._more = api.keystone.tenant_list( self.request, user=self.request.user.id, paginate=True, marker=marker, filters=filters, admin=False) except Exception: exceptions.handle(self.request, _("Unable to retrieve project information.")) else: msg = \ _("Insufficient privilege level to view project information.") messages.info(self.request, msg) if api.keystone.VERSIONS.active >= 3: domain_lookup = api.keystone.domain_lookup(self.request) for t in tenants: t.domain_name = domain_lookup.get(t.domain_id) return tenants
def get_data(self): images = [] if not policy.check((("image", "get_images"),), self.request): msg = _("Insufficient privilege level to retrieve image list.") messages.info(self.request, msg) return images filters = self.get_filters() if (setting_utils.get_dict_config('FILTER_DATA_FIRST', 'admin.images') and len(filters) == len(self.DEFAULT_FILTERS)): self._prev = False self._more = False self._needs_filter_first = True return images self._needs_filter_first = False prev_marker = self.request.GET.get( project_tables.AdminImagesTable._meta.prev_pagination_param, None) if prev_marker is not None: marker = prev_marker else: marker = self.request.GET.get( project_tables.AdminImagesTable._meta.pagination_param, None) reversed_order = prev_marker is not None try: images, self._more, self._prev = api.glance.image_list_detailed( self.request, marker=marker, paginate=True, filters=filters, sort_dir='asc', sort_key='name', reversed_order=reversed_order) except Exception: self._prev = False self._more = False msg = _('Unable to retrieve image list.') exceptions.handle(self.request, msg) if images: try: tenants, more = api.keystone.tenant_list(self.request) except Exception: tenants = [] msg = _('Unable to retrieve project list.') exceptions.handle(self.request, msg) tenant_dict = dict((t.id, t.name) for t in tenants) for image in images: image.tenant_name = tenant_dict.get(image.owner) return images
def allowed(self, context): request = context['request'] try: return (setting_utils.get_dict_config('OPENSTACK_NEUTRON_NETWORK', 'enable_rbac_policy') and neutron.is_extension_supported( request, extension_alias='rbac-policies')) except Exception: LOG.error("Call to list enabled services failed. This is likely " "due to a problem communicating with the Neutron " "endpoint. RBAC Policies panel will not be displayed.") return False
def __init__(self, request, *args, **kwargs): super(UpdatePortInfoAction, self).__init__(request, *args, **kwargs) try: if api.neutron.is_extension_supported(request, 'binding'): supported_vnic_types = setting_utils.get_dict_config( 'OPENSTACK_NEUTRON_NETWORK', 'supported_vnic_types') if supported_vnic_types: if supported_vnic_types == ['*']: vnic_type_choices = api.neutron.VNIC_TYPES else: vnic_type_choices = [ vnic_type for vnic_type in api.neutron.VNIC_TYPES if vnic_type[0] in supported_vnic_types ] self.fields['binding__vnic_type'] = ( forms.ThemableChoiceField( choices=vnic_type_choices, label=_("Binding: VNIC Type"), required=False)) except Exception: msg = _("Unable to verify the VNIC types extension in Neutron") exceptions.handle(self.request, msg) try: if api.neutron.is_extension_supported(request, 'mac-learning'): self.fields['mac_state'] = forms.BooleanField( label=_("MAC Learning State"), initial=False, required=False) except Exception: msg = _("Unable to retrieve MAC learning state") exceptions.handle(self.request, msg) try: if api.neutron.is_extension_supported(request, 'port-security'): self.fields['port_security_enabled'] = forms.BooleanField( label=_("Port Security"), required=False, widget=forms.CheckboxInput( attrs={ 'class': 'switchable', 'data-slug': 'port_security_enabled', 'data-hide-tab': 'update_port__update_security_groups', 'data-hide-on-checked': 'false' })) except Exception: msg = _("Unable to retrieve port security state") exceptions.handle(self.request, msg)
def get_context(request, context=None): """Returns common context data for network topology views.""" if context is None: context = {} context['launch_instance_allowed'] = (base.is_service_enabled( request, 'compute') and policy.check( (("compute", "os_compute_api:servers:create"), ), request)) context['instance_quota_exceeded'] = _quota_exceeded(request, 'instances') context['create_network_allowed'] = policy.check( (("network", "create_network"), ), request) context['network_quota_exceeded'] = _quota_exceeded(request, 'network') context['create_router_allowed'] = (setting_utils.get_dict_config( 'OPENSTACK_NEUTRON_NETWORK', 'enable_router') and policy.check( (("network", "create_router"), ), request)) context['router_quota_exceeded'] = _quota_exceeded(request, 'router') context['console_type'] = settings.CONSOLE_TYPE return context
def get_data(self): users = [] filters = self.get_filters() self._needs_filter_first = False if policy.check((("identity", "identity:list_users"),), self.request): # If filter_first is set and if there are not other filters # selected, then search criteria must be provided # and return an empty list if (setting_utils.get_dict_config( 'FILTER_DATA_FIRST', 'identity.users') and not filters): self._needs_filter_first = True return users domain_id = identity.get_domain_id_for_operation(self.request) try: users = api.keystone.user_list(self.request, domain=domain_id, filters=filters) except Exception: exceptions.handle(self.request, _('Unable to retrieve user list.')) elif policy.check((("identity", "identity:get_user"),), self.request): try: user = api.keystone.user_get(self.request, self.request.user.id, admin=False) users.append(user) except Exception: exceptions.handle(self.request, _('Unable to retrieve user information.')) else: msg = _("Insufficient privilege level to view user information.") messages.info(self.request, msg) domain_lookup = api.keystone.domain_lookup(self.request) for u in users: u.domain_name = domain_lookup.get(u.domain_id) return users
def _populate_vnic_type_choices(self, request): supported_vnic_types = setting_utils.get_dict_config( 'OPENSTACK_NEUTRON_NETWORK', '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'] return binding_supported = self._hide_field_if_not_supported( request, 'binding__vnic_type', 'binding', _("Unable to verify the VNIC types extension in Neutron")) if not binding_supported: # binding__vnic_type field is already deleted, so return here return if supported_vnic_types == ['*']: vnic_type_choices = api.neutron.VNIC_TYPES else: vnic_type_choices = [ vnic_type for vnic_type in api.neutron.VNIC_TYPES if vnic_type[0] in supported_vnic_types ] self.fields['binding__vnic_type'].choices = vnic_type_choices
def __init__(self, request, context, *args, **kwargs): super(CreateSubnetInfoAction, self).__init__(request, context, *args, **kwargs) if not setting_utils.get_dict_config('OPENSTACK_NEUTRON_NETWORK', 'enable_ipv6'): self.fields['ip_version'].widget = forms.HiddenInput() self.fields['ip_version'].initial = 4 try: if api.neutron.is_extension_supported(request, 'subnet_allocation'): self.fields['subnetpool'].choices = \ self.get_subnetpool_choices(request) else: self.hide_subnetpool_choices() except Exception: self.hide_subnetpool_choices() msg = _('Unable to initialize subnetpools') exceptions.handle(request, msg) if len(self.fields['subnetpool'].choices) > 1: # Pre-populate prefixlen choices to satisfy Django # ChoiceField Validation. This is overridden w/data from # subnetpool on select. self.fields['prefixlen'].choices = \ zip(list(range(0, 128 + 1)), list(range(0, 128 + 1))) # Populate data-fields for switching the prefixlen field # when user selects a subnetpool other than # "Provider default pool" for (id_, name) in self.fields['subnetpool'].choices: if not id_: continue key = 'data-subnetpool-' + id_ self.fields['prefixlen'].widget.attrs[key] = \ _('Network Mask') else: self.hide_subnetpool_choices()
def get_data(self): app_creds = [] filters = self.get_filters() self._needs_filter_first = False # If filter_first is set and if there are not other filters # selected, then search criteria must be provided # and return an empty list if (setting_utils.get_dict_config( 'FILTER_DATA_FIRST', 'identity.application_credentials') and not filters): self._needs_filter_first = True return app_creds try: app_creds = api.keystone.application_credential_list( self.request, filters=filters) except Exception: exceptions.handle( self.request, _('Unable to retrieve application credential list.')) return app_creds
def keystone_can_edit_role(): return setting_utils.get_dict_config( 'OPENSTACK_KEYSTONE_BACKEND', 'can_edit_role')
def keystone_can_edit_domain(): can_edit_domain = setting_utils.get_dict_config( 'OPENSTACK_KEYSTONE_BACKEND', 'can_edit_domain') multi_domain_support = settings.OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT return can_edit_domain and multi_domain_support
def __init__(self, request, context, *args, **kwargs): super(CreateSubnetDetailAction, self).__init__(request, context, *args, **kwargs) if not setting_utils.get_dict_config('OPENSTACK_NEUTRON_NETWORK', 'enable_ipv6'): self.fields['ipv6_modes'].widget = forms.HiddenInput()
def allowed(self, request, datum): if not setting_utils.get_dict_config('OPENSTACK_NEUTRON_NETWORK', 'enable_router'): return False # Determine whether this action is allowed for the current request. return datum.agent_type == "L3 agent"
def requires_keypair(): return utils.get_dict_config('OPENSTACK_HYPERVISOR_FEATURES', 'requires_keypair')
def get_data(self): marker, sort_dir = self._get_marker() default_search_opts = { 'marker': marker, 'paginate': True, 'all_tenants': True } search_opts = self.get_filters(default_search_opts.copy()) # If filter_first is set and if there are not other filters # selected, then search criteria must be provided and return an empty # list if (setting_utils.get_dict_config('FILTER_DATA_FIRST', 'admin.instances') and len(search_opts) == len(default_search_opts)): self._needs_filter_first = True self._more = False return [] self._needs_filter_first = False instances = self._get_instances(search_opts, sort_dir) results = futurist_utils.call_functions_parallel( (self._get_images, [tuple(instances)]), self._get_flavors, self._get_tenants) image_dict, flavor_dict, tenant_dict = results non_api_filter_info = ( ('project', 'tenant_id', tenant_dict.values()), ('image_name', 'image', image_dict.values()), ('flavor_name', 'flavor', flavor_dict.values()), ) if not views.process_non_api_filters(search_opts, non_api_filter_info): self._more = False return [] # Loop through instances to get image, flavor and tenant info. for inst in instances: if hasattr(inst, 'image') and isinstance(inst.image, dict): image_id = inst.image.get('id') if image_id in image_dict: inst.image = image_dict[image_id] # In case image not found in image_map, set name to empty # to avoid fallback API call to Glance in api/nova.py # until the call is deprecated in api itself else: inst.image['name'] = _("-") flavor_id = inst.flavor["id"] try: if flavor_id in flavor_dict: inst.full_flavor = flavor_dict[flavor_id] else: # If the flavor_id is not in flavor_dict list, # gets it via nova api. inst.full_flavor = api.nova.flavor_get( self.request, flavor_id) except Exception: msg = _('Unable to retrieve instance size information.') exceptions.handle(self.request, msg) tenant = tenant_dict.get(inst.tenant_id, None) inst.tenant_name = getattr(tenant, "name", None) return instances
def get_default_dns_servers(self): # this returns the default dns servers to be used for new subnets default_dns_nameservers = setting_utils.get_dict_config( 'OPENSTACK_NEUTRON_NETWORK', 'default_dns_nameservers') return "\n".join(default_dns_nameservers)
def can_set_server_password(): return utils.get_dict_config('OPENSTACK_HYPERVISOR_FEATURES', 'can_set_password')
def get_data(self): default_filters = {'all_tenants': True} filters = self.get_filters(default_filters.copy()) volumes = [] self.table.needs_filter_first = False if (setting_utils.get_dict_config('FILTER_DATA_FIRST', 'admin.volumes') and len(filters) == len(default_filters)): self.table.needs_filter_first = True return volumes volumes = [] attached_instance_ids = [] tenants = [] tenant_dict = {} instances = [] volume_ids_with_snapshots = [] def _task_get_tenants(): # Gather our tenants to correlate against IDs try: tmp_tenants, __ = keystone.tenant_list(self.request) tenants.extend(tmp_tenants) tenant_dict.update([(t.id, t) for t in tenants]) except Exception: msg = _('Unable to retrieve volume project information.') exceptions.handle(self.request, msg) def _task_get_instances(): # As long as Nova API does not allow passing attached_instance_ids # to nova.server_list, this call can be forged to pass anything # != None instances.extend( self._get_instances(search_opts={'all_tenants': True})) # In volumes tab we don't need to know about the assignment # instance-image, therefore fixing it to an empty value for instance in instances: if hasattr(instance, 'image'): if isinstance(instance.image, dict): instance.image['name'] = "-" def _task_get_volumes_snapshots(): volume_ids_with_snapshots.extend( self._get_volumes_ids_with_snapshots( search_opts={'all_tenants': True})) def _task_get_volumes(): volumes.extend(self._get_volumes(search_opts=filters)) # update group name for volumes self._get_groups(volumes, search_opts={'all_tenants': True}) attached_instance_ids.extend( self._get_attached_instance_ids(volumes)) if 'project' in filters: futurist_utils.call_functions_parallel( _task_get_tenants, _task_get_instances, _task_get_volumes_snapshots) tenant_ids = [ t.id for t in tenants if t.name == filters['project'] ] if not tenant_ids: return [] del filters['project'] for id in tenant_ids: filters['project_id'] = id volumes += self._get_volumes(search_opts=filters) attached_instance_ids = self._get_attached_instance_ids(volumes) else: futurist_utils.call_functions_parallel( _task_get_volumes, _task_get_tenants, _task_get_instances, _task_get_volumes_snapshots) self._set_volume_attributes(volumes, instances, volume_ids_with_snapshots) for volume in volumes: tenant_id = getattr(volume, "os-vol-tenant-attr:tenant_id", None) tenant = tenant_dict.get(tenant_id, None) volume.tenant_name = getattr(tenant, "name", None) return volumes
def can_set_mount_point(): """Return the Hypervisor's capability of setting mount points.""" return utils.get_dict_config('OPENSTACK_HYPERVISOR_FEATURES', 'can_set_mount_point')
def keystone_backend_name(): return setting_utils.get_dict_config( 'OPENSTACK_KEYSTONE_BACKEND', 'name') or 'unknown'
# # 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 django.conf.urls import url from django.utils.translation import ugettext_lazy as _ from horizon.browsers import views from openstack_dashboard.dashboards.project.key_pairs import views as \ legacy_views from openstack_dashboard.utils import settings as setting_utils if setting_utils.get_dict_config('ANGULAR_FEATURES', 'key_pairs_panel'): title = _("Key Pairs") urlpatterns = [ url('', views.AngularIndexView.as_view(title=title), name='index'), url(r'^(?P<keypair_name>[^/]+)/$', views.AngularIndexView.as_view(title=title), name='detail'), ] else: urlpatterns = [ url(r'^$', legacy_views.IndexView.as_view(), name='index'), url(r'^import/$', legacy_views.ImportView.as_view(), name='import'), url(r'^(?P<keypair_name>[^/]+)/$', legacy_views.DetailView.as_view(), name='detail'), ]
# 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 django.conf.urls import url from django.utils.translation import ugettext_lazy as _ from horizon.browsers.views import AngularIndexView from openstack_dashboard.dashboards.identity.roles import views from openstack_dashboard.utils import settings as setting_utils if setting_utils.get_dict_config('ANGULAR_FEATURES', 'roles_panel'): # New angular panel title = _('Roles') urlpatterns = [ url(r'^$', AngularIndexView.as_view(title=title), name='index'), ] else: urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), url(r'^(?P<role_id>[^/]+)/update/$', views.UpdateView.as_view(), name='update'), url(r'^create/$', views.CreateView.as_view(), name='create'), ]
def can_set_quotas(): return utils.get_dict_config('OPENSTACK_HYPERVISOR_FEATURES', 'enable_quotas')