我一直收到此错误:
/ entities / pull-ipam-types /中的ConnectionError HTTPConnectionPool(host = '10 .30.0.10',port = 7777):超过最大重试次数 网址:/ devices / resources / IPamTypes /(由 NewConnectionError(':无法建立新连接:[Errno 10061]否 由于目标计算机主动拒绝,因此可以建立连接 它,))
在此功能:
def pull_ipam_types(request):
#ftp_host = FTPConfiguration.objects.all()[0].FTP_HOST
#url = 'http://' + ftp_host + ':7777/devices/resources/IPamTypes/'
# resp = requests.get(url, headers={'User-Agent': 'Definitely-Not-Requests'}, auth = ('user', '123456'))
resp = requests.get('http://' + FTPConfiguration.objects.all()[0].FTP_HOST +
':7777/devices/resources/IPamTypes/', auth=('user', '123456')) #olivera auth=('user', '123456'))
ret_message = 'Pulled successfully. '
# 1) get old types
old_ipam_types = []
for one_type in IpamType.objects.all():
old_ipam_types.append(one_type.type)
# 2) get new types
new_ipam_types = []
if resp.status_code != 200:
# This means something went wrong.
messages.error(request, 'Error ' + resp.status_code + ' during REST request, review your FTP configuration.')
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
for one_type in resp.json():
new_ipam_types.append(one_type)
# 3) create list of added and removed.
added_ipams = []
for new_ipam in new_ipam_types:
is_found = False # current old still exists
for old_ipam in old_ipam_types:
if old_ipam == new_ipam:
is_found = True
# new_ipam added
if not is_found:
added_ipams.append(new_ipam)
removed_ipams = []
for old_ipam in old_ipam_types:
is_found = False # current old still exists
for new_ipam in new_ipam_types:
if old_ipam == new_ipam:
is_found = True
# old_ipam removed
if not is_found:
removed_ipams.append(old_ipam)
# 4) check that all removed are not used + error message in case they are used.
removed_ipam_ids = IpamType.objects.filter(type__in=removed_ipams).values_list('id', flat=True)
entity_ids = Parameter.objects.filter(ipam_type__in=removed_ipam_ids).values_list('entity_id', flat=True)
if len(entity_ids) > 0:
relevant_entites = Entity.objects.filter(id__in=entity_ids).values_list('name', flat=True)
messages.error(request, "FAILURE. Some IPAM types that were removed from " +
"NetAce are still used by some of the entities in ME.\n Relevant IPAM types are: " +
', '.join(removed_ipams) + ".\n Relevant Entities are: " + ', '.join(relevant_entites) +
".\n Please fix those entites before pulling IPAM types.")
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
# 5) remove + append message: xxx removed
if len(removed_ipams) > 0:
IpamType.objects.filter(type__in=removed_ipams).delete()
ret_message = ret_message + 'Removed IPAM Types: ' + ', '.join(removed_ipams) + '.\n'
# 6) add + append message: yyy added.
if len(added_ipams) > 0:
ret_message = ret_message + 'Added IPAM Types: ' + ', '.join(added_ipams) + '.\n'
for new_ipam in added_ipams:
IpamType.objects.get_or_create(type=new_ipam)
if len(removed_ipams) == 0 and len(added_ipams) == 0:
ret_message = 'There are no new IPAM Types to pull'
messages.success(request, ret_message)
# context = get_base_context()
# return render_to_response('left_container.html', context)
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
)