コード例 #1
0
def template_constraints(request, template_id):
	t = get_template(template_id)
	te_list = []
	if t:
		try:
			for index, te in enumerate(t["terms"]["allTerms"]["guaranteeTerms"]):
				cns = json.loads(te["serviceLevelObjetive"]["kpitarget"]["customServiceLevel"])["constraint"].split(" ")
				cns_name = t["terms"]["allTerms"]["serviceProperties"][0]["variableSet"]["variables"][index]["name"]
				kpiName = te["serviceLevelObjetive"]["kpitarget"]["kpiName"]
				te_item = {
					"t_name": t["name"],
					"t_time": t["context"]["expirationTime"],
					"service": t["context"]["service"],
					"provider": t["context"]["agreementInitiator"],
					"cns": cns[1],
					"cns_val": cns[2],
					"cns_name": guiformatter.humanReadableMetric(cns_name),
					"kpiName": guiformatter.humanReadableMetric(kpiName, True)
					}
				
				if "policy" in te["serviceLevelObjetive"]["kpitarget"]["customServiceLevel"]:
					policyValue = json.loads(te["serviceLevelObjetive"]["kpitarget"]["customServiceLevel"])["policy"];
					te_item["policy"] = guiformatter.getIntervalFromPolicy(policyValue)
				else:
					te_item["policy"] = ""
				
				te_list.append(te_item)
			print json.dumps(te_list)
		except:
			return HttpResponse(json.dumps([]), content_type="application/json")
	return HttpResponse(json.dumps(te_list), content_type="application/json")
コード例 #2
0
def get_measurements(request):
	service_param = request.GET.get('service');
	kind_service = re.search("^(.+)\|.*$", service_param).group(1)
	service_id = re.search("^.+:(.+)$", service_param).group(1)
	
	org_name = str(request.session.get("current_organization")['name'])
	measurements_cache_id = 'measurements' + service_id 
	measurements = []
	if cache.get(measurements_cache_id):
		measurements = cache.get(measurements_cache_id)
	else:
		fm = FMAdapter()
		node = re.search("^.+\|(.+):.*$", service_param).group(1)
			
		if kind_service == u"host" :
			url = fm.dca_request_url.replace('NODE', node) + "/"+ service_id
		else:
			url = fm.vm_request_url.replace('NODE', node) + service_id
		
		credentials = None
		info = fm.do_fm_request( url, credentials, True, fm.FM)
			
		if 'measures' in info:
			for measure_dict in info['measures']:
				for measure in measure_dict.keys():
					if measure not in ['timestamp', 'hostName']:
						measurements.append((measure, guiformatter.humanReadableMetric(measure, True)))
			orderMeasurementsPerName(measurements)
		else:
			print('No services found for ' + url)
			
		cache.set(measurements_cache_id, measurements, 60 * 30)
	return HttpResponse(json.dumps(measurements), content_type="application/json")