Esempio n. 1
0
    def POST(self, *args):
        if not cache_valid(self.cache_time):
            print 'not cache'
            web.http.expires(timedelta(days=1))
            request_data = eval(web.data())['request']
            request_type = utils.s(request_data['type'])
            response = utils.generate_response_header(request_data)

            if request_type == 'get_all_service':
                try:
                    services = model_ora.get_service()
                    result = []
                    for item in services:
                        tmp = {'service_name': item}
                        result.append(tmp)
                    response.update({
                        'data': result,
                        'result': 'success'
                    })
                except Exception, e:
                    response.update({
                        'message': e.message,
                        'result': 'fail'
                    })
                return json.dumps(response)

            elif request_type == 'get_ip_service':
                ip_address = string.strip(request_data['ip_address'])
                services = model_ora.get_ip_accord_business(ip_address)
                response.update({
                    'data': services,
                    'result': 'success',
                    'ip_address': ip_address
                })
                return render.main(response)
Esempio n. 2
0
 def POST(self):
     request_data = eval(web.data())['request']
     response = {}
     response_header = utils.generate_response_header(request_data)
     response.update(response_header)
     request_type = utils.s(request_data['type'])
     oop_name = request_data['oop_name']
     response.update({'oop_name': oop_name})
     if request_type == 'current_volume_system':
         try:
             data = compute_diff_rate.get_current_volume_sys(oop_name)
             response.update({
                 'data': data,
                 'result': 'success',
                 'message': 'OK'
             })
         except Exception, e:
             response.update({
                 'message': e.message,
                 'result': 'fail'
             })
Esempio n. 3
0
 def POST(self):
     request_data = eval(web.data())['request']
     response = {}
     response_header = utils.generate_response_header(request_data)
     response.update(response_header)
     request_type = utils.s(request_data['type'])
     oop_name = request_data['oop_name']
     business_name = request_data['business_name']
     if request_type == 'changed_info':
         try:
             data = model_mysql.get_changed_ip_accord_busi(business_name)
             response.update({
                 'data': data,
                 'result': 'success',
                 'message': 'OK'
             })
         except Exception, e:
             response.update({
                 'result': 'fail',
                 'message': e.message
             })
Esempio n. 4
0
    def POST(self):
        request_data = eval(web.input().keys()[0])['request']
        print request_data
        request_type = utils.s(request_data['type'])
        response = utils.generate_response_header(request_data)
        if request_type == 'get_ip_service':
            pass
        elif request_type == 'business_relations':
            business, ip_insts = Alert.preprocess_request_data(request_data)
            ips = list(set([ip[0] for ip in ip_insts]))
            insts_to_business = list(set([ip[1] for ip in ip_insts]))
            if business.find(',') != -1:
                business = business.split(',')[0]
            right_business, left_business = [], []
            center_business_json, left_business_json, right_business_json = [], [], []
            inst_to_ips_dict = {}
            if len(ips) != 0:
                for item in ip_insts:
                    if item[1] in inst_to_ips_dict:
                        inst_to_ips_dict[item[1]].add(item[0])
                    else:
                        inst_to_ips_dict[item[1]] = set()
                        inst_to_ips_dict[item[1]].add(item[0])

                if len(insts_to_business) > 1:
                    left_business = model_ora.get_left_business_accord_instances_and_ips(insts_to_business, ips)
                    right_business = model_ora.get_right_business_accord_instances_and_ips(insts_to_business, ips)
                else:
                    left_business = model_ora.get_left_business_accord_instance_and_ips(insts_to_business[0], ips)
                    right_business = model_ora.get_right_business_accord_instance_and_ips(insts_to_business[0], ips)
            else:
                insts_to_business = model_ora.get_all_instances_accord_busi(business)
                left_business = model_ora.get_left_business(business)
                right_business = model_ora.get_right_business(business)

            all_businesses = list(
                set(list(set(item[0] for item in right_business)) + list(set(item[0] for item in left_business))))
            alert_businesses, alert_instances = map(lambda x: list(set(x)), model_reporter.get_alert_businesses_insts())
            busi_alert_dict = {}
            inst_alert_dict = {}
            for busi in all_businesses:
                if busi in alert_businesses:
                    busi_alert_dict.update({busi: True})
            for inst in insts_to_business:
                if inst in alert_instances:
                    inst_alert_dict.update({inst: True})

            right_business_set = list(set([unicode(item[0], 'utf-8') for item in right_business]))
            left_business_set = list(set([unicode(item[0], 'utf-8') for item in left_business]))
            for item in left_business:
                try:
                    oop = item[1]
                    tmp = {
                        'services_name': item[0],
                        'services_next': item[1],
                        'services_index': insts_to_business.index(item[1])
                    }
                    if tmp['services_name'] in busi_alert_dict:
                        tmp.update({'alert': True})
                    left_business_json.append(tmp)
                except:
                    pass
            for item in right_business:
                try:
                    tmp = {
                        'oop_name': item[1],
                        'oop_next': unicode(item[0], 'utf-8'),
                        'oop_index': right_business_set.index(unicode(item[0], 'utf-8'))
                    }
                    if tmp['oop_next'] == u'':
                        continue
                    if tmp['oop_name'] in inst_alert_dict:
                        tmp.update({'alert': True})
                    if tmp['oop_name'] in inst_to_ips_dict:
                        tmp.update({'center_ips': list(inst_to_ips_dict[tmp['oop_name']])})
                    center_business_json.append(tmp)
                except:
                    pass

            for item in right_business_set:
                try:
                    tmp = {
                        'services_name': item,
                        'services_index': right_business_set.index(item)
                    }
                    if tmp['services_name'] in busi_alert_dict:
                        tmp.update({'alert': True})
                    right_business_json.append(tmp)
                except:
                    pass
            if len(center_business_json) == 0:
                for i, item in enumerate(insts_to_business):
                    tmp = {
                        'oop_name': item,
                        'oop_next': '',
                        'oop_index': i
                    }
                center_business_json.append(tmp)
            data = {
                'business_left': left_business_json,
                'business_center': {
                    'services_name': business,
                    'service_data': center_business_json
                },
                'business_right': right_business_json}
            response.update({
                'data': data,
                'result': 'success',
                'services_name': business,
                'message': 'OK'
            })
        elif request_type == 'oop_relations':
            instance_name = request_data['oop_name']
            center_ips = request_data['center_ips'] if 'center_ips' in request_data else None
            oop_left, oop_right = [], []
            if center_ips is None:
                oop_left = model_ora.get_left_business_accord_instance(instance_name)
                oop_right = model_ora.get_right_business_accord_instance(instance_name)
            else:
                # 需要测试实现方法
                oop_left = model_ora.get_left_business_accord_instance_and_ips(instance_name, center_ips)
                oop_right = model_ora.get_right_business_accord_instance_and_ips(instance_name, center_ips)
            try:
                oop_left_set = [unicode(item[0], 'utf-8') for item in oop_left]
                oop_right_set = [unicode(item[0], 'utf-8') for item in oop_right]
                oop_left_json, oop_right_json = [], []

                for item in oop_left_set:
                    tmp = dict({
                        'services_name': item,
                        'services_index': oop_left_set.index(item)
                    })
                    oop_left_json.append(tmp)
                for item in oop_right_set:
                    tmp = dict({
                        'services_name': item,
                        'services_index': oop_right_set.index(item)}
                    )
                    oop_right_json.append(tmp)

                if string.lower('-'.join([instance_name.split('-')[0],
                                          instance_name.split('-')[-1]])) == 'inst-db':
                    oop_right_json = []
                response.update({
                    'data': {
                        'oop_left': oop_left_json,
                        'oop_right': oop_right_json
                    },
                    'result': 'success',
                    'message': 'OK'
                })
            except:
                pass
        elif request_type == 'oop_ip_list':
            instance_name = request_data['oop_name']
            business_name = request_data['business_name']
            # 如果center_ips不是空,则需要将不再center_ips中的ips都要剔除
            center_ips = set(request_data['center_ips']) if 'center_ips' in request_data else None
            instance_infos = []
            try:
                instance_infos = model_ora.get_detail_info_of_instance_to_business(instance_name, business_name)
                if center_ips is not None:
                    for item in instance_infos:
                        if item['ip_address'] in center_ips:
                            instance_infos.remove(item)

                response.update({
                    'result': 'success',
                    'data': instance_infos,
                    'message': 'OK'
                })
            except Exception, e:
                response.update({
                    'result': 'fail',
                    'message': e.message
                })
            pass
Esempio n. 5
0
    def POST(self):
        print web.data()
        request_data = eval(web.data())['request']
        request_type = utils.s(request_data['type'])
        response = utils.generate_response_header(request_data)
        if request_type == 'business_relations':
            business = request_data['services_name']

            # print business
            if business.find(',') != -1:
                print 'business with instance'
                bu_in = business.split(',')
                instance = bu_in[1]
                business = bu_in[0]
            else:
                instance = None
            instances_to_busi = model_ora.get_all_instances_accord_busi(business)
            business_right_json, business_left_json, center_instance_json = [], [], []
            business_right_set, business_left_set, center_instance_set = [], [], []
            business_to_instance, instance_to_business = {}, {}
            business_left, business_right = model_ora.get_left_business(business), model_ora.get_right_business(
                business)
            business_right_set = list(set([unicode(item[0], 'utf-8') for item in business_right]))
            instance_accord_right_set = list(set(item[1] for item in business_right))
            instance_diff = list(set(instances_to_busi).difference(set(instance_accord_right_set)))
            business_left_set = list(set([unicode(item[0], 'utf-8') for item in business_left]))
            for item in business_left:
                try:
                    oop = item[1]
                    tmp = {
                        'services_name': item[0],
                        'services_next': item[1],
                        'services_index': instances_to_busi.index(item[1])
                    }
                    business_left_json.append(tmp)
                except:
                    pass

            for item in business_right:
                try:
                    tmp = {
                        'oop_name': item[1],
                        'oop_next': unicode(item[0], 'utf-8'),
                        'oop_index': business_right_set.index(unicode(item[0], 'utf-8'))
                    }
                    center_instance_json.append(tmp)
                except:
                    pass

            for item in business_right_set:
                try:
                    tmp = {
                        'services_name': item,
                        'services_index': business_right_set.index(item)
                    }
                    business_right_json.append(tmp)
                except:
                    pass
            if len(instance_diff) != 0:
                for i, item in enumerate(instance_diff):
                    tmp = {
                        'oop_name': item,
                        'oop_next': '',
                        'oop_index': i
                    }
                    center_instance_json.append(tmp)
            if len(center_instance_json) == 0:
                for i, item in enumerate(instances_to_busi):
                    tmp = {
                        'oop_name': item,
                        'oop_next': '',
                        'oop_index': i
                    }
                    center_instance_json.append(tmp)
            data = {
                'business_left': business_left_json,
                'business_center': {
                    'services_name': business,
                    'service_data': center_instance_json
                },
                'business_right': business_right_json}
            if instance is not None:
                data.update({'oop_name': instance})

            response.update({
                'data': data,
                'result': 'success',
                'services_name': business,
                'message': 'OK'
            })

        elif request_type == 'oop_relations':
            instance_name = request_data['oop_name']
            try:
                oop_left = model_ora.get_left_business_accord_instance(instance_name)
                oop_right = model_ora.get_right_business_accord_instance(instance_name)
                oop_left_set = [unicode(item[0], 'utf-8') for item in oop_left]
                oop_right_set = [unicode(item[0], 'utf-8') for item in oop_right]
                oop_left_json, oop_right_json = [], []

                for item in oop_left_set:
                    tmp = dict({
                        'services_name': item,
                        'services_index': oop_left_set.index(item)
                    })
                    oop_left_json.append(tmp)
                for item in oop_right_set:
                    tmp = dict({
                        'services_name': item,
                        'services_index': oop_right_set.index(item)}
                    )
                    oop_right_json.append(tmp)

                if string.lower('-'.join([instance_name.split('-')[0],
                                          instance_name.split('-')[-1]])) == 'inst-db':
                    oop_right_json = []
                response.update({
                    'data': {
                        'oop_left': oop_left_json,
                        'oop_right': oop_right_json
                    },
                    'result': 'success',
                    'message': 'OK'
                })
            except Exception, e:
                print e.message
                response.update({
                    'result': 'fail',
                    'message': e.message
                })