예제 #1
0
def instance_detail_view(request, pk):
    tag = request.GET.get("tag", 'instance_detail')
    try:
        instance = Instance.objects.get(pk=pk, user=request.user)
    except Exception as e:
        LOG.error("Get instance error, msg:%s" % e)
        return Response({"OPERATION_STATUS": 0, "MSG": "Instance no exist"}, status=status.HTTP_200_OK)

    if "instance_detail" == tag:
        instance_data = dict(InstanceSerializer(instance).data)

        try:
            server = instance_get(instance)
            instance_data['host'] = getattr(server, 'OS-EXT-SRV-ATTR:host', None)
            instance_data['instance_name'] = getattr(server, 'OS-EXT-SRV-ATTR:instance_name', None)
        except Exception as e:
            LOG.error("Obtain host fail,msg: %s" % e)

        try:
            firewall = Firewall.objects.get(pk=instance.firewall_group.id)
            firewall_data = FirewallSerializer(firewall).data
            instance_data['firewall'] = firewall_data
        except Exception as e:
            LOG.exception("Obtain firewall fail, msg:%s" % e)

        # 挂载的所有硬盘
        volume_set = Volume.objects.filter(instance=instance, deleted=False)
        volume_data = VolumeSerializer(volume_set, many=True).data
        instance_data['volume_list'] = volume_data
        return Response(instance_data)
    elif 'instance_log' == tag:
        log_data = instance_get_console_log(instance)
        return Response(log_data)
예제 #2
0
def instance_detail_view(request, pk):
    tag = request.GET.get("tag", 'instance_detail')
    try:
        instance = Instance.objects.get(pk=pk, user=request.user)
    except Exception as e:
        LOG.error("Get instance error, msg:%s" % e)
        return Response({"OPERATION_STATUS": 0, "MSG": "Instance no exist"}, status=status.HTTP_200_OK)

    if "instance_detail" == tag:
        return _get_instance_detail(instance)
    elif 'instance_log' == tag:
        log_data = instance_get_console_log(instance)
        return Response(log_data)