class MonitoringChannelSerializer(PlusModelSerializer): id = ReadOnlyField() service_specific_attribute = ReadOnlyField() ceilometer_url = ReadOnlyField() tenant_list_str = ReadOnlyField() #creator = ReadOnlyField() #instance = ReadOnlyField() provider_service = serializers.PrimaryKeyRelatedField( queryset=CeilometerService.get_service_objects().all(), default=get_default_ceilometer_service) humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") related = serializers.DictField(required=False) #computeNodeName = serializers.SerializerMethodField("getComputeNodeName") class Meta: model = MonitoringChannelForAPI fields = ('humanReadableName', 'id', 'provider_service', 'service_specific_attribute', 'ceilometer_url', 'tenant_list_str', 'related') def getHumanReadableName(self, obj): return obj.__unicode__()
class ExampleTenantSerializer(PlusModelSerializer): id = ReadOnlyField() provider_service = serializers.PrimaryKeyRelatedField(queryset=ExampleService.get_service_objects().all(), default=get_default_example_service) tenant_message = serializers.CharField(required=False) backend_status = ReadOnlyField() humanReadableName = serializers.SerializerMethodField("getHumanReadableName") class Meta: model = ExampleTenant fields = ('humanReadableName', 'id', 'provider_service', 'tenant_message', 'backend_status') def getHumanReadableName(self, obj): return obj.__unicode__()
class PoolSerializer(PlusModelSerializer): id = ReadOnlyField() class Meta: model = Pool fields = ('id', 'ptr_health_monitor_id', 'name', 'health_monitor', 'lb_algorithm', 'protocol', 'description', 'admin_state_up')
class MemberSerializer(PlusModelSerializer): id = ReadOnlyField() class Meta: model = Member fields = ('id', 'memberpool', 'ptr_pool_id', 'address', 'protocol_port', 'weight', 'admin_state_up')
class VTNServiceSerializer(PlusModelSerializer): id = ReadOnlyField() privateGatewayMac = serializers.CharField(required=False) localManagementIp = serializers.CharField(required=False) ovsdbPort = serializers.IntegerField(required=False) sshPort = serializers.IntegerField(required=False) sshUser = serializers.CharField(required=False) sshKeyFile = serializers.CharField(required=False) mgmtSubnetBits = serializers.IntegerField(required=False) xosEndpoint = serializers.CharField(required=False) xosUser = serializers.CharField(required=False) xosPassword = serializers.CharField(required=False) humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") class Meta: model = VTNService fields = ('humanReadableName', 'id', 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits', 'xosEndpoint', 'xosUser', 'xosPassword') def getHumanReadableName(self, obj): return obj.__unicode__()
class VSGTenantSerializer(PlusModelSerializer): id = ReadOnlyField() wan_container_ip = serializers.CharField() wan_container_mac = ReadOnlyField() related = serializers.DictField(required=False) humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") class Meta: model = VSGTenantForAPI fields = ('humanReadableName', 'id', 'wan_container_ip', 'wan_container_mac', 'related') def getHumanReadableName(self, obj): return obj.__unicode__()
class ListenerSerializer(PlusModelSerializer): id = ReadOnlyField() class Meta: model = Listener fields = ('id', 'name', 'protocol', 'protocol_port', 'stat_port', 'admin_state_up', 'connection_limit', 'description')
class VRouterIpSerializer(PlusModelSerializer): id = ReadOnlyField() ip = serializers.CharField(required=False) name = serializers.CharField(required=False) class Meta: model = VRouterIp fields = ('id', 'ip', 'name')
class OpenVPNTenantSerializer(PlusModelSerializer): """A Serializer for the OpenVPNTenant that has the minimum information required for clients. Attributes: id (ReadOnlyField): The ID of OpenVPNTenant. server_network (ReadOnlyField): The network of the VPN. vpn_subnet (ReadOnlyField): The subnet of the VPN. script_text (SerializerMethodField): The text of the script for the client to use to connect. """ id = ReadOnlyField() server_network = ReadOnlyField() vpn_subnet = ReadOnlyField() script_text = serializers.SerializerMethodField() class Meta: model = OpenVPNTenant fields = ('id', 'service_specific_attribute', 'vpn_subnet', 'server_network', 'script_text') def get_script_text(self, obj): """Gets the text of the client script for the requesting user. Parameters: obj (services.openvpn.models.OpenVPNTenant): The OpenVPNTenant to connect to. Returns: str: The client script as a str. """ env = jinja2.Environment(loader=jinja2.FileSystemLoader( "/opt/xos/services/openvpn/templates")) template = env.get_template("connect.vpn.j2") client_name = self.context['request'].user.email + "-" + str(obj.id) remote_ids = list(obj.failover_server_ids) remote_ids.insert(0, obj.id) remotes = OpenVPNTenant.get_tenant_objects().filter(pk__in=remote_ids) pki_dir = OpenVPNService.get_pki_dir(obj) fields = { "client_name": client_name, "remotes": remotes, "is_persistent": obj.is_persistent, "ca_crt": obj.get_ca_crt(pki_dir), "client_crt": obj.get_client_cert(client_name, pki_dir), "client_key": obj.get_client_key(client_name, pki_dir) } return template.render(fields)
class HealthSerializer(PlusModelSerializer): id = ReadOnlyField() class Meta: model = Healthmonitor fields = ('id', 'name', 'type', 'delay', 'max_retries', 'timeout', 'http_method', 'admin_state_up', 'url_path', 'expected_codes')
class LoadbalancerSerializer(PlusModelSerializer): id = ReadOnlyField() owner = serializers.PrimaryKeyRelatedField(queryset=LbService.objects.all(), default=get_default_lb_service) vip_address = serializers.CharField(required=True) class Meta: model = Loadbalancer fields = ('id', 'owner', 'name', 'listener', 'ptr_listener_id', 'pool', 'ptr_pool_id', 'slice_name', 'vip_address', 'description', 'admin_state_up')
class CeilometerServiceSerializer(PlusModelSerializer): id = ReadOnlyField() backend_status = ReadOnlyField() humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") ceilometer_pub_sub_url = ReadOnlyField() ceilometer_enable_pub_sub = ReadOnlyField() kafka_url = ReadOnlyField() related = serializers.DictField(required=False) class Meta: model = CeilometerServiceForApi fields = ('humanReadableName', 'id', 'backend_status', 'ceilometer_pub_sub_url', 'ceilometer_enable_pub_sub', 'kafka_url', 'related') def getHumanReadableName(self, obj): return obj.__unicode__()
class VTNNetworkSerializer(serializers.Serializer): id = ReadOnlyField() name = serializers.CharField(required=False) subnet = serializers.CharField(required=False) gateway = serializers.CharField(required=False) segmentation_id = serializers.CharField(required=False) class Meta: fields = ('id', 'name', 'subnet', 'gateway', 'segmentation_id')
class VTNServiceNetworkSerializer(serializers.Serializer): id = ReadOnlyField() type = serializers.CharField(required=False) subscriberNetworks = serializers.SerializerMethodField( "getSubscriberNetworks") providerNetworks = serializers.SerializerMethodField("getProviderNetworks") ownerSliceName = ReadOnlyField() ownerServiceName = ReadOnlyField() class Meta: fields = ('id', 'type', "subscriberNetworks", "providerNetworks", "ownerSliceName", "ownerServiceName") def getSubscriberNetworks(self, obj): return obj.subscriberNetworks def getProviderNetworks(self, obj): return obj.providerNetworks
class FirewallSerializer(PlusModelSerializer): id = ReadOnlyField() owner = serializers.PrimaryKeyRelatedField( queryset=FwService.objects.all(), default=get_default_fw_service) class Meta: model = Firewall fields = ('id', 'owner', 'firewall_name', 'firewall_name', 'firewall_id', 'firewall_rules', 'slice_name', 'status', 'description')
class VTNPortSerializer(serializers.Serializer): id = ReadOnlyField() name = serializers.CharField(required=False) network_id = serializers.CharField(required=False) network_name = serializers.CharField(required=False) mac_address = serializers.CharField(required=False) ip_address = serializers.CharField(required=False) class Meta: fields = ('id', 'name', 'network_id', 'network_name', 'mac_address', 'ip_address')
class ExampleServiceSerializer(PlusModelSerializer): id = ReadOnlyField() humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") service_message = serializers.CharField(required=False) class Meta: model = ExampleService fields = ('humanReadableName', 'id', 'service_message') def getHumanReadableName(self, obj): return obj.__unicode__()
class ONOSAppSerializer(PlusModelSerializer): id = ReadOnlyField() name = serializers.CharField() dependencies = serializers.CharField() humanReadableName = serializers.SerializerMethodField("getHumanReadableName") class Meta: model = ONOSApp fields = ('humanReadableName', 'id', 'name', 'dependencies') def getHumanReadableName(self, obj): return obj.__unicode__()
class VRouterPortSerializer(PlusModelSerializer): id = ReadOnlyField() name = serializers.CharField(required=False) openflow_id = serializers.CharField(required=False) interfaces = serializers.SerializerMethodField("getPortInterfaces") def getPortInterfaces(self, port): interfaces = VRouterInterface.objects.filter(vrouter_port=port.id) return VRouterInterfaceSerializer(interfaces, many=True).data class Meta: model = VRouterPort fields = ('id', 'name', 'openflow_id', 'interfaces')
class VRouterInterfaceSerializer(PlusModelSerializer): id = ReadOnlyField() name = serializers.CharField(required=False) mac = serializers.CharField(required=False) vlan = serializers.CharField(required=False) ips = serializers.SerializerMethodField("getInterfaceIps") def getInterfaceIps(self, interface): interfaces = VRouterIp.objects.filter(vrouter_interface=interface.id) return VRouterIpSerializer(interfaces, many=True).data class Meta: model = VRouterPort fields = ('id', 'name', 'mac', 'vlan', 'ips')
class MetroNetworkSystemSerializer(PlusModelSerializer): id = ReadOnlyField() humanReadableName = serializers.SerializerMethodField("getHumanReadableName") class Meta: model = MetroNetworkSystem fields = ('humanReadableName', 'id', 'restUrl', 'administrativeState', 'operationalState') def getHumanReadableName(self, obj): return obj.name
class VRouterAppSerializer(PlusModelSerializer): id = ReadOnlyField() name = serializers.CharField(required=False) control_plane_connect_point = serializers.CharField(required=False) ospf_enabled = serializers.BooleanField(required=False) interfaces = serializers.SerializerMethodField("dumpInterfaces") def dumpInterfaces(self, app): return json.dumps(app.interfaces) class Meta: model = VRouterApp fields = ('id', 'name', 'control_plane_connect_point', 'ospf_enabled', 'interfaces')
class VTRTenantSerializer(PlusModelSerializer): id = ReadOnlyField() target_id = serializers.IntegerField() test = serializers.CharField() scope = serializers.CharField() argument = serializers.CharField(required=False) provider_service = serializers.PrimaryKeyRelatedField(queryset=VTRService.get_service_objects().all(), default=get_default_vtr_service) result = serializers.CharField(required=False) result_code = serializers.CharField(required=False) backend_status = ReadOnlyField() humanReadableName = serializers.SerializerMethodField("getHumanReadableName") is_synced = serializers.SerializerMethodField("isSynced") class Meta: model = VTRTenantForAPI fields = ('humanReadableName', 'id', 'provider_service', 'target_id', 'scope', 'test', 'argument', 'result', 'result_code', 'is_synced', 'backend_status' ) def getHumanReadableName(self, obj): return obj.__unicode__() def isSynced(self, obj): return (obj.enacted is not None) and (obj.enacted >= obj.updated)
class VTNServicePortSerializer(serializers.Serializer): id = ReadOnlyField() vlan_id = serializers.IntegerField(required=False) network_name = serializers.CharField(required=False) # TODO: structure this better floating_address_pairs = serializers.SerializerMethodField( "getFloatingAddressPairs") class Meta: fields = ('id', 'vlan_id', 'network_name') def getFloatingAddressPairs(self, obj): return obj.floating_address_pairs
class VRouterServiceSerializer(PlusModelSerializer): id = ReadOnlyField() name = serializers.CharField(required=False) kind = serializers.CharField(required=False) service_specific_attribute = serializers.CharField(required=False) humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") class Meta: model = VRouterService fields = ('humanReadableName', 'id', 'name', 'kind', 'service_specific_attribute') def getHumanReadableName(self, obj): return obj.__unicode__()
class CordSubscriberSerializer(PlusModelSerializer): id = ReadOnlyField() humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") features = FeatureSerializer(required=False) identity = IdentitySerializer(required=False) related = serializers.DictField(required=False) nested_fields = ["features", "identity"] class Meta: model = CordSubscriberNew fields = ('humanReadableName', 'id', 'features', 'identity', 'related') def getHumanReadableName(self, obj): return obj.__unicode__()
class ONOSServiceSerializer(PlusModelSerializer): id = ReadOnlyField() rest_hostname = serializers.CharField(required=False) rest_port = serializers.CharField(default="8181") no_container = serializers.BooleanField(default=False) node_key = serializers.CharField(required=False) humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") class Meta: model = ONOSService fields = ('humanReadableName', 'id', 'rest_hostname', 'rest_port', 'no_container', 'node_key') def getHumanReadableName(self, obj): return obj.__unicode__()
class VSGServiceSerializer(PlusModelSerializer): id = ReadOnlyField() humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") wan_container_gateway_ip = serializers.CharField(required=False) wan_container_gateway_mac = serializers.CharField(required=False) dns_servers = serializers.CharField(required=False) url_filter_kind = serializers.CharField(required=False) node_label = serializers.CharField(required=False) class Meta: model = VSGServiceForApi fields = ('humanReadableName', 'id', 'wan_container_gateway_ip', 'wan_container_gateway_mac', 'dns_servers', 'url_filter_kind', 'node_label') def getHumanReadableName(self, obj): return obj.__unicode__()
class VRouterDeviceSerializer(PlusModelSerializer): id = ReadOnlyField() name = serializers.CharField(required=False) openflow_id = serializers.CharField(required=False) config_key = serializers.CharField(required=False) driver = serializers.CharField(required=False) vrouter_service = serializers.PrimaryKeyRelatedField(read_only=True) ports = serializers.SerializerMethodField("getDevicePorts") def getDevicePorts(self, device): ports = VRouterPort.objects.filter(vrouter_device=device.id) return VRouterPortSerializer(ports, many=True).data class Meta: model = VRouterDevice fields = ('id', 'name', 'openflow_id', 'config_key', 'driver', 'vrouter_service', 'ports')
class ComputeNodeServiceSerializer(PlusModelSerializer): id = ReadOnlyField() nodeId = serializers.CharField(required=True) hostname = serializers.CharField(required=True) fabricAddress = serializers.CharField(required=True) hardwareAddress = serializers.CharField(required=True) role = serializers.CharField(required=True) humanReadableName = serializers.SerializerMethodField( "getHumanReadableName") class Meta: model = ComputeNodeService fields = ('humanReadableName', 'id', 'nodeId', 'hostname', 'fabricAddress', 'hardwareAddress', 'role') def getHumanReadableName(self, obj): return obj.__unicode__()