Remove unused code + Increase frequeuncy of host heartbeat update

This commit is contained in:
ahmadbilalkhalid 2019-12-30 14:58:05 +05:00
commit 52867614df
8 changed files with 1 additions and 924 deletions

View file

@ -1,40 +0,0 @@
import logging
import socket
import requests
import json
from ipaddress import ip_address
from os.path import join as join_path
from . import logger
# TODO: Should be removed as soon as migration
# mechanism is finalized inside ucloud
def get_ipv4_address():
# If host is connected to internet
# Return IPv4 address of machine
# Otherwise, return 127.0.0.1
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
try:
s.connect(("8.8.8.8", 80))
except socket.timeout:
address = "127.0.0.1"
except Exception as e:
logger.exception(e)
address = "127.0.0.1"
else:
address = s.getsockname()[0]
return address
def get_ipv6_address():
try:
r = requests.get("https://api6.ipify.org?format=json")
content = json.loads(r.content.decode("utf-8"))
ip = ip_address(content["ip"]).exploded
except Exception as e:
logger.exception(e)
else:
return ip

View file

@ -70,15 +70,3 @@ def delete_network_interface(iface):
except Exception:
logger.exception("Interface %s Deletion failed", iface)
def find_free_port():
with closing(
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
) as s:
try:
s.bind(("", 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
except Exception:
return None
else:
return s.getsockname()[1]