Refactor get sfc swagger generate logic 55/29755/2
authorfujinhua <fu.jinhua@zte.com.cn>
Wed, 31 Jan 2018 06:38:05 +0000 (14:38 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Wed, 31 Jan 2018 06:54:18 +0000 (14:54 +0800)
Change-Id: Ie93a29f031e6797d030547dd72f861a1879df73d
Issue-ID: VFC-694
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/ns/sfcs/detail_views.py

index b5646f5..dfbed98 100644 (file)
 # 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.
+import logging
 
 from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
+from drf_yasg.utils import swagger_auto_schema
 
 from lcm.ns.sfcs.delete_sfcs import DeleteSfcs
 from lcm.ns.sfcs.get_sfcs import GetSfcs
+from lcm.ns.sfcs.serializers import GetSfcRespSerializer
+
+logger = logging.getLogger(__name__)
 
 
 class SfcDetailView(APIView):
+    @swagger_auto_schema(
+        request_body=None,
+        responses={
+            status.HTTP_200_OK: GetSfcRespSerializer(),
+            status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error",
+            status.HTTP_404_NOT_FOUND: "SFC not found"
+        }
+    )
     def get(self, request, sfc_inst_id):
-        print "SfcCreateView--get::> %s" % sfc_inst_id
+        logger.debug("SfcCreateView--get::> %s", sfc_inst_id)
         sfc_inst_info = GetSfcs(sfc_inst_id).do()
         if not sfc_inst_info:
             return Response(status=status.HTTP_404_NOT_FOUND)
-        return Response(status=status.HTTP_200_OK, data={'sfcInstId': sfc_inst_id,
-                                                         'sfcName': "xxx",
-                                                         'sfcStatus': sfc_inst_info[0].status})
+
+        resp_data = {'sfcInstId': sfc_inst_id,
+                     'sfcName': "xxx",
+                     'sfcStatus': sfc_inst_info[0].status}
+
+        resp_serializer = GetSfcRespSerializer(data=resp_data)
+        if not resp_serializer.is_valid():
+            logger.error(resp_serializer.errors)
+            return Response(data={'error': resp_serializer.errors},
+                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+        return Response(status=status.HTTP_200_OK, data=resp_serializer.data)
 
     def delete(self, request_paras, sfc_inst_id):
         resp = DeleteSfcs(sfc_inst_id).do()