def config(since, **kwargs): license_info = get_license() install_type = 'traditional' if os.environ.get('container') == 'oci': install_type = 'openshift' elif 'KUBERNETES_SERVICE_PORT' in os.environ: install_type = 'k8s' return { 'platform': { 'system': platform.system(), 'dist': platform.dist(), 'release': platform.release(), 'type': install_type, }, 'install_uuid': settings.INSTALL_UUID, 'instance_uuid': settings.SYSTEM_UUID, 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'free_instances': license_info.get('free_instances', 0), 'total_licensed_instances': license_info.get('instance_count', 0), 'license_expiry': license_info.get('time_remaining', 0), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'authentication_backends': settings.AUTHENTICATION_BACKENDS, 'logging_aggregators': settings.LOG_AGGREGATOR_LOGGERS, 'external_logger_enabled': settings.LOG_AGGREGATOR_ENABLED, 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', None), }
def get(self, request, format=None): '''Return various sitewide configuration settings''' if request.user.is_superuser or request.user.is_system_auditor: license_data = get_license(show_key=True) else: license_data = get_license(show_key=False) if not license_data.get('valid_key', False): license_data = {} if license_data and 'features' in license_data and 'activity_streams' in license_data[ 'features']: # FIXME: Make the final setting value dependent on the feature? license_data['features'][ 'activity_streams'] &= settings.ACTIVITY_STREAM_ENABLED pendo_state = settings.PENDO_TRACKING_STATE if settings.PENDO_TRACKING_STATE in ( 'off', 'anonymous', 'detailed') else 'off' data = dict( time_zone=settings.TIME_ZONE, license_info=license_data, version=get_awx_version(), ansible_version=get_ansible_version(), eula=render_to_string("eula.md") if license_data.get('license_type', 'UNLICENSED') != 'open' else '', analytics_status=pendo_state, analytics_collectors=all_collectors(), become_methods=PRIVILEGE_ESCALATION_METHODS, ) # If LDAP is enabled, user_ldap_fields will return a list of field # names that are managed by LDAP and should be read-only for users with # a non-empty ldap_dn attribute. if getattr(settings, 'AUTH_LDAP_SERVER_URI', None): user_ldap_fields = ['username', 'password'] user_ldap_fields.extend( getattr(settings, 'AUTH_LDAP_USER_ATTR_MAP', {}).keys()) user_ldap_fields.extend( getattr(settings, 'AUTH_LDAP_USER_FLAGS_BY_GROUP', {}).keys()) data['user_ldap_fields'] = user_ldap_fields if request.user.is_superuser \ or request.user.is_system_auditor \ or Organization.accessible_objects(request.user, 'admin_role').exists() \ or Organization.accessible_objects(request.user, 'auditor_role').exists() \ or Organization.accessible_objects(request.user, 'project_admin_role').exists(): data.update( dict(project_base_dir=settings.PROJECTS_ROOT, project_local_paths=Project.get_local_path_choices(), custom_virtualenvs=get_custom_venv_choices())) elif JobTemplate.accessible_objects(request.user, 'admin_role').exists(): data['custom_virtualenvs'] = get_custom_venv_choices() return Response(data)
def config(since): license_info = get_license(show_key=False) return { 'system_uuid': settings.SYSTEM_UUID, 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'free_instances': license_info.get('free instances', 0), 'license_expiry': license_info.get('time_remaining', 0), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'authentication_backends': settings.AUTHENTICATION_BACKENDS, 'logging_aggregators': settings.LOG_AGGREGATOR_LOGGERS, 'external_logger_enabled': settings.LOG_AGGREGATOR_ENABLED, 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', None), }
def galaxy_validate(serializer, attrs): """Ansible Galaxy config options have mutual exclusivity rules, these rules are enforced here on serializer validation so that users will not be able to save settings which obviously break all project updates. """ prefix = 'PRIMARY_GALAXY_' errors = {} def _new_value(setting_name): if setting_name in attrs: return attrs[setting_name] elif not serializer.instance: return '' return getattr(serializer.instance, setting_name, '') if not _new_value('PRIMARY_GALAXY_URL'): if _new_value('PUBLIC_GALAXY_ENABLED') is False: msg = _( 'A URL for Primary Galaxy must be defined before disabling public Galaxy.' ) # put error in both keys because UI has trouble with errors in toggles for key in ('PRIMARY_GALAXY_URL', 'PUBLIC_GALAXY_ENABLED'): errors.setdefault(key, []) errors[key].append(msg) raise serializers.ValidationError(errors) from awx.main.constants import GALAXY_SERVER_FIELDS if not any('{}{}'.format(prefix, subfield.upper()) in attrs for subfield in GALAXY_SERVER_FIELDS): return attrs galaxy_data = {} for subfield in GALAXY_SERVER_FIELDS: galaxy_data[subfield] = _new_value('{}{}'.format( prefix, subfield.upper())) if not galaxy_data['url']: for k, v in galaxy_data.items(): if v: setting_name = '{}{}'.format(prefix, k.upper()) errors.setdefault(setting_name, []) errors[setting_name].append( _('Cannot provide field if PRIMARY_GALAXY_URL is not set.') ) for k in GALAXY_SERVER_FIELDS: if galaxy_data[k]: setting_name = '{}{}'.format(prefix, k.upper()) if (not serializer.instance) or (not getattr( serializer.instance, setting_name, '')): # new auth is applied, so check if compatible with version from awx.main.utils import get_ansible_version current_version = get_ansible_version() min_version = '2.9' if Version(current_version) < Version(min_version): errors.setdefault(setting_name, []) errors[setting_name].append( _('Galaxy server settings are not available until Ansible {min_version}, ' 'you are running {current_version}.').format( min_version=min_version, current_version=current_version)) if (galaxy_data['password'] or galaxy_data['username']) and (galaxy_data['token'] or galaxy_data['auth_url']): for k in ('password', 'username', 'token', 'auth_url'): setting_name = '{}{}'.format(prefix, k.upper()) if setting_name in attrs: errors.setdefault(setting_name, []) errors[setting_name].append( _('Setting Galaxy token and authentication URL is mutually exclusive with username and password.' )) if bool(galaxy_data['username']) != bool(galaxy_data['password']): msg = _( 'If authenticating via username and password, both must be provided.' ) for k in ('username', 'password'): setting_name = '{}{}'.format(prefix, k.upper()) errors.setdefault(setting_name, []) errors[setting_name].append(msg) if bool(galaxy_data['token']) != bool(galaxy_data['auth_url']): msg = _( 'If authenticating via token, both token and authentication URL must be provided.' ) for k in ('token', 'auth_url'): setting_name = '{}{}'.format(prefix, k.upper()) errors.setdefault(setting_name, []) errors[setting_name].append(msg) if errors: raise serializers.ValidationError(errors) return attrs
def metrics(): license_info = get_license(show_key=False) SYSTEM_INFO.info({ 'system_uuid': settings.SYSTEM_UUID, 'insights_analytics': str(settings.INSIGHTS_DATA_ENABLED), 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'free_instances': str(license_info.get('free instances', 0)), 'license_expiry': str(license_info.get('time_remaining', 0)), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'external_logger_enabled': str(settings.LOG_AGGREGATOR_ENABLED), 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', 'None') }) current_counts = counts(None) ORG_COUNT.set(current_counts['organization']) USER_COUNT.set(current_counts['user']) TEAM_COUNT.set(current_counts['team']) INV_COUNT.set(current_counts['inventory']) PROJ_COUNT.set(current_counts['project']) JT_COUNT.set(current_counts['job_template']) WFJT_COUNT.set(current_counts['workflow_job_template']) HOST_COUNT.labels(type='all').set(current_counts['host']) HOST_COUNT.labels(type='active').set(current_counts['active_host_count']) SCHEDULE_COUNT.set(current_counts['schedule']) INV_SCRIPT_COUNT.set(current_counts['custom_inventory_script']) CUSTOM_VENVS.set(current_counts['custom_virtualenvs']) USER_SESSIONS.labels(type='all').set(current_counts['active_sessions']) USER_SESSIONS.labels(type='user').set(current_counts['active_user_sessions']) USER_SESSIONS.labels(type='anonymous').set(current_counts['active_anonymous_sessions']) RUNNING_JOBS.set(current_counts['running_jobs']) instance_data = instance_info(None) for uuid in instance_data: INSTANCE_CAPACITY.labels(type=uuid).set(instance_data[uuid]['capacity']) INSTANCE_CPU.labels(type=uuid).set(instance_data[uuid]['cpu']) INSTANCE_MEMORY.labels(type=uuid).set(instance_data[uuid]['memory']) INSTANCE_INFO.labels(type=uuid).info({ 'enabled': str(instance_data[uuid]['enabled']), 'last_isolated_check': getattr(instance_data[uuid], 'last_isolated_check', 'None'), 'managed_by_policy': str(instance_data[uuid]['managed_by_policy']), 'version': instance_data[uuid]['version'] }) instance_data = job_instance_counts(None) for node in instance_data: # skipping internal execution node (for system jobs) # TODO: determine if we should exclude execution_node from instance count if node == '': continue types = instance_data[node].get('launch_type', {}) for launch_type, value in types.items(): INSTANCE_LAUNCH_TYPE.labels(node=node, launch_type=launch_type).set(value) statuses = instance_data[node].get('status', {}) for status, value in statuses.items(): INSTANCE_STATUS.labels(node=node, status=status).set(value) return generate_latest()
self.start_queue() def tearDown(self): super(QueueStartStopTestMixin, self).tearDown() self.terminate_queue() class MockCommonlySlowTestMixin(object): def __init__(self, *args, **kwargs): from awx.api import generics mock.patch.object(generics, 'get_view_description', return_value=None).start() super(MockCommonlySlowTestMixin, self).__init__(*args, **kwargs) ansible_version = get_ansible_version() class BaseTestMixin(MockCommonlySlowTestMixin): ''' Mixin with shared code for use by all test cases. ''' def setUp(self): super(BaseTestMixin, self).setUp() global ansible_version self.object_ctr = 0 # Save sys.path before tests. self._sys_path = [x for x in sys.path] # Save os.environ before tests. self._environ = dict(os.environ.items())