aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2018-01-31 14:38:05 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2018-01-31 14:54:18 +0800
commit52da36dd6ed776b1e836dbe4153f596f77fc3c0d (patch)
treefc05bab7501655d5c1dfd9580e9e567520bcd479
parentefa6ec32c10b6a85552cc70bfb0fd38b4da1006d (diff)
Refactor get sfc swagger generate logic
Change-Id: Ie93a29f031e6797d030547dd72f861a1879df73d Issue-ID: VFC-694 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/ns/sfcs/detail_views.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/lcm/ns/sfcs/detail_views.py b/lcm/ns/sfcs/detail_views.py
index b5646f5f..dfbed985 100644
--- a/lcm/ns/sfcs/detail_views.py
+++ b/lcm/ns/sfcs/detail_views.py
@@ -11,24 +11,46 @@
# 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()