def get_resource_url(ID, API): USER = api.USER PASSWORD = api.PASSWORD date = str(int(time.time())) sign_text = date + API + USER + api.md5(PASSWORD) sign = api.md5(sign_text) res_url = API + '?id=%sdate=%s&sign=%s:%s' % (ID, date, USER, sign) return res_url
'server_id': virus_server['id'], 'tenant_id': tenant_id, 'tenant_name': tenant_name, 'user_id': 'a5982c0ae54a4b9693b2f0f3cc630edf', 'user_name': config.admin_user, 'ip_address': ip_addr, 'region': server.get('region', '') } num_once = 500 num_total = 0 len_response = 500 error_occured = False data_virus = [] date = str(int(time.time())) sign_text = date + self.API + api.USER + api.md5(api.PASSWORD) sign = api.USER + ':' + api.md5(sign_text) # Get virus list from current server while len_response == num_once and not error_occured: virus_port = self.virus_port virus_url = 'http://%s:%s%s?date=%s&sign=%s&from=%d&size=%d' \ % (ip_addr, virus_port, self.API, date, sign, num_total, num_once) try: data_virus = self.get_virus_list(virus_url) len_response = len(data_virus) num_total += len_response all_virus_data.extend(data_virus) except Exception, e: error_occured = True log.error('Failed to fetch virus list for server %s from %s: %r' \ % (virus_server['id'], ip_addr, e))
tenant_name = tenants_id_name_dict.get(tenant_id, '') data = {'server_id': virus_server['id'], 'tenant_id': tenant_id, 'tenant_name': tenant_name, 'user_id': 'a5982c0ae54a4b9693b2f0f3cc630edf', 'user_name': config.admin_user, 'ip_address': ip_addr, 'region': server.get('region', '')} num_once = 500 num_total = 0 len_response = 500 error_occured = False data_virus = [] date = str(int(time.time())) sign_text = date + self.API + api.USER + api.md5(api.PASSWORD) sign = api.USER + ':' + api.md5(sign_text) # Get virus list from current server while len_response == num_once and not error_occured: virus_port = self.virus_port virus_url = 'http://%s:%s%s?date=%s&sign=%s&from=%d&size=%d' \ % (ip_addr, virus_port, self.API, date, sign, num_total, num_once) try: data_virus = self.get_virus_list(virus_url) len_response = len(data_virus) num_total += len_response all_virus_data.extend(data_virus) except Exception, e: error_occured = True log.error('Failed to fetch virus list for server %s from %s: %r' \ % (virus_server['id'], ip_addr, e))