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)
def _get_instance_detail(instance): instance_data = 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) instance_data['fault'] = getattr(server, 'fault', 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)
def _get_instance_detail(instance): instance_data = 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) instance_data['fault'] = getattr(server, 'fault', 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)
def qos_get_instance_detail(instance): instance_data = 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: ports = instance_get_port(instance) if ports: instance_data['port'] = ports[0].port_id else: instance_data['port'] = False except Exception as e: LOG.error("Obtain instance port fail,msg: %s" % e) try: from biz.floating.models import Floating floating = Floating.get_instance_ip(instance.id) if floating: instance_data["bandwidth"] = floating.bandwidth else: instance_data["bandwidth"] = settings.DEFAULT_BANDWIDTH except Exception as e: LOG.error("Obtain instance bandwidth fail,msg: %s" % e) return instance_data
def qos_get_instance_detail(instance): instance_data = 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: ports = instance_get_port(instance) if ports: instance_data['port'] = ports[0].port_id else: instance_data['port'] = False except Exception as e: LOG.error("Obtain instance port fail,msg: %s" % e) try: from biz.floating.models import Floating floating = Floating.get_instance_ip(instance.id) if floating: instance_data["bandwidth"] = floating.bandwidth else: instance_data["bandwidth"] = settings.DEFAULT_BANDWIDTH except Exception as e: LOG.error("Obtain instance bandwidth fail,msg: %s" % e) return instance_data