Commit 42092a44 by Karsa Zoltán István

rules and interfaces endpoint

parent 0c41ced7
......@@ -71,6 +71,7 @@ class InstanceSerializer(serializers.ModelSerializer):
ipv4addr = serializers.SerializerMethodField('get_ipv4')
ipv6addr = serializers.SerializerMethodField('get_ipv6')
vlans = serializers.SerializerMethodField('get_vlans')
#interfaces = serializers.SerializerMethodField('get_interfaces')
def get_ipv4(self, i):
return str(i.ipv4)
......@@ -81,10 +82,13 @@ class InstanceSerializer(serializers.ModelSerializer):
def get_vlans(self, i):
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:
model = Instance
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']
extra_kwargs = {
'disks': {'required': False, 'allow_empty': True,},
......
......@@ -64,7 +64,7 @@ from .views import (
SleepInstanceREST, WakeUpInstanceREST, DownloadPersistentDiskREST,
CreatePersistentDiskREST, GetStorageActivityREST, GetTemplateREST,
MessageList, MessageDetail, MessageCreate, MessageDelete,
SetupPortREST,
SetupPortREST, RulesREST,
EnableTwoFactorView, DisableTwoFactorView,
AclUserGroupAutocomplete, AclUserAutocomplete,
RescheduleView, GroupImportView, GroupExportView,
......@@ -101,6 +101,7 @@ urlpatterns = [
path('acpi/ftusersid/', InstanceFTforUsersIdREST.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>/rules/<int:vlan_id>/', RulesREST.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>/shutdown/', ShutdownInstanceREST.as_view()),
......
......@@ -338,8 +338,17 @@ class SleepInstanceREST(APIView):
class RulesREST(APIView):
def post():
pass
authentication_classes = [TokenAuthentication,BasicAuthentication]
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):
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