diff options
12 files changed, 1439 insertions, 166 deletions
diff --git a/gvnfmadapter/driver/interfaces/serializers.py b/gvnfmadapter/driver/interfaces/serializers.py deleted file mode 100644 index 43b3110..0000000 --- a/gvnfmadapter/driver/interfaces/serializers.py +++ /dev/null @@ -1,132 +0,0 @@ -# Copyright 2018 ZTE Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from rest_framework import serializers - - -class AdditionalParams(serializers.Serializer): - sdncontroller = serializers.CharField(help_text="sdncontroller", required=False) - NatIpRange = serializers.CharField(help_text="NatIpRange", required=False) - m6000_mng_ip = serializers.CharField(help_text="m6000_mng_ip", required=False) - externalPluginManageNetworkName = serializers.CharField(help_text="externalPluginManageNetworkName", required=False) - location = serializers.CharField(help_text="location", required=False) - externalManageNetworkName = serializers.CharField(help_text="externalManageNetworkName", required=False) - sfc_data_network = serializers.CharField(help_text="sfc_data_network", required=False) - externalDataNetworkName = serializers.CharField(help_text="externalDataNetworkName", required=False) - inputs = serializers.DictField( - help_text="inputs", - child=serializers.CharField(help_text="but i needed to test these 2 fields somehow", allow_blank=True), - required=False, - allow_null=True - ) - - -class VnfInstReqParamsSerializer(serializers.Serializer): - vnfDescriptorId = serializers.CharField( - help_text="Identifier that identifies the VNFD which defines the VNF instance to be created.", - max_length=255, - required=True, - allow_null=True - ) - vnfInstanceName = serializers.CharField( - help_text="Human-readable name of the VNF instance to be created.", - max_length=255, - required=True, - allow_null=False - ) - vnfInstanceDescription = serializers.CharField( - help_text="Human-readable description of the VNF instance to be created.", - max_length=255, - required=False, - allow_null=True - ) - additionalParam = AdditionalParams( - help_text="Additional input parameters for the instantiation process," - " specific to the VNF being instantiated.", - required=True - ) - - -class ResponseSerializer(serializers.Serializer): - vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True) - jobId = serializers.CharField(help_text="Job ID.", required=True) - - -class VnfTermReqSerializer(serializers.Serializer): - vnfInstanceId = serializers.CharField( - help_text="VNF instance identifier.", - max_length=255, - required=True, - allow_null=True - ) - - -class VnfInfo(serializers.Serializer): - vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True) - vnfStatus = serializers.CharField(help_text="The instantiation state of the VNF.", required=True) - version = serializers.CharField(help_text="Version of the VNF.", required=True) - - -class VnfQueryRespSerializer(serializers.Serializer): - vnfInfo = VnfInfo( - help_text="The information items about the selected VNF instance(s) that are returned.", - required=True - ) - - -class ResponseDescriptor(serializers.Serializer): - status = serializers.CharField(help_text="status.", required=True) - responsehistorylist = serializers.CharField(help_text="History response messages.", required=True) - responseid = serializers.IntegerField(help_text="Response identifier.", required=True) - errorcode = serializers.CharField(help_text="Errorcode.", required=True) - progress = serializers.IntegerField(help_text="Progress.", required=True) - statusdescription = serializers.CharField(help_text="Status description.", required=True) - - -class OperationStatusInfo(serializers.Serializer): - responsedescriptor = ResponseDescriptor(help_text="Response descriptor.", required=True) - jobid = serializers.CharField(help_text="Job ID.", required=True) - - -class VnfOperRespSerializer(serializers.Serializer): - operationStatusInfo = OperationStatusInfo( - help_text="Operation Status.", - required=True - ) - - -class VnfGrantReqSerializer(serializers.Serializer): - vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True) - nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True) - vimid = serializers.CharField(help_text="VIM identifier.", required=True) - exvimidlist = serializers.CharField(help_text="Extend VIM identifier list.", required=True) - tenant = serializers.CharField(help_text="Tenant name.", required=True) - vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True) - operationright = serializers.CharField(help_text="Operation right.", required=True) - vmlist = serializers.CharField(help_text="VM list.", required=True) - - -class VnfGrantRespSerializer(serializers.Serializer): - vimid = serializers.CharField(help_text="VIM identifier.", required=True) - tenant = serializers.CharField(help_text="Tenant name.", required=True) - - -class VnfNotifyReqSerializer(serializers.Serializer): - nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True) - vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True) - vimid = serializers.CharField(help_text="VIM identifier.", required=True) - timestamp = serializers.CharField(help_text="Timestamp.", required=True) - vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True) - eventtype = serializers.CharField(help_text="Event type.", required=True) - vmlist = serializers.CharField(help_text="VM list.", required=True) diff --git a/gvnfmadapter/driver/interfaces/serializers/__init__.py b/gvnfmadapter/driver/interfaces/serializers/__init__.py new file mode 100644 index 0000000..342c2a8 --- /dev/null +++ b/gvnfmadapter/driver/interfaces/serializers/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/gvnfmadapter/driver/interfaces/serializers/grant.py b/gvnfmadapter/driver/interfaces/serializers/grant.py new file mode 100644 index 0000000..4fa5335 --- /dev/null +++ b/gvnfmadapter/driver/interfaces/serializers/grant.py @@ -0,0 +1,402 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from driver.interfaces.serializers.link import LinkSerializer + +from rest_framework import serializers + + +class VimConnectionInfoSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.", + required=True + ) + vimId = serializers.CharField( + help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.", + required=False + ) + vimType = serializers.CharField( + help_text="Discriminator for the different types of the VIM information.", + required=False + ) + interfaceInfo = serializers.DictField( + help_text="Information about the interface or interfaces to the VIM.", + child=serializers.CharField(help_text="Interface Info", allow_blank=True), + required=False + ) + accessInfo = serializers.DictField( + help_text="Authentication credentials for accessing the VIM.", + child=serializers.CharField(help_text="Access Info", allow_blank=True), + required=False + ) + extra = serializers.DictField( + help_text="VIM type specific additional information.", + child=serializers.CharField(help_text="Extra", allow_blank=True), + required=False + ) + +class ZoneInfoSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="The identifier of this ZoneInfo instance, for the purpose of referencing it from other structures in the Grant structure.", + required=True + ) + zoneId = serializers.CharField( + help_text="The identifier of the resource zone, as managed by the resource management layer(typically, the VIM).", + required=False + ) + vimConnectionId = serializers.CharField( + help_text="Identifier of the connection to the VIM that manages the resource zone.", + required=False + ) + resourceProviderId = serializers.CharField( + help_text="Identifies the entity responsible for the management the resource zone.", + required=False + ) + + +class ZoneGroupInfoSerializer(serializers.Serializer): + zoneId = serializers.ListSerializer( + help_text="References of identifiers of ZoneInfo structures.", + child=serializers.CharField(help_text="IdentifierLocal", allow_blank=True), + required=False + ) + + +class GrantInfoSerializer(serializers.Serializer): + resourceDefinitionId = serializers.CharField( + help_text="Identifier of the related ResourceDefinition from the related GrantRequest.", + required=True + ) + reservationId = serializers.CharField( + help_text="The reservation identifier applicable to the VNFC/VirtualLink/VirtualStorage.", + required=False + ) + vimConnectionId = serializers.CharField( + help_text="Identifier of the VIM connection to be used to manage this resource.", + required=False, + ) + resourceProviderId = serializers.CharField( + help_text="Identifies the entity responsible for the management of the virtualised resource.", + required=False + ) + zoneId = serializers.CharField( + help_text="Reference to the identifier of the ZoneInfo in the Grant.", + required=False + ) + resourceGroupId = serializers.CharField( + help_text="Identifier of the infrastructure resource group.", + required=False + ) + + +class VimComputeResourceFlavourSerializer(serializers.Serializer): + vimConnectionId = serializers.CharField( + help_text="Identifier of the VIM connection to access the flavour referenced in this structure.", + required=False + ) + resourceProviderId = serializers.CharField( + help_text="Identifies the entity responsible for the management of the virtualised resource.", + required=False, + ) + vnfdVirtualComputeDescId = serializers.CharField( + help_text="Identifier which references the virtual compute descriptor in the VNFD that maps to this flavour.", + required=False + ) + vimFlavourId = serializers.CharField( + help_text="Identifier of the compute resource flavour in the resource management layer (i.e. VIM).", + required=False + ) + + +class VimSoftwareImageSerializer(serializers.Serializer): + vimConnectionId = serializers.CharField( + help_text="Identifier of the VIM connection to access the flavour referenced in this structure.", + required=False + ) + resourceProviderId = serializers.CharField( + help_text="Identifies the entity responsible for the management of the virtualised resource.", + required=False + ) + vnfdSoftwareImageId = serializers.CharField( + help_text="Identifier which references the software image descriptor in the VNFD.", + required=False + ) + vimSoftwareImageId = serializers.CharField( + help_text="Identifier of the software image in the resource management layer (i.e. VIM).", + required=False + ) + + +class VimAssetsSerializer(serializers.Serializer): + computeResourceFlavours = VimComputeResourceFlavourSerializer( + help_text="Mappings between virtual compute descriptors defined in the VNFD and compute resource flavours managed in the VIM.", + many=True, + required=False + ) + softwareImages = VimSoftwareImageSerializer( + help_text="Mappings between software images defined in the VNFD and software images managed in the VIM.", + many=True, + required=False + ) + + +class AddressRangeSerializer(serializers.Serializer): + minAddress = serializers.CharField( + help_text="Lowest IP address belonging to the range.", + required=True + ) + maxAddress = serializers.CharField( + help_text="Highest IP address belonging to the range.", + required=True + ) + + +class IpAddresseSerializer(serializers.Serializer): + type = serializers.ChoiceField( + help_text="The type of the IP addresses.", + choices=["IPV4", "IPV6"], + required=True + ) + fixedAddresses = serializers.ListSerializer( + help_text="Fixed addresses to assign.", + child=serializers.CharField(help_text="IpAddress"), + required=False + ) + numDynamicAddresses = serializers.IntegerField( + help_text="Number of dynamic addresses to assign.", + required=True + ) + addressRange = AddressRangeSerializer( + help_text="An IP address range to be used, e.g. in case of egress connections.", + required=False + ) + subnetId = serializers.CharField( + help_text="Subnet defined by the identifier of the subnet resource in the VIM.", + required=False + ) + + +class IpOverEthernetAddressDataSerializer(serializers.Serializer): + macAddress = serializers.CharField( + help_text="MAC address.", + required=False + ) + ipAddresses = IpAddresseSerializer( + help_text="List of IP addresses to assign to the CP instance.", + many=True, + required=False + ) + + +class CpProtocolDataSerializer(serializers.Serializer): + layerProtocol = serializers.ChoiceField( + help_text="Identifier of layer(s) and protocol(s).", + choices=["IP_OVER_ETHERNET"], + required=True + ) + ipOverEthernet = IpOverEthernetAddressDataSerializer( + help_text="Network address data for IP over Ethernet to assign to the extCP instance.", + required=False, + ) + + +class VnfExtCpConfigSerializer(serializers.Serializer): + cpInstanceId = serializers.CharField( + help_text="Identifier of the external CP instance to which this set of configuration parameters is requested to be applied.", + required=False + ) + linkPortId = serializers.CharField( + help_text="Identifier of a pre-configured link port to which the external CP will be associated.", + required=False + ) + cpProtocolData = CpProtocolDataSerializer( + help_text="Parameters for configuring the network protocols on the link port that connects the CP to a VL.", + many=True + ) + + +class VnfExtCpDataSerializer(serializers.Serializer): + cpdId = serializers.CharField( + help_text="The identifier of the CPD in the VNFD.", + required=True + ) + cpConfig = VnfExtCpConfigSerializer( + help_text="List of instance data that need to be configured on the CP instances created from the respective CPD.", + many=True, + required=False + ) + + +class ExtLinkPortDataSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="Identifier of this link port as provided by the entity that has created the link port.", + required=True + ) + resourceHandle = serializers.CharField( + help_text="Reference to the virtualised resource realizing this link port.", + required=True + ) + + +class ExtVirtualLinkDataSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="The identifier of the external VL instance.", + required=True + ) + vimConnectionId = serializers.CharField( + help_text="Identifier of the VIM connection to manage this resource.", + required=False + ) + resourceProviderId = serializers.CharField( + help_text="Identifies the entity responsible for the management of this resource.", + required=False + ) + resourceId = serializers.CharField( + help_text="The identifier of the resource in the scope of the VIM or the resource provider.", + required=True + ) + extCps = VnfExtCpDataSerializer( + help_text="External CPs of the VNF to be connected to this external VL.", + many=True, + required=False + ) + extLinkPorts = ExtLinkPortDataSerializer( + help_text="Externally provided link ports to be used to connect external connection points to this external VL.", + many=True, + required=False + ) + + +class ExtManagedVirtualLinkDataSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="The identifier of the externally-managed internal VL instance.", + required=True + ) + virtualLinkDescId = serializers.CharField( + help_text="The identifier of the VLD in the VNFD for this VL.", + required=True + ) + vimConnectionId = serializers.CharField( + help_text="Identifier of the VIM connection to manage this resource.", + required=False + ) + resourceProviderId = serializers.CharField( + help_text="Identifies the entity responsible for the management of this resource.", + required=False + ) + resourceId = serializers.CharField( + help_text="The identifier of the resource in the scope of the VIM or the resource provider.", + required=True + ) + + +class GrantLinksSerializer(serializers.Serializer): + self = LinkSerializer( + help_text="URI of this resource.", + required=True + ) + vnfLcmOpOcc = LinkSerializer( + help_text="Related VNF lifecycle management operation occurrence.", + required=True + ) + vnfInstance = LinkSerializer( + help_text="Related VNF instance.", + required=True + ) + + +class GrantSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="Identifier of the grant.", + required=True + ) + vnfInstanceId = serializers.CharField( + help_text="Identifier of the related VNF instance.", + required=True + ) + vnfLcmOpOccId = serializers.CharField( + help_text="Identifier of the related VNF lifecycle management operation occurrence.", + required=True, + ) + vimConnections = VimConnectionInfoSerializer( + help_text="Provides information regarding VIM connections that are approved to be used by the VNFM to allocate resources.", + many=True, + required=False + ) + zones = ZoneInfoSerializer( + help_text="Identifies resource zones where the resources are approved to be allocated by the VNFM.", + many=True, + required=False + ) + zoneGroups = ZoneGroupInfoSerializer( + help_text="Information about groups of resource zones.", + many=True, + required=False + ) + computeReservationId = serializers.CharField( + help_text="Information that identifies a reservation applicable to the compute resource requirements.", + required=False, + ) + networkReservationId = serializers.CharField( + help_text="Information that identifies a reservation applicable to the network resource requirements.", + required=False, + ) + storageReservationId = serializers.CharField( + help_text="Information that identifies a reservation applicable to the storage resource requirements.", + required=False, + ) + addResources = GrantInfoSerializer( + help_text="List of resources that are approved to be added.", + many=True, + required=False + ) + tempResources = GrantInfoSerializer( + help_text="List of resources that are approved to be temporarily instantiated during the runtime of the lifecycle operation.", + many=True, + required=False + ) + removeResources = GrantInfoSerializer( + help_text="List of resources that are approved to be removed.", + many=True, + required=False + ) + updateResources = GrantInfoSerializer( + help_text="List of resources that are approved to be modified.", + many=True, + required=False + ) + vimAssets = VimAssetsSerializer( + help_text="Information about assets for the VNF that are managed by the NFVO in the VIM.", + required=False, + ) + extVirtualLinks = ExtVirtualLinkDataSerializer( + help_text="Information about external VLs to connect the VNF to.", + many=True, + required=False + ) + extManagedVirtualLinks = ExtManagedVirtualLinkDataSerializer( + help_text="Information about internal VLs that are managed by other entities than the VNFM.", + many=True, + required=False + ) + additionalParams = serializers.DictField( + help_text="Additional parameters passed by the NFVO, \ + specific to the VNF and the LCM operation.", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + ) + _links = GrantLinksSerializer( + help_text="Links to resources related to this resource.", + required=True + ) diff --git a/gvnfmadapter/driver/interfaces/serializers/grant_request.py b/gvnfmadapter/driver/interfaces/serializers/grant_request.py new file mode 100644 index 0000000..6b93e1d --- /dev/null +++ b/gvnfmadapter/driver/interfaces/serializers/grant_request.py @@ -0,0 +1,192 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from driver.interfaces.serializers.link import LinkSerializer +from driver.interfaces.serializers.resource_handle import ResourceHandleSerializer + +from rest_framework import serializers + + +class ResourceDefinitionSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="Identifier of this ResourceDefinition, unique at least within the scope of the GrantRequest.", + required=True + ) + type = serializers.ChoiceField( + help_text="Type of the resource definition referenced.", + choices=["COMPUTE", "VL", "STORAGE", "LINKPORT"], + required=True + ) + vduId = serializers.CharField( + help_text="Reference to the related VDU in the VNFD applicable to this resource.", + required=False, + allow_null=True, + allow_blank=True + ) + resourceTemplateId = serializers.CharField( + help_text="Reference to a resource template(such as VnfVirtualLinkDesc) in the VNFD.", + required=False, + allow_null=True, + allow_blank=True + ) + resource = ResourceHandleSerializer( + help_text="Resource information for an existing resource.", + required=False, + allow_null=True + ) + + +class ConstraintResourceRefSerializer(serializers.Serializer): + idType = serializers.ChoiceField( + help_text="The type of the identifier.", + choices=["RES_MGMT", "GRANT"], + required=True + ) + resourceId = serializers.CharField( + help_text="An actual resource-management-level identifier(idType=RES_MGMT), or an identifier that references a ResourceDefinition(idType=GRANT).", + required=True + ) + vimConnectionId = serializers.CharField( + help_text="", + required=False, + allow_null=True, + allow_blank=True + ) + resourceProviderId = serializers.CharField( + help_text="Identifier of the resource provider. It shall only be present when idType = RES_MGMT.", + required=False, + allow_null=True, + allow_blank=True + ) + + +class PlacementConstraintSerializer(serializers.Serializer): + affinityOrAntiAffinity = serializers.ChoiceField( + help_text="The type of the constraint.", + choices=["AFFINITY", "ANTI_AFFINITY"], + required=True + ) + scope = serializers.ChoiceField( + help_text="The scope of the placement constraint indicating the category of the place where the constraint applies.", + choices=["NFVI_POP", "ZONE", "ZONE_GROUP", "NFVI_NODE"], + required=True + ) + resource = ConstraintResourceRefSerializer( + help_text="References to resources in the constraint rule.", + many=True, + required=False + ) + + +class VimConstraintSerializer(serializers.Serializer): + sameResourceGroup = serializers.BooleanField( + help_text="Set to true when the constraint applies not only to the same VIM connection, but also to the same infrastructure resource group.", + required=False + ) + resource = ConstraintResourceRefSerializer( + help_text="References to resources in the constraint rule.", + many=True, + required=False + ) + + +class GrantRequestLinksSerializer(serializers.Serializer): + vnfLcmOpOcc = LinkSerializer( + help_text="Related VNF lifecycle management operation occurrence.", + required=True + ) + vnfInstance = LinkSerializer( + help_text="Related VNF instance.", + required=True + ) + + +class GrantRequestSerializer(serializers.Serializer): + vnfInstanceId = serializers.CharField( + help_text="Identifier of the VNF instance which this grant request is related to.", + required=True + ) + vnfLcmOpOccId = serializers.CharField( + help_text="The identifier of the VNF lifecycle management operation occurrence associated to the GrantRequest.", + required=False, # TODO required + allow_null=True, + allow_blank=True + ) + vnfdId = serializers.CharField( + help_text="Identifier of the VNFD that defines the VNF for which the LCM operation is to be granted.", + required=False, # TODO required + allow_null=True, + allow_blank=True + ) + flavourId = serializers.CharField( + help_text="Identifier of the VNF deployment flavour of the VNFD that defines the VNF for which the LCM operation is to be granted.", + required=False, + allow_null=True, + allow_blank=True + ) + operation = serializers.ChoiceField( + help_text="The lifecycle management operation for which granting is requested.", + choices=["INSTANTIATE", "SCALE", "SCALE_TO_LEVEL", "CHANGE_FLAVOUR", "TERMINATE", "HEAL", "OPERATE", "CHANGE_EXT_CONN", "MODIFY_INFO"], + required=True + ) + isAutomaticInvocation = serializers.BooleanField( + help_text="Set to true if this VNF LCM operation occurrence has been triggered by an automated procedure inside the VNFM, set to false otherwise.", + required=True + ) + instantiationLevelId = serializers.CharField( + help_text="If operation=INSTANTIATE, the identifier of the instantiation level may be provided as an alternative way to define the resources to be added.", + required=False, + allow_null=True, + allow_blank=True + ) + addResources = ResourceDefinitionSerializer( + help_text="List of resource definitions in the VNFD for resources to be added by the LCM operation.", + many=True, + required=False + ) + tempResources = ResourceDefinitionSerializer( + help_text="List of resource definitions in the VNFD for resources to be temporarily instantiated during the runtime of the LCM operation.", + many=True, + required=False + ) + removeResources = ResourceDefinitionSerializer( + help_text="Provides the definitions of resources to be removed by the LCM operation.", + many=True, + required=False + ) + updateResources = ResourceDefinitionSerializer( + help_text="Provides the definitions of resources to be modified by the LCM operation.", + many=True, + required=False + ) + placementConstraints = PlacementConstraintSerializer( + help_text="Placement constraints that the VNFM may send to the NFVO in order to influence the resource placement decision.", + many=True, + required=False + ) + vimConstraints = VimConstraintSerializer( + help_text="Used by the VNFM to require that multiple resources are managed through the same VIM connection.", + many=True, + required=False + ) + additionalParams = serializers.DictField( + help_text="Additional parameters passed by the VNFM.", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True + ) + _links = GrantRequestLinksSerializer( + help_text="Links to resources related to this request.", + required=False # TODO required + ) diff --git a/gvnfmadapter/driver/interfaces/serializers/link.py b/gvnfmadapter/driver/interfaces/serializers/link.py new file mode 100644 index 0000000..1f54425 --- /dev/null +++ b/gvnfmadapter/driver/interfaces/serializers/link.py @@ -0,0 +1,22 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from rest_framework import serializers + + +class LinkSerializer(serializers.Serializer): + href = serializers.CharField( + help_text="URI of the referenced resource.", + required=True + ) diff --git a/gvnfmadapter/driver/interfaces/serializers/resource_handle.py b/gvnfmadapter/driver/interfaces/serializers/resource_handle.py new file mode 100644 index 0000000..689c8a9 --- /dev/null +++ b/gvnfmadapter/driver/interfaces/serializers/resource_handle.py @@ -0,0 +1,40 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from rest_framework import serializers + + +class ResourceHandleSerializer(serializers.Serializer): + vimConnectionId = serializers.CharField( + help_text="Identifier of the VIM connection to manage the resource.", + required=False, + allow_null=True, + allow_blank=True + ) + resourceProviderId = serializers.CharField( + help_text="Identifier of the entity responsible for the management of the resource.", + required=False, + allow_null=True, + allow_blank=True + ) + resourceId = serializers.CharField( + help_text="Identifier of the resource in the scope of the VIM or the resource provider.", + required=True + ) + vimLevelResourceType = serializers.CharField( + help_text="Type of the resource in the scope of the VIM or the resource provider.", + required=False, + allow_null=True, + allow_blank=True + ) diff --git a/gvnfmadapter/driver/interfaces/serializers/serializers.py b/gvnfmadapter/driver/interfaces/serializers/serializers.py new file mode 100644 index 0000000..4936d17 --- /dev/null +++ b/gvnfmadapter/driver/interfaces/serializers/serializers.py @@ -0,0 +1,601 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from driver.interfaces.serializers.link import LinkSerializer +from driver.interfaces.serializers.resource_handle import ResourceHandleSerializer + +from rest_framework import serializers + +LCM_OPERATION_TYPES = [ + "INSTANTIATE", + "SCALE", + "SCALE_TO_LEVEL", + "CHANGE_FLAVOUR", + "TERMINATE", + "HEAL", + "OPERATE", + "CHANGE_EXT_CONN", + "MODIFY_INFO" +] + + +LCM_OPERATION_STATE_TYPES = [ + "STARTING", + "PROCESSING", + "COMPLETED", + "FAILED_TEMP", + "FAILED", + "ROLLING_BACK", + "ROLLED_BACK" +] + + +VNFCS_CHANGE_TYPES = [ + "ADDED", + "REMOVED", + "MODIFIED", + "TEMPORARY" +] + + +STORAGES_CHANGE_TYPES = [ + "ADDED", + "REMOVED", + "MODIFIED", + "TEMPORARY" +] + + +VLS_CHANGE_TYPES = [ + "ADDED", + "REMOVED", + "MODIFIED", + "TEMPORARY", + "LINK_PORT_ADDED", + "LINK_PORT_REMOVED" +] + + +class AdditionalParams(serializers.Serializer): + sdncontroller = serializers.CharField(help_text="sdncontroller", required=False) + NatIpRange = serializers.CharField(help_text="NatIpRange", required=False) + m6000_mng_ip = serializers.CharField(help_text="m6000_mng_ip", required=False) + externalPluginManageNetworkName = serializers.CharField(help_text="externalPluginManageNetworkName", required=False) + location = serializers.CharField(help_text="location", required=False) + externalManageNetworkName = serializers.CharField(help_text="externalManageNetworkName", required=False) + sfc_data_network = serializers.CharField(help_text="sfc_data_network", required=False) + externalDataNetworkName = serializers.CharField(help_text="externalDataNetworkName", required=False) + inputs = serializers.DictField( + help_text="inputs", + child=serializers.CharField(help_text="but i needed to test these 2 fields somehow", allow_blank=True), + required=False, + allow_null=True + ) + + +class VnfInstReqParamsSerializer(serializers.Serializer): + vnfDescriptorId = serializers.CharField( + help_text="Identifier that identifies the VNFD which defines the VNF instance to be created.", + max_length=255, + required=True, + allow_null=True + ) + vnfInstanceName = serializers.CharField( + help_text="Human-readable name of the VNF instance to be created.", + max_length=255, + required=True, + allow_null=False + ) + vnfInstanceDescription = serializers.CharField( + help_text="Human-readable description of the VNF instance to be created.", + max_length=255, + required=False, + allow_null=True + ) + additionalParam = AdditionalParams( + help_text="Additional input parameters for the instantiation process," + " specific to the VNF being instantiated.", + required=True + ) + + +class ResponseSerializer(serializers.Serializer): + vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True) + jobId = serializers.CharField(help_text="Job ID.", required=True) + + +class VnfTermReqSerializer(serializers.Serializer): + vnfInstanceId = serializers.CharField( + help_text="VNF instance identifier.", + max_length=255, + required=True, + allow_null=True + ) + + +class VnfInfo(serializers.Serializer): + vnfInstanceId = serializers.CharField(help_text="VNF instance identifier.", required=True) + vnfStatus = serializers.CharField(help_text="The instantiation state of the VNF.", required=True) + version = serializers.CharField(help_text="Version of the VNF.", required=True) + + +class VnfQueryRespSerializer(serializers.Serializer): + vnfInfo = VnfInfo( + help_text="The information items about the selected VNF instance(s) that are returned.", + required=True + ) + + +class ResponseDescriptor(serializers.Serializer): + status = serializers.CharField(help_text="status.", required=True) + responsehistorylist = serializers.CharField(help_text="History response messages.", required=True) + responseid = serializers.IntegerField(help_text="Response identifier.", required=True) + errorcode = serializers.CharField(help_text="Errorcode.", required=True) + progress = serializers.IntegerField(help_text="Progress.", required=True) + statusdescription = serializers.CharField(help_text="Status description.", required=True) + + +class OperationStatusInfo(serializers.Serializer): + responsedescriptor = ResponseDescriptor(help_text="Response descriptor.", required=True) + jobid = serializers.CharField(help_text="Job ID.", required=True) + + +class VnfOperRespSerializer(serializers.Serializer): + operationStatusInfo = OperationStatusInfo( + help_text="Operation Status.", + required=True + ) + + +class VnfGrantReqSerializer(serializers.Serializer): + vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True) + nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True) + vimid = serializers.CharField(help_text="VIM identifier.", required=True) + exvimidlist = serializers.CharField(help_text="Extend VIM identifier list.", required=True) + tenant = serializers.CharField(help_text="Tenant name.", required=True) + vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True) + operationright = serializers.CharField(help_text="Operation right.", required=True) + vmlist = serializers.CharField(help_text="VM list.", required=True) + + +class VnfGrantRespSerializer(serializers.Serializer): + vimid = serializers.CharField(help_text="VIM identifier.", required=True) + tenant = serializers.CharField(help_text="Tenant name.", required=True) + + +class VnfNotifyReqSerializer(serializers.Serializer): + nfvoid = serializers.CharField(help_text="NFVO identifier.", required=True) + vnfmid = serializers.CharField(help_text="VNFM identifier.", required=True) + vimid = serializers.CharField(help_text="VIM identifier.", required=True) + timestamp = serializers.CharField(help_text="Timestamp.", required=True) + vnfistanceid = serializers.CharField(help_text="VNF instance identifier.", required=True) + eventtype = serializers.CharField(help_text="Event type.", required=True) + vmlist = serializers.CharField(help_text="VM list.", required=True) + + +class VimConnectionInfoSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="The identifier of the VIM Connection. This identifier is managed by the NFVO.", + max_length=255, + required=True, + allow_null=False, + allow_blank=False) + vimId = serializers.CharField( + help_text="The identifier of the VIM instance. This identifier is managed by the NFVO.", + max_length=255, + required=False, + allow_null=True, + allow_blank=True) + vimType = serializers.CharField( + help_text="Discriminator for the different types of the VIM information.", + max_length=255, + required=True, + allow_null=False, + allow_blank=False) + interfaceInfo = serializers.DictField( + help_text="Information about the interface or interfaces to the VIM", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True) + accessInfo = serializers.DictField( + help_text="Authentication credentials for accessing the VIM, and other access-related information", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True) + extra = serializers.DictField( + help_text="VIM type specific additional information. \ + The applicable structure, and whether or not this attribute is available, is dependent on the content of vimType.", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True) + + +class ProblemDetailsSerializer(serializers.Serializer): + type = serializers.CharField(help_text="Type", required=False, allow_null=True) + title = serializers.CharField(help_text="Title", required=False, allow_null=True) + status = serializers.IntegerField(help_text="Status", required=True) + detail = serializers.CharField(help_text="Detail", required=True, allow_null=True) + instance = serializers.CharField(help_text="Instance", required=False, allow_null=True) + additional_details = serializers.ListField( + help_text="Any number of additional attributes, as defined in a " + + "specification or by an implementation.", + required=False, + allow_null=True) + + +class ExtlinkPortInfoSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="Identifier of this link port as provided by the entity that has created the link port.", + max_length=255, + required=True, + allow_blank=False, + allow_null=False) + resourceHandle = ResourceHandleSerializer( + help_text="Reference to the virtualised resource realizing this link port.", + required=True, + allow_null=False) + id = serializers.CharField( + help_text="Identifier of the external CP of the VNF connected to this link port. \ + There shall be at most one link port associated with any external connection point instance.", + max_length=255, + required=False, + allow_blank=True, + allow_null=True) + + +class ExtVirtualLinkInfoSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="Identifier of the external VL and the related external VL information instance. \ + The identifier is assigned by the NFV-MANO entity that manages this VL instance.", + required=True, + max_length=255, + allow_null=False, + allow_blank=False) + resourceHandle = ResourceHandleSerializer( + help_text="Reference to the resource realizing this VL.", + required=True, + allow_null=False) + extlinkPorts = ExtlinkPortInfoSerializer( + help_text="Link ports of this VL.", + many=True, + required=False, + allow_null=True) + + +class VnfInfoModificationsSerializer(serializers.Serializer): + vnfInstanceName = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfInstanceName' attribute in 'VnfInstance'", + max_length=255, + required=False, + allow_null=True, + allow_blank=True) + vnfInstanceDescription = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfInstanceDescription' attribute in 'VnfInstance'", + required=False, + allow_null=True, + allow_blank=True) + vnfdId = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfdId' attribute in 'VnfInstance'", + max_length=255, + required=False, + allow_null=True, + allow_blank=True) + vnfProvider = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfProvider' attribute in 'VnfInstance'", + max_length=255, + required=False, + allow_null=True) + vnfProductName = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfProductName' attribute in 'vnfInstance'", + max_length=255, + required=False, + allow_null=True, + allow_blank=True) + vnfSoftwareVersion = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfSoftwareVersion' attribute in 'VnfInstance'.", + max_length=255, + required=False, + allow_null=True, + allow_blank=True) + vnfdVersion = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfdVersion' attribute in 'VnfInstance'. ", + max_length=255, + required=False, + allow_null=True, + allow_blank=False) + vnfPkgId = serializers.CharField( + help_text="If present, this attribute signals modifications of the " + + "'vnfPkgId' attribute in 'VnfInstance'.", + max_length=255, + required=False, + allow_null=True, + allow_blank=False) + vnfConfigurableProperties = serializers.DictField( + help_text="If present, this attribute signals modifications of the " + + "'vnfConfigurableProperties' attribute in 'VnfInstance'. ", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True,) + vimConnectionInfo = VimConnectionInfoSerializer( + help_text="If present, this attribute signals modifications of certain" + + "entries in the 'vimConnectionInfo'", + required=False, + many=True, + allow_null=True) + metadata = serializers.DictField( + help_text="If present, this attribute signals modifications of certain" + + "'metadata' attribute in 'vnfInstance'.", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True) + extensions = serializers.DictField( + help_text="If present, this attribute signals modifications of certain" + + "'extensions' attribute in 'vnfInstance'.", + child=serializers.CharField(help_text="KeyValue Pairs", allow_blank=True), + required=False, + allow_null=True) + + +class LcmOpLinkSerializer(serializers.Serializer): + self = LinkSerializer( + help_text="URI of this resource.", + required=True, + allow_null=False) + vnfInstance = serializers.CharField( + help_text="Link to the VNF instance that the operation applies to.", + required=True) + grant = serializers.CharField( + help_text="Link to the grant for this operation, if one exists.", + required=False) + cancel = serializers.CharField( + help_text="Link to the task resource that represents the 'cancel' " + + "operation for this VNF LCM operation occurrence.", + required=False) + retry = serializers.CharField( + help_text="Link to the task resource that represents the 'retry' " + + "operation for this VNF LCM operation occurrence, if" + + " retrying is currently allowed", + required=False) + rollback = serializers.CharField( + help_text="Link to the task resource that represents the 'cancel' " + + "operation for this VNF LCM operation occurrence.", + required=False) + fail = serializers.CharField( + help_text="Link to the task resource that represents the 'fail' " + + "operation for this VNF LCM operation occurrence.", + required=False) + + +class AffectedVnfcsSerializer(serializers.Serializer): + id = serializers.UUIDField( + help_text="Identifier of the Vnfc instance, identifying the " + + "applicable 'vnfcResourceInfo' entry in the 'VnfInstance' data type", + required=True + ) + vduId = serializers.UUIDField( + help_text="Identifier of the related VDU in the VNFD.", + required=True + ) + changeType = serializers.ChoiceField( + help_text="Signals the type of change", + required=True, + choices=VNFCS_CHANGE_TYPES + ) + affectedVnfcCpIds = serializers.ListField( + help_text="Identifiers of CP(s) of the VNFC instance that " + + "were affected by the change", + required=False, + child=serializers.UUIDField(required=True) + ) + addedStorageResourceIds = serializers.ListField( + help_text="References to VirtualStorage resources that " + + "have been added", + required=False, + child=serializers.UUIDField() + ) + removedStorageResourceIds = serializers.ListField( + help_text="References to VirtualStorage resources that " + + "have been removed.", + required=False, + child=serializers.UUIDField() + ) + metadata = serializers.DictField( + help_text="Metadata about this resource. ", + required=False, + allow_null=True) + computeResource = ResourceHandleSerializer( + help_text="Reference to the VirtualCompute resource.", + required=True, + allow_null=False) + + +class AffectedStoragesSerializer(serializers.Serializer): + id = serializers.UUIDField( + help_text="Identifier of the Storage instance, identifying the " + + "applicable 'virtualStorageResourceInfo' entry in the 'VnfInstance' data type", + required=True + ) + virtualStorageDescId = serializers.UUIDField( + help_text="Identifier of the related VirtualStorage descriptor " + + "in the VNFD. ", + required=True + ) + changeType = serializers.ChoiceField( + help_text="Signals the type of change", + required=True, + choices=STORAGES_CHANGE_TYPES + ) + metadata = serializers.DictField( + help_text="Metadata about this resource. ", + required=False, + allow_null=True) + storageResource = ResourceHandleSerializer( + help_text="Reference to the VirtualStorage resource.", + required=True, + allow_null=False) + + +class AffectedVLsSerializer(serializers.Serializer): + id = serializers.UUIDField( + help_text="Identifier of the virtual link instance, identifying " + + "the applicable 'vnfVirtualLinkResourceInfo' ", + required=True + ) + virtualLinkDescId = serializers.UUIDField( + help_text="Identifier of the related VLD in the VNFD.", + required=True + ) + changeType = serializers.ChoiceField( + help_text="Signals the type of change", + required=True, + choices=VLS_CHANGE_TYPES + ) + metadata = serializers.DictField( + help_text="Metadata about this resource. ", + required=False, + allow_null=True) + networkResource = ResourceHandleSerializer( + help_text="Reference to the VirtualNetwork resource.", + required=True, + allow_null=False) + + +class ResourceChangesSerializer(serializers.Serializer): + affectedVnfcs = AffectedVnfcsSerializer( + help_text="Information about VNFC instances that were affected " + + "during the lifecycle operation.", + required=False, + many=True + ) + affectedVirtualLinks = AffectedVLsSerializer( + help_text="Information about VL instances that were affected " + + "during the lifecycle operation. ", + required=False, + many=True + ) + affectedVirtualStorages = AffectedStoragesSerializer( + help_text="Information about virtualised storage instances that " + + "were affected during the lifecycle operation", + required=False, + many=True + ) + + +class VNFLCMOpOccSerializer(serializers.Serializer): + id = serializers.CharField( + help_text="Identifier of this VNF lifecycle management operation" + + "occurrence,", + max_length=255, + required=True, + allow_null=False + ) + operationState = serializers.ChoiceField( + help_text="The state of the VNF LCM operation occurrence. ", + required=True, + choices=LCM_OPERATION_STATE_TYPES + ) + stateEnteredTime = serializers.CharField( + help_text="Date-time when the current state was entered.", + max_length=50 + ) + startTime = serializers.CharField( + help_text="Date-time of the start of the operation.", + max_length=50 + ) + vnfInstanceId = serializers.UUIDField( + help_text="Identifier of the VNF instance to which the operation" + + "applies" + ) + grantId = serializers.UUIDField( + help_text="Identifier of the grant related to this VNF LCM operation " + + "occurrence, if such grant exists.", + allow_null=True + ) + operation = serializers.ChoiceField( + help_text="The lifecycle management operation", + required=True, + choices=LCM_OPERATION_TYPES + ) + isAutomaticInvocation = serializers.BooleanField( + help_text="Set to true if this VNF LCM operation occurrence has " + + "been triggered by an automated procedure inside the VNFM. " + + "Set to False otherwise.", + default=False + ) + operationParams = serializers.DictField( + help_text="Input parameters of the LCM operation. This attribute " + + "shall be formatted according to the request data type of the " + + "related LCM operation. The following mapping between operationType and the " + + "data type of this attribute shall apply: " + + "1. INSTANTIATE: InstantiateVnfRequest" + + "2. SCALE: ScaleVnfRequest " + + "3. SCALE_TO_LEVEL: ScaleVnfToLevelRequest " + + "4. CHANGE_FLAVOUR: ChangeVnfFlavourRequest " + + "5. OPERATE: OperateVnfRequest " + + "6. HEAL: HealVnfRequest " + + "7. CHANGE_EXT_CONN: ChangeExtVnfConnectivityRequest " + + "8. TERMINATE: TerminateVnfRequest " + + "9. MODIFY_INFO: VnfInfoModifications", + required=True, + allow_null=False + ) + isCancelPending = serializers.BooleanField( + help_text="If the VNF LCM operation occurrence is in 'STARTING'" + + "'PROCESSING' or 'ROLLING_BACK' state and the operation is being" + + " cancelled, this attribute shall be set to True. Otherwise, " + + " it shall be set to False.", + required=True + ) + cancelMode = serializers.CharField( + help_text="The mode of an ongoing cancellation. Shall be present " + + "when isCancelPending=true, and shall be None otherwise.", + allow_null=True, + required=False + ) + error = ProblemDetailsSerializer( + help_text="If 'operationState' is 'FAILED_TEMP' or 'FAILED' or " + + "'PROCESSING' or 'ROLLING_BACK' and previous value of 'operationState' " + + "was 'FAILED_TEMP' this attribute shall be present ", + allow_null=True, + required=False + ) + resourceChanges = ResourceChangesSerializer( + help_text="It contains information about the cumulative changes " + + "to virtualised resources that were performed so far by the LCM " + + "operation since its start, if applicable.", + required=False, + allow_null=True) + changedInfo = VnfInfoModificationsSerializer( + help_text="Information about the changed VNF instance information, " + + "including VNF configurable properties", + required=False, + allow_null=True) + changedExtConnectivity = ExtVirtualLinkInfoSerializer( + help_text="Information about changed external connectivity, if this " + + "notification represents the result of a lifecycle operation occurrence. " + + "Shall be present if the 'notificationStatus' is set to 'RESULT' and the " + + "'operation' is set to 'CHANGE_EXT_CONN'. Shall be absent otherwise.", + many=True, + required=False, + allow_null=True) + _links = LcmOpLinkSerializer( + help_text="Links to resources related to this resource.", + required=True) diff --git a/gvnfmadapter/driver/interfaces/tests.py b/gvnfmadapter/driver/interfaces/tests.py index 2e73623..9c50466 100644 --- a/gvnfmadapter/driver/interfaces/tests.py +++ b/gvnfmadapter/driver/interfaces/tests.py @@ -286,31 +286,60 @@ class InterfacesTest(TestCase): } } } - grant_resp_data = { - "id": "1", - "vnfInstanceId": "1", - "vnfLcmOpOccId": "2", - "vimConnections": [ - { - "id": "1", - "vimId": "1" - } - ] + grant = { + 'id': 'Identifier of the garnt', + 'vnfInstanceId': 'Identifier of the related VNF instance', + 'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc', + # NOT REQUIERD # + # 'vimConnections': [], + # 'zones': [], + # 'zoneGroups': [], + # 'computeReservationId': None, + # 'networkReservationId': None, + # 'storageReservationId': None, + # 'addResources': None, + # 'tempResources': None, + # 'removeResource': None, + # 'updateResource': None, + # 'vimAssets': None, + # 'extVirtualLinks': None, + # 'extManagedVirtualLinks': None, + # 'additionalParams': None, + '_links': { + 'self': {'href': 'URI of this resource'}, + 'vnfLcmOpOcc': {'href': 'Related VNF lifecycle management operation occurrence'}, + 'vnfInstance': {'href': 'Related VNF instance'} + } } - mock_call_req.return_value = [0, json.JSONEncoder().encode(grant_resp_data), '201'] + + mock_call_req.return_value = [0, json.JSONEncoder().encode(grant), '201'] response = self.client.put("/api/gvnfmdriver/v1/resource/grant", data=json.dumps(data), content_type='application/json') self.assertEqual(status.HTTP_201_CREATED, response.status_code) expect_resp_data = { - "id": "1", - "vnfInstanceId": "1", - "vnfLcmOpOccId": "2", - "vimConnections": [ - { - "id": "1", - "vimId": "1" - } - ] + 'id': 'Identifier of the garnt', + 'vnfInstanceId': 'Identifier of the related VNF instance', + 'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc', + # NOT REQUIERD # + # 'vimConnections': [], + # 'zones': [], + # 'zoneGroups': [], + # 'computeReservationId': None, + # 'networkReservationId': None, + # 'storageReservationId': None, + # 'addResources': None, + # 'tempResources': None, + # 'removeResource': None, + # 'updateResource': None, + # 'vimAssets': None, + # 'extVirtualLinks': None, + # 'extManagedVirtualLinks': None, + # 'additionalParams': None, + '_links': { + 'self': {'href': 'URI of this resource'}, + 'vnfLcmOpOcc': {'href': 'Related VNF lifecycle management operation occurrence'}, + 'vnfInstance': {'href': 'Related VNF instance'} + } } self.assertDictEqual(expect_resp_data, response.data) @@ -538,3 +567,69 @@ class InterfacesTest(TestCase): mock_call_req.return_value = [1, json.JSONEncoder().encode(""), '200'] resp = self.client.get("/api/gvnfmdriver/v1/vnfpackages") self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, resp.status_code) + + @mock.patch.object(restcall, 'call_req') + def test_get_vnflcmopocc_with_id(self, mock_call_req): + vnfLcmOpOccId = "99442b18-a5c7-11e8-998c-bf1755941f16" + vnfm_info = { + "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", + "name": "g_vnfm", + "type": "gvnfmdriver", + "vimId": "", + "vendor": "ZTE", + "version": "v1.0", + "description": "vnfm", + "certificateUrl": "", + "url": "http://10.74.44.11", + "userName": "admin", + "password": "admin", + "createTime": "2016-07-06 15:33:18" + } + dummy_single_vnf_lcm_op = { + "id": vnfLcmOpOccId, + "operationState": "STARTING", + "stateEnteredTime": "2018-07-09", + "startTime": "2018-07-09", + "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", + "grantId": None, + "operation": "SCALE", + "isAutomaticInvocation": False, + "operationParams": {}, + "isCancelPending": False, + "cancelMode": None, + "error": None, + "resourceChanges": None, + "changedInfo": None, + "changedExtConnectivity": None, + "_links": { + "self": { + "href": "dem1o" + }, + "vnfInstance": "demo" + } + } + mock_call_req.return_value = [0, json.JSONEncoder().encode(dummy_single_vnf_lcm_op), status.HTTP_200_OK] + resp = self.client.get("/api/gvnfmdriver/v1/%s/vnf_lcm_op_occs/%s" % (vnfm_info['vnfmId'], vnfLcmOpOccId)) + self.assertEqual(dummy_single_vnf_lcm_op, resp.data) + self.assertEqual(status.HTTP_200_OK, resp.status_code) + + @mock.patch.object(restcall, 'call_req') + def test_get_vnflcmopocc_failed(self, mock_call_req): + vnfLcmOpOccId = "99442b18-a5c7-11e8-998c-bf1755941f16" + vnfm_info = { + "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", + "name": "g_vnfm", + "type": "gvnfmdriver", + "vimId": "", + "vendor": "ZTE", + "version": "v1.0", + "description": "vnfm", + "certificateUrl": "", + "url": "http://10.74.44.11", + "userName": "admin", + "password": "admin", + "createTime": "2016-07-06 15:33:18" + } + mock_call_req.return_value = [1, json.JSONEncoder().encode({}), status.HTTP_500_INTERNAL_SERVER_ERROR] + resp = self.client.get("/api/gvnfmdriver/v1/%s/vnf_lcm_op_occs/%s" % (vnfm_info['vnfmId'], vnfLcmOpOccId)) + self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, resp.status_code) diff --git a/gvnfmadapter/driver/interfaces/urls.py b/gvnfmadapter/driver/interfaces/urls.py index 446e3fa..6adb6f9 100644 --- a/gvnfmadapter/driver/interfaces/urls.py +++ b/gvnfmadapter/driver/interfaces/urls.py @@ -14,7 +14,7 @@ from django.conf.urls import url from driver.interfaces.views import VnfInstInfo, VnfTermInfo, VnfQueryInfo, VnfOperInfo -from driver.interfaces.views import VnfPkgsInfo, VnfGrantInfo, VnfNotifyInfo +from driver.interfaces.views import VnfPkgsInfo, VnfGrantInfo, VnfNotifyInfo, QuerySingleVnfLcmOpOcc urlpatterns = [ url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs$', VnfInstInfo.as_view()), @@ -27,5 +27,7 @@ urlpatterns = [ url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfpackages$', VnfPkgsInfo.as_view()), url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/resource/grant$', VnfGrantInfo.as_view()), url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfs/lifecyclechangesnotification$', - VnfNotifyInfo.as_view()) + VnfNotifyInfo.as_view()), + url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnf_lcm_op_occs/(?P<lcmopoccid>[0-9a-zA-Z_-]+)$', + QuerySingleVnfLcmOpOcc.as_view()), ] diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py index e3c107f..362fe12 100644 --- a/gvnfmadapter/driver/interfaces/views.py +++ b/gvnfmadapter/driver/interfaces/views.py @@ -23,13 +23,15 @@ from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView +from driver.interfaces.serializers.serializers import VnfInstReqParamsSerializer, ResponseSerializer +from driver.interfaces.serializers.serializers import VnfNotifyReqSerializer, VNFLCMOpOccSerializer +from driver.interfaces.serializers.serializers import VnfOperRespSerializer +from driver.interfaces.serializers.serializers import VnfTermReqSerializer, VnfQueryRespSerializer +from driver.interfaces.serializers.grant_request import GrantRequestSerializer +from driver.interfaces.serializers.grant import GrantSerializer from driver.pub.exceptions import GvnfmDriverException from driver.pub.utils import restcall from driver.pub.utils.restcall import req_by_msb -from driver.interfaces.serializers import VnfInstReqParamsSerializer, ResponseSerializer -from driver.interfaces.serializers import VnfTermReqSerializer, VnfQueryRespSerializer -from driver.interfaces.serializers import VnfOperRespSerializer, VnfGrantReqSerializer, VnfGrantRespSerializer -from driver.interfaces.serializers import VnfNotifyReqSerializer logger = logging.getLogger(__name__) @@ -233,9 +235,9 @@ class VnfOperInfo(APIView): class VnfGrantInfo(APIView): @swagger_auto_schema( - request_body=VnfGrantReqSerializer(), + request_body=GrantRequestSerializer(), # TODO: not used responses={ - status.HTTP_201_CREATED: VnfGrantRespSerializer(), + status.HTTP_201_CREATED: GrantSerializer(), status.HTTP_404_NOT_FOUND: "The request body is wrong", status.HTTP_500_INTERNAL_SERVER_ERROR: "The url is invalid" } @@ -243,12 +245,18 @@ class VnfGrantInfo(APIView): def put(self, request, vnfmtype): try: logger.debug("[grantvnf] req_data = %s", request.data) + grant_request = GrantRequestSerializer(data=request.data) + if not grant_request.is_valid(): + raise GvnfmDriverException(grant_request.error_messages) ret = req_by_msb('api/nslcm/v2/grants', "POST", content=json.JSONEncoder().encode(request.data)) logger.debug("ret = %s", ret) if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise GvnfmDriverException('Failed to grant vnf.') resp = json.JSONDecoder().decode(ret[1]) + grant = GrantSerializer(data=resp) + if not grant.is_valid(): + raise GvnfmDriverException(grant.error_messages) logger.debug("[%s]resp_data=%s", fun_name(), resp) return Response(data=resp, status=status.HTTP_201_CREATED) except GvnfmDriverException as e: @@ -268,7 +276,7 @@ class VnfNotifyInfo(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: "The url is invalid" } ) - def post(self, request, vnfmtype): + def post(self, request, vnfmtype): # TODO: not compatable with VnfIdentifierCreationNotification and VnfIdentifierDeletionNotification try: logger.debug("[%s]req_data = %s", fun_name(), request.data) vnfminstid = ignorcase_get(request.data, 'vnfmInstId') @@ -306,6 +314,36 @@ class VnfPkgsInfo(APIView): logger.error(traceback.format_exc()) return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) +class QuerySingleVnfLcmOpOcc(APIView): + @swagger_auto_schema( + responses={ + status.HTTP_200_OK: VNFLCMOpOccSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "" + } + ) + def get(self, request, vnfmtype, vnfmid, lcmopoccid): + logger.debug("[%s]LCMOpOccId = %s", fun_name(), lcmopoccid) + try: + vnfm_info = get_vnfminfo_from_nslcm(vnfmid) + logger.debug("[get lcm op occ] vnfm_info=[%s]", vnfm_info) + ret = call_vnfm("api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcmopoccid, "GET", vnfm_info) + if ret[0] != 0: + logger.error("Status code is %s. detail is %s.", ret[2], ret[1]) + raise GvnfmDriverException("Failed to query vnf lcm op occ %s" % lcmopoccid) + resp_data = json.JSONDecoder().decode(ret[1]) + vnf_lcm_op_occ_serializer = VNFLCMOpOccSerializer(data=resp_data) + if vnf_lcm_op_occ_serializer.is_valid(): + logger.debug("[%s]resp_data=%s" % (fun_name(), resp_data)) + return Response(data=vnf_lcm_op_occ_serializer.data, status=status.HTTP_200_OK) + else: + raise GvnfmDriverException(vnf_lcm_op_occ_serializer.errors) + except GvnfmDriverException as e: + logger.error("Query vnflcmopocc failed, detail message: %s" % e.message) + return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except: + logger.error(traceback.format_exc()) + return Response(data={'error': traceback.format_exc()}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + def call_vnfm(resource, method, vnfm_info, data=""): ret = restcall.call_req( diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java index 3a8bc5c..7a178ca 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java @@ -45,6 +45,7 @@ public class FileUtils { public static final String GBK = "GBK"; private static Logger log = LoggerFactory.getLogger(FileUtils.class); + private static final String OS_NAME = "os.name"; private FileUtils(){ @@ -342,7 +343,7 @@ public class FileUtils { * */ public static boolean isWindows() { - String os = System.getProperty("os.name").toLowerCase(); + String os = System.getProperty(OS_NAME).toLowerCase(); // windows return (os.indexOf("win") >= 0); @@ -394,7 +395,7 @@ public class FileUtils { * */ public static boolean isMac() { - String os = System.getProperty("os.name").toLowerCase(); + String os = System.getProperty(OS_NAME).toLowerCase(); // Mac return (os.indexOf("mac") >= 0); @@ -407,7 +408,7 @@ public class FileUtils { * */ public static boolean isUnix() { - String os = System.getProperty("os.name").toLowerCase(); + String os = System.getProperty(OS_NAME).toLowerCase(); // linux or unix return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0); diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfResourceMgr.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfResourceMgr.java index d0a1f01..80d24d3 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfResourceMgr.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfResourceMgr.java @@ -211,8 +211,7 @@ public class VnfResourceMgr { if(vnfmInfo != null && StringUtils.isNotBlank(vnfmInfo.getExtend())){ JSONObject json = JSONObject.fromObject(vnfmInfo.getExtend()); JSONObject extVirtualLinkLink = json.getJSONArray("extVirtualLinks").getJSONObject(0); - String vimId = extVirtualLinkLink.getJSONObject("vim").getString("vimid"); - return vimId; + return extVirtualLinkLink.getJSONObject("vim").getString("vimid"); } } catch(Exception e) { LOG.error("vnfmInfo.getExtend() format error!please check it",e); |