mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 05:55:59 -03:30
Host Metrics List API
This commit is contained in:
committed by
John Westcott IV
parent
bf98f62654
commit
ef4e77d78f
@@ -56,6 +56,7 @@ from awx.main.models import (
|
|||||||
ExecutionEnvironment,
|
ExecutionEnvironment,
|
||||||
Group,
|
Group,
|
||||||
Host,
|
Host,
|
||||||
|
HostMetric,
|
||||||
Instance,
|
Instance,
|
||||||
InstanceGroup,
|
InstanceGroup,
|
||||||
InstanceLink,
|
InstanceLink,
|
||||||
@@ -5386,6 +5387,14 @@ class InstanceHealthCheckSerializer(BaseSerializer):
|
|||||||
fields = read_only_fields
|
fields = read_only_fields
|
||||||
|
|
||||||
|
|
||||||
|
class HostMetricSerializer(BaseSerializer):
|
||||||
|
show_capabilities = ['delete']
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = HostMetric
|
||||||
|
fields = ("hostname", "first_automation", "last_automation")
|
||||||
|
|
||||||
|
|
||||||
class InstanceGroupSerializer(BaseSerializer):
|
class InstanceGroupSerializer(BaseSerializer):
|
||||||
show_capabilities = ['edit', 'delete']
|
show_capabilities = ['edit', 'delete']
|
||||||
capacity = serializers.SerializerMethodField()
|
capacity = serializers.SerializerMethodField()
|
||||||
|
|||||||
10
awx/api/urls/host_metric.py
Normal file
10
awx/api/urls/host_metric.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Copyright (c) 2017 Ansible, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
|
||||||
|
from django.urls import re_path
|
||||||
|
|
||||||
|
from awx.api.views import HostMetricList
|
||||||
|
|
||||||
|
urls = [re_path(r'$^', HostMetricList.as_view(), name='host_metric_list')]
|
||||||
|
|
||||||
|
__all__ = ['urls']
|
||||||
@@ -50,6 +50,7 @@ from .inventory import urls as inventory_urls
|
|||||||
from .execution_environments import urls as execution_environment_urls
|
from .execution_environments import urls as execution_environment_urls
|
||||||
from .team import urls as team_urls
|
from .team import urls as team_urls
|
||||||
from .host import urls as host_urls
|
from .host import urls as host_urls
|
||||||
|
from .host_metric import urls as host_metric_urls
|
||||||
from .group import urls as group_urls
|
from .group import urls as group_urls
|
||||||
from .inventory_source import urls as inventory_source_urls
|
from .inventory_source import urls as inventory_source_urls
|
||||||
from .inventory_update import urls as inventory_update_urls
|
from .inventory_update import urls as inventory_update_urls
|
||||||
@@ -118,6 +119,7 @@ v2_urls = [
|
|||||||
re_path(r'^teams/', include(team_urls)),
|
re_path(r'^teams/', include(team_urls)),
|
||||||
re_path(r'^inventories/', include(inventory_urls)),
|
re_path(r'^inventories/', include(inventory_urls)),
|
||||||
re_path(r'^hosts/', include(host_urls)),
|
re_path(r'^hosts/', include(host_urls)),
|
||||||
|
re_path(r'^host_metrics/', include(host_metric_urls)),
|
||||||
re_path(r'^groups/', include(group_urls)),
|
re_path(r'^groups/', include(group_urls)),
|
||||||
re_path(r'^inventory_sources/', include(inventory_source_urls)),
|
re_path(r'^inventory_sources/', include(inventory_source_urls)),
|
||||||
re_path(r'^inventory_updates/', include(inventory_update_urls)),
|
re_path(r'^inventory_updates/', include(inventory_update_urls)),
|
||||||
|
|||||||
@@ -1548,6 +1548,13 @@ class HostRelatedSearchMixin(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
class HostMetricList(ListAPIView):
|
||||||
|
always_allow_superuser = False
|
||||||
|
name = _("Host Metrics List")
|
||||||
|
model = models.HostMetric
|
||||||
|
serializer_class = serializers.HostMetricSerializer
|
||||||
|
|
||||||
|
|
||||||
class HostList(HostRelatedSearchMixin, ListCreateAPIView):
|
class HostList(HostRelatedSearchMixin, ListCreateAPIView):
|
||||||
always_allow_superuser = False
|
always_allow_superuser = False
|
||||||
model = models.Host
|
model = models.Host
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ from awx.main.models import (
|
|||||||
ExecutionEnvironment,
|
ExecutionEnvironment,
|
||||||
Group,
|
Group,
|
||||||
Host,
|
Host,
|
||||||
|
HostMetric,
|
||||||
Instance,
|
Instance,
|
||||||
InstanceGroup,
|
InstanceGroup,
|
||||||
Inventory,
|
Inventory,
|
||||||
@@ -883,6 +884,38 @@ class OrganizationAccess(NotificationAttachMixin, BaseAccess):
|
|||||||
return super(OrganizationAccess, self).can_attach(obj, sub_obj, relationship, *args, **kwargs)
|
return super(OrganizationAccess, self).can_attach(obj, sub_obj, relationship, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class HostMetricAccess(BaseAccess):
|
||||||
|
"""
|
||||||
|
- I can see host metrics when a super user or system auditor.
|
||||||
|
- I can delete host metrics when a super user.
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = HostMetric
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
# if self.user.is_superuser or self.user.is_system_auditor:
|
||||||
|
# return self.model.objects.filter(Q(user__isnull=True) | Q(user=self.user))
|
||||||
|
# else:
|
||||||
|
# return self.model.objects.filter(user=self.user)
|
||||||
|
if self.user.is_superuser or self.user.is_system_auditor:
|
||||||
|
qs = self.model.objects.all()
|
||||||
|
else:
|
||||||
|
qs = self.filtered_queryset()
|
||||||
|
return qs
|
||||||
|
|
||||||
|
def can_read(self, obj):
|
||||||
|
return bool(self.user.is_superuser or self.user.is_system_auditor or (obj and obj.user == self.user))
|
||||||
|
|
||||||
|
def can_add(self, data):
|
||||||
|
return False # There is no API endpoint to POST new settings.
|
||||||
|
|
||||||
|
def can_change(self, obj, data):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def can_delete(self, obj):
|
||||||
|
return bool(self.user.is_superuser or (obj and obj.user == self.user))
|
||||||
|
|
||||||
|
|
||||||
class InventoryAccess(BaseAccess):
|
class InventoryAccess(BaseAccess):
|
||||||
"""
|
"""
|
||||||
I can see inventory when:
|
I can see inventory when:
|
||||||
|
|||||||
Reference in New Issue
Block a user