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")
def convert_paas_id_to_node(paas_list): p_list= [] if paas_list: fm = FMAdapter() credentials = None url = settings.FM_VM_URL for p in paas_list: if p['status']!='P_DELETED': try: url2 = url.replace('NODE', p['region']) + str(p['id']) hostNameValue = None try: host_name = fm.do_fm_request(url2, credentials, True, fm.FM) if host_name['measures']: hostNameValue = host_name['measures'][0]['hostName']['value'] except Exception, e: print("Error when calling the FM") hostNameValue ="" p = {'node': hostNameValue, 'region': p['region'], 'name': p['name'] } p_list.append(p) except Exception, e: print("Error parsing PaaS instances" +e.args)
def get_agreement_paas(cloudId): agreement_paas = 'agreement_paas'+cloudId if cache.get(agreement_paas): p_list = cache.get(agreement_paas) return p_list else: url = settings.DCA_PAAS_URL + cloudId #credentials = '{"auth": {"passwordCredentials": {"username":"******", "password":"******"}}}' #To be reviewed credentials = None fm = FMAdapter() paas_list = fm.do_fm_request(url, credentials, True, fm.DCA) p_list = convert_paas_id_to_node(paas_list) cache.set(agreement_paas, p_list, 60 * 30) return p_list
def get_template_paas(request): org_name = str(request.session.get("current_organization")['name']) template_paas = 'template_paas' + org_name p_list = [] if cache.get(template_paas): p_list = cache.get(template_paas) else: fm = FMAdapter() if org_name in fm.org_node_list: node = fm.org_node_list[org_name] url = fm.dca_request_url.replace('NODE', node) credentials = None paas_list = fm.do_fm_request( url, credentials, True, fm.FM) if paas_list: for paas in paas_list['hosts']: if 'None' != str(paas['id']): p = {'id': paas['id'], 'node': node} p_list.append(p) else: print('No Paas found..') cache.set(template_paas, p_list, 60 * 30) return p_list