Пример #1
0
def create_data_center(request):
    try:
        serializer = DataCenterSerializer(data=request.data,
                                          context={"request": request})
        if serializer.is_valid():
            serializer.save()
            return Response(
                {
                    'success': True,
                    "msg": _('Data Center is created successfully!')
                },
                status=status.HTTP_201_CREATED)
        else:
            return Response(
                {
                    "success": False,
                    "msg": _('Data Center data is not valid!'),
                    'errors': serializer.errors
                },
                status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        LOG.error("Failed to create data center, msg:[%s]" % e)
        return Response({
            "success":
            False,
            "msg":
            _('Failed to create data center for unknown reason.')
        })
Пример #2
0
def init_data_center(request):

    params = {'name': request.data['name']}

    for key in ('host', 'project', 'user', 'password', 'auth_url', 'ext_net'):
        params[key] = request.data[key]

    try:
        data_center = DataCenter.objects.create(**params)
    except IntegrityError:
        return Response(
            {
                'success':
                False,
                "msg":
                _('The host IP is used by other Data Center, Please check your host IP.'
                  )
            },
            status=status.HTTP_200_OK)
    except Exception as e:
        LOG.error("Failed to create data center, msg:[%s]" % e)
        return Response(
            {
                'success': False,
                "msg": _("Unknown Error happened when creating data center!"),
                "resouce": "data_center"
            },
            status=status.HTTP_200_OK)
    else:
        return Response({
            "success": True,
            'data': DataCenterSerializer(data_center).data,
            "msg": _("Data center is initialized successfully!")
        })
Пример #3
0
def create_data_center(request):
    try:
        serializer = DataCenterSerializer(data=request.data, context={"request": request})
        if serializer.is_valid():
            serializer.save()
            return Response({'success': True,
                             "msg": _('Data Center is created successfully!')},
                            status=status.HTTP_201_CREATED)
        else:
            return Response({"success": False,
                             "msg": _('Data Center data is not valid!'),
                             'errors': serializer.errors},
                            status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        LOG.error("Failed to create data center, msg:[%s]" % e)
        return Response({"success": False, "msg": _('Failed to create data center for unknown reason.')})