aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/serializers
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-06-08 12:46:53 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-07-21 13:17:51 -0400
commita09db9f287a02873c0226759f8ea444bb304cd59 (patch)
tree59e744e4b998973a808abbae2d21fbdd6201d829 /src/api/serializers
parent8ddc7e820e120f1dde4e901d3cb6f1dd3f281e65 (diff)
LaaS 3.0 Almost MVP
Change-Id: Ided9a43cf3088bb58a233dc459711c03f43e11b8 Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/api/serializers')
-rw-r--r--src/api/serializers/__init__.py8
-rw-r--r--src/api/serializers/booking_serializer.py173
-rw-r--r--src/api/serializers/old_serializers.py21
3 files changed, 0 insertions, 202 deletions
diff --git a/src/api/serializers/__init__.py b/src/api/serializers/__init__.py
deleted file mode 100644
index e0408fa..0000000
--- a/src/api/serializers/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
diff --git a/src/api/serializers/booking_serializer.py b/src/api/serializers/booking_serializer.py
deleted file mode 100644
index 993eb22..0000000
--- a/src/api/serializers/booking_serializer.py
+++ /dev/null
@@ -1,173 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from rest_framework import serializers
-
-from resource_inventory.models import (
- ResourceConfiguration,
- CpuProfile,
- DiskProfile,
- InterfaceProfile,
- RamProfile,
- Image,
- Interface
-)
-
-
-class BookingField(serializers.Field):
-
- def to_representation(self, booking):
- """
- Take in a booking object.
-
- Returns a dictionary of primitives representing that booking
- """
- ser = {}
- ser['id'] = booking.id
- # main loop to grab relevant info out of booking
- host_configs = {} # mapping hostname -> config
- networks = {} # mapping vlan id -> network_hosts
- for host in booking.resource.hosts.all():
- host_configs[host.name] = ResourceConfiguration.objects.get(host=host.template)
- if "jumphost" not in ser and host_configs[host.name].opnfvRole.name.lower() == "jumphost":
- ser['jumphost'] = host.name
- # host is a Host model
- for i in range(len(host.interfaces.all())):
- interface = host.interfaces.all()[i]
- # interface is an Interface model
- for vlan in interface.config.all():
- # vlan is Vlan model
- if vlan.id not in networks:
- networks[vlan.id] = []
- net_host = {"hostname": host.name, "tagged": vlan.tagged, "interface": i}
- networks[vlan.id].append(net_host)
- # creates networking object of proper form
- networking = []
- for vlanid in networks:
- network = {}
- network['vlan_id'] = vlanid
- network['hosts'] = networks[vlanid]
-
- ser['networking'] = networking
-
- # creates hosts object of correct form
- hosts = []
- for hostname in host_configs:
- host = {"hostname": hostname}
- host['deploy_image'] = True # TODO?
- image = host_configs[hostname].image
- host['image'] = {
- "name": image.name,
- "lab_id": image.lab_id,
- "dashboard_id": image.id
- }
- hosts.append(host)
-
- ser['hosts'] = hosts
-
- return ser
-
- def to_internal_value(self, data):
- """
- Take in a dictionary of primitives, and return a booking object.
-
- This is not going to be implemented or allowed.
- If someone needs to create a booking through the api,
- they will send a different booking object
- """
- return None
-
-
-class BookingSerializer(serializers.Serializer):
-
- booking = BookingField()
-
-
-# Host Type stuff, for inventory
-class CPUSerializer(serializers.ModelSerializer):
- class Meta:
- model = CpuProfile
- fields = ('cores', 'architecture', 'cpus')
-
-
-class DiskSerializer(serializers.ModelSerializer):
- class Meta:
- model = DiskProfile
- fields = ('size', 'media_type', 'name')
-
-
-class InterfaceProfileSerializer(serializers.ModelSerializer):
- class Meta:
- model = InterfaceProfile
- fields = ('speed', 'name')
-
-
-class RamSerializer(serializers.ModelSerializer):
- class Meta:
- model = RamProfile
- fields = ('amount', 'channels')
-
-
-class HostTypeSerializer(serializers.Serializer):
- name = serializers.CharField(max_length=200)
- ram = RamSerializer()
- interface = InterfaceProfileSerializer()
- description = serializers.CharField(max_length=1000)
- disks = DiskSerializer()
- cpu = CPUSerializer()
-
-
-# the rest of the inventory stuff
-class NetworkSerializer(serializers.Serializer):
- cidr = serializers.CharField(max_length=200)
- gateway = serializers.IPAddressField(max_length=200)
- vlan = serializers.IntegerField()
-
-
-class ImageSerializer(serializers.ModelSerializer):
- lab_id = serializers.IntegerField()
- id = serializers.IntegerField(source="dashboard_id")
- name = serializers.CharField(max_length=50)
- description = serializers.CharField(max_length=200)
-
- class Meta:
- model = Image
-
-
-class InterfaceField(serializers.Field):
- def to_representation(self, interface):
- pass
-
- def to_internal_value(self, data):
- """Take in a serialized interface and creates an Interface model."""
- mac = data['mac']
- bus_address = data['busaddr']
- switch_name = data['switchport']['switch_name']
- port_name = data['switchport']['port_name']
- # TODO config??
- return Interface.objects.create(
- mac_address=mac,
- bus_address=bus_address,
- switch_name=switch_name,
- port_name=port_name
- )
-
-
-class InventoryHostSerializer(serializers.Serializer):
- hostname = serializers.CharField(max_length=100)
- host_type = serializers.CharField(max_length=100)
- interfaces = InterfaceField()
-
-
-class InventorySerializer(serializers.Serializer):
- hosts = InventoryHostSerializer()
- networks = NetworkSerializer()
- images = ImageSerializer()
- host_types = HostTypeSerializer()
diff --git a/src/api/serializers/old_serializers.py b/src/api/serializers/old_serializers.py
deleted file mode 100644
index 0944881..0000000
--- a/src/api/serializers/old_serializers.py
+++ /dev/null
@@ -1,21 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from rest_framework import serializers
-
-from account.models import UserProfile
-
-
-class UserSerializer(serializers.ModelSerializer):
- username = serializers.CharField(source='user.username')
-
- class Meta:
- model = UserProfile
- fields = ('user', 'username', 'ssh_public_key', 'pgp_public_key', 'email_addr')