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