Commit 42092a44 by Karsa Zoltán István

rules and interfaces endpoint

parent 0c41ced7
...@@ -71,6 +71,7 @@ class InstanceSerializer(serializers.ModelSerializer): ...@@ -71,6 +71,7 @@ class InstanceSerializer(serializers.ModelSerializer):
ipv4addr = serializers.SerializerMethodField('get_ipv4') ipv4addr = serializers.SerializerMethodField('get_ipv4')
ipv6addr = serializers.SerializerMethodField('get_ipv6') ipv6addr = serializers.SerializerMethodField('get_ipv6')
vlans = serializers.SerializerMethodField('get_vlans') vlans = serializers.SerializerMethodField('get_vlans')
#interfaces = serializers.SerializerMethodField('get_interfaces')
def get_ipv4(self, i): def get_ipv4(self, i):
return str(i.ipv4) return str(i.ipv4)
...@@ -81,10 +82,13 @@ class InstanceSerializer(serializers.ModelSerializer): ...@@ -81,10 +82,13 @@ class InstanceSerializer(serializers.ModelSerializer):
def get_vlans(self, i): def get_vlans(self, i):
return list(net.vlan.id for net in i.interface_set.all() if net.host) return list(net.vlan.id for net in i.interface_set.all() if net.host)
def get_interfaces(self, i):
return i.interface_set.all()
class Meta: class Meta:
model = Instance model = Instance
fields = ['id', 'name', 'description', 'status', 'owner', 'access_method', 'boot_menu', 'pw', 'is_base', fields = ['id', 'name', 'description', 'status', 'owner', 'access_method', 'boot_menu', 'pw', 'is_base',
'lease', 'raw_data', 'cloud_init', 'ci_meta_data', 'ci_user_data', 'system', 'req_traits', 'lease', 'raw_data', 'cloud_init', 'ci_meta_data', 'ci_user_data', 'system', 'req_traits', 'interface_set',
'has_agent', 'num_cores', 'ram_size', 'max_ram_size', 'arch', 'priority', 'disks', 'node', 'ipv4addr', 'ipv6addr', 'vlans'] 'has_agent', 'num_cores', 'ram_size', 'max_ram_size', 'arch', 'priority', 'disks', 'node', 'ipv4addr', 'ipv6addr', 'vlans']
extra_kwargs = { extra_kwargs = {
'disks': {'required': False, 'allow_empty': True,}, 'disks': {'required': False, 'allow_empty': True,},
......
...@@ -64,7 +64,7 @@ from .views import ( ...@@ -64,7 +64,7 @@ from .views import (
SleepInstanceREST, WakeUpInstanceREST, DownloadPersistentDiskREST, SleepInstanceREST, WakeUpInstanceREST, DownloadPersistentDiskREST,
CreatePersistentDiskREST, GetStorageActivityREST, GetTemplateREST, CreatePersistentDiskREST, GetStorageActivityREST, GetTemplateREST,
MessageList, MessageDetail, MessageCreate, MessageDelete, MessageList, MessageDetail, MessageCreate, MessageDelete,
SetupPortREST, SetupPortREST, RulesREST,
EnableTwoFactorView, DisableTwoFactorView, EnableTwoFactorView, DisableTwoFactorView,
AclUserGroupAutocomplete, AclUserAutocomplete, AclUserGroupAutocomplete, AclUserAutocomplete,
RescheduleView, GroupImportView, GroupExportView, RescheduleView, GroupImportView, GroupExportView,
...@@ -101,6 +101,7 @@ urlpatterns = [ ...@@ -101,6 +101,7 @@ urlpatterns = [
path('acpi/ftusersid/', InstanceFTforUsersIdREST.as_view()), path('acpi/ftusersid/', InstanceFTforUsersIdREST.as_view()),
path('acpi/vm/<int:pk>/downloaddisk/', DownloadDiskREST.as_view()), path('acpi/vm/<int:pk>/downloaddisk/', DownloadDiskREST.as_view()),
path('acpi/vm/<int:vm_id>/port/<int:vlan_id>/', SetupPortREST.as_view()), path('acpi/vm/<int:vm_id>/port/<int:vlan_id>/', SetupPortREST.as_view()),
path('acpi/vm/<int:vm_id>/rules/<int:vlan_id>/', RulesREST.as_view()),
path('acpi/vm/<int:pk>/createdisk/', CreateDiskREST.as_view()), path('acpi/vm/<int:pk>/createdisk/', CreateDiskREST.as_view()),
path('acpi/vm/<int:pk>/deploy/', DeployInstanceREST.as_view()), path('acpi/vm/<int:pk>/deploy/', DeployInstanceREST.as_view()),
path('acpi/vm/<int:pk>/shutdown/', ShutdownInstanceREST.as_view()), path('acpi/vm/<int:pk>/shutdown/', ShutdownInstanceREST.as_view()),
......
...@@ -338,8 +338,17 @@ class SleepInstanceREST(APIView): ...@@ -338,8 +338,17 @@ class SleepInstanceREST(APIView):
class RulesREST(APIView): class RulesREST(APIView):
def post(): authentication_classes = [TokenAuthentication,BasicAuthentication]
pass permission_classes = [IsAdminUser]
def get(self, request, vm_id, vlan_id, format=None):
instance = Instance.objects.get(pk=vm_id)
vlan=Vlan.objects.get(pk=vlan_id)
interface = Interface.objects.filter(instance=instance).filter(vlan=vlan).get()
rules = Rule.objects.filter(host=interface.host)
serializer = RuleSerializer(rules, many=True)
return JsonResponse(serializer.data, safe=False, status=200)
class SetupPortREST(APIView): class SetupPortREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication] authentication_classes = [TokenAuthentication,BasicAuthentication]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment