diff --git a/confluent_client/confluent/asynclient.py b/confluent_client/confluent/asynclient.py index 2f29e2e6..28de349f 100644 --- a/confluent_client/confluent/asynclient.py +++ b/confluent_client/confluent/asynclient.py @@ -400,8 +400,8 @@ class Command(object): async def _connect_tls(self): server, port = _parseserver(self.serverloc) - for res in socket.getaddrinfo(server, port, socket.AF_UNSPEC, - socket.SOCK_STREAM): + for res in await asyncio.get_running_loop().getaddrinfo( + server, port, socket.AF_UNSPEC, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.connection = socket.socket(af, socktype, proto) diff --git a/confluent_server/aiohmi/ipmi/oem/lenovo/handler.py b/confluent_server/aiohmi/ipmi/oem/lenovo/handler.py index 162ffd47..4f5f830e 100755 --- a/confluent_server/aiohmi/ipmi/oem/lenovo/handler.py +++ b/confluent_server/aiohmi/ipmi/oem/lenovo/handler.py @@ -1158,7 +1158,7 @@ class OEMHandler(generic.OEMHandler): if domain is not None: await self._set_ris_string(6, domain) await self._set_ris_string(1, path) - ip = util.get_ipv4(host)[0] + ip = await util.get_ipv4(host)[0] await self._set_short_ris_string(2, ip) await self._set_short_ris_string(5, proto) # now to restart RIS to have changes take effect... diff --git a/confluent_server/aiohmi/ipmi/private/session.py b/confluent_server/aiohmi/ipmi/private/session.py index b48c3678..b4b4ff6f 100644 --- a/confluent_server/aiohmi/ipmi/private/session.py +++ b/confluent_server/aiohmi/ipmi/private/session.py @@ -1930,10 +1930,11 @@ class Session(object): self.allsockaddrs = [] myport = self.socket.getsockname()[1] try: - for res in socket.getaddrinfo(self.bmc, - self.port, - 0, - socket.SOCK_DGRAM): + loop = asyncio.get_running_loop() + addrinfo = await loop.getaddrinfo(self.bmc, + self.port, + type=socket.SOCK_DGRAM) + for res in addrinfo: sockaddr = res[4] if ipv6support and res[0] == socket.AF_INET: # convert the sockaddr to AF_INET6 diff --git a/confluent_server/aiohmi/ipmi/private/util.py b/confluent_server/aiohmi/ipmi/private/util.py index 782b1195..19cfc4c2 100644 --- a/confluent_server/aiohmi/ipmi/private/util.py +++ b/confluent_server/aiohmi/ipmi/private/util.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import asyncio import ctypes import functools import os @@ -70,12 +71,12 @@ def urlsplit(url): return proto, host, rest -def get_ipv4(hostname): +async def get_ipv4(hostname): """Get list of ipv4 addresses for hostname """ - addrinfo = socket.getaddrinfo(hostname, None, socket.AF_INET, - socket.SOCK_STREAM) + addrinfo = await asyncio.get_running_loop().getaddrinfo( + hostname, None, socket.AF_INET, socket.SOCK_STREAM) return [addrinfo[x][4][0] for x in range(len(addrinfo))] diff --git a/confluent_server/aiohmi/redfish/command.py b/confluent_server/aiohmi/redfish/command.py index a68b5283..9fb4fdd3 100644 --- a/confluent_server/aiohmi/redfish/command.py +++ b/confluent_server/aiohmi/redfish/command.py @@ -181,7 +181,9 @@ class Command(object): self._bmcv4ip = None self._bmcv6ip = None self.xauthtoken = None - for addrinf in socket.getaddrinfo(bmc, 0, 0, socket.SOCK_STREAM): + addrinfo = await asyncio.get_running_loop().getaddrinfo( + bmc, 0, family=0, type=socket.SOCK_STREAM) + for addrinf in addrinfo: if addrinf[0] == socket.AF_INET: self._bmcv4ip = socket.inet_pton(addrinf[0], addrinf[-1][0]) elif addrinf[0] == socket.AF_INET6: diff --git a/confluent_server/confluent/certutil.py b/confluent_server/confluent/certutil.py index a34b7fa5..8dae61ae 100644 --- a/confluent_server/confluent/certutil.py +++ b/confluent_server/confluent/certutil.py @@ -1,3 +1,4 @@ +import asyncio import os if __name__ == '__main__': import sys @@ -363,7 +364,8 @@ async def create_certificate(keyout=None, certout=None, csrfile=None, subj=None, dnsnames.add(longname) break for currip in ipaddrs: - currname = socket.getnameinfo((currip, 0), 0)[0] + currname = (await asyncio.get_running_loop().getnameinfo( + (currip, 0), 0))[0] for suffix in permitdomains: if currname.endswith(suffix): dnsnames.add(currname) diff --git a/confluent_server/confluent/discovery/core.py b/confluent_server/confluent/discovery/core.py index 20f388ec..44599eb8 100644 --- a/confluent_server/confluent/discovery/core.py +++ b/confluent_server/confluent/discovery/core.py @@ -1509,7 +1509,8 @@ async def discover_node(cfg, handler, info, nodename, manual): else: bmcaddr = bmcaddr.split('/', 1)[0] await wait_for_connection(bmcaddr) - socket.getaddrinfo(bmcaddr, 443) + loop = asyncio.get_running_loop() + await loop.getaddrinfo(bmcaddr, 443) if nodeconfig: await util.check_call(['/opt/confluent/bin/nodeconfig', nodename] + nodeconfig) log.log({'info': 'Configured {0} ({1})'.format(nodename, diff --git a/confluent_server/confluent/discovery/handlers/bmc.py b/confluent_server/confluent/discovery/handlers/bmc.py index eac44b83..2394a2e8 100644 --- a/confluent_server/confluent/discovery/handlers/bmc.py +++ b/confluent_server/confluent/discovery/handlers/bmc.py @@ -21,7 +21,7 @@ import confluent.netutil as netutil import aiohmi.exceptions as pygexc import aiohmi.ipmi.command as ipmicommand -import socket +import asyncio class NodeHandler(generic.NodeHandler): DEFAULT_USER = 'USERID' @@ -156,7 +156,8 @@ class NodeHandler(generic.NodeHandler): 'fe80::')): newip = cd['hardwaremanagement.manager']['value'] newip = newip.split('/', 1)[0] - newipinfo = socket.getaddrinfo(newip, 0)[0] + newipinfo = (await asyncio.get_running_loop().getaddrinfo( + newip, 0))[0] # This getaddrinfo is repeated in get_nic_config, could be # optimized, albeit with a more convoluted api.. newip = newipinfo[-1][0] diff --git a/confluent_server/confluent/discovery/handlers/redfishbmc.py b/confluent_server/confluent/discovery/handlers/redfishbmc.py index 5cdaeacc..a486f68d 100644 --- a/confluent_server/confluent/discovery/handlers/redfishbmc.py +++ b/confluent_server/confluent/discovery/handlers/redfishbmc.py @@ -20,8 +20,6 @@ import confluent.util as util import json -from socket import getaddrinfo - import aiohmi.util.webclient as webclient async def get_host_interface_urls(wc, mginfo): @@ -259,7 +257,7 @@ class NodeHandler(generic.NodeHandler): 'fe80::')): newip = cd['hardwaremanagement.manager']['value'] newip = newip.split('/', 1)[0] - newipinfo = getaddrinfo(newip, 0)[0] + newipinfo = (await asyncio.get_running_loop().getaddrinfo(newip, 0))[0] newip = newipinfo[-1][0] if ':' in newip: raise exc.NotImplementedException('IPv6 remote config TODO') @@ -342,7 +340,7 @@ async def remote_nodecfg(nodename, cfm): ipaddr = cfg.get(nodename, {}).get('hardwaremanagement.manager', {}).get( 'value', None) ipaddr = ipaddr.split('/', 1)[0] - ipaddr = getaddrinfo(ipaddr, 0)[0][-1] + ipaddr = (await asyncio.get_running_loop().getaddrinfo(ipaddr, 0))[0][-1] if not ipaddr: raise Exception('Cannot remote configure a system without known ' 'address') diff --git a/confluent_server/confluent/discovery/handlers/tsm.py b/confluent_server/confluent/discovery/handlers/tsm.py index 6b637e51..665fd68f 100644 --- a/confluent_server/confluent/discovery/handlers/tsm.py +++ b/confluent_server/confluent/discovery/handlers/tsm.py @@ -194,7 +194,7 @@ class NodeHandler(generic.NodeHandler): 'fe80::')): newip = cd['hardwaremanagement.manager']['value'] newip = newip.split('/', 1)[0] - newipinfo = socket.getaddrinfo(newip, 0)[0] + newipinfo = (await asyncio.get_running_loop().getaddrinfo(newip, 0))[0] newip = newipinfo[-1][0] if ':' in newip: raise exc.NotImplementedException('IPv6 remote config TODO') @@ -231,7 +231,7 @@ async def remote_nodecfg(nodename, cfm): ipaddr = cfg.get(nodename, {}).get('hardwaremanagement.manager', {}).get( 'value', None) ipaddr = ipaddr.split('/', 1)[0] - ipaddr = socket.getaddrinfo(ipaddr, 0)[0][-1] + ipaddr = (await asyncio.get_running_loop().getaddrinfo(ipaddr, 0))[0][-1] if not ipaddr: raise Exception('Cannot remote configure a system without known ' 'address') diff --git a/confluent_server/confluent/discovery/handlers/xcc3.py b/confluent_server/confluent/discovery/handlers/xcc3.py index dbfa4e10..7b48d8b7 100644 --- a/confluent_server/confluent/discovery/handlers/xcc3.py +++ b/confluent_server/confluent/discovery/handlers/xcc3.py @@ -97,7 +97,7 @@ async def remote_nodecfg(nodename, cfm): ipaddr = cfg.get(nodename, {}).get('hardwaremanagement.manager', {}).get( 'value', None) ipaddr = ipaddr.split('/', 1)[0] - ipaddr = socket.getaddrinfo(ipaddr, 0)[0][-1] + ipaddr = (await asyncio.get_running_loop().getaddrinfo(ipaddr, 0))[0][-1] if not ipaddr: raise Exception('Cannot remote configure a system without known ' 'address') diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index cbd37793..7a46d8c6 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -834,7 +834,8 @@ async def resourcehandler_backend(req, make_response): targip = targip.split('/', 1)[0] if default: try: - ip_info = socket.getaddrinfo(targip, 0, 0, socket.SOCK_STREAM) + loop = asyncio.get_running_loop() + ip_info = await loop.getaddrinfo(targip, 0, 0, socket.SOCK_STREAM) except socket.gaierror: rsp = await make_response('text/plain', 404) await rsp.write(b'hardwaremanagement.manager definition could not be resolved') @@ -1244,7 +1245,7 @@ async def serve(bind_host, bind_port, bind_group, bind_perms): os.umask(oldumask) bind_arg = bind_host else: - bindinfo = socket.getaddrinfo( + bindinfo = await asyncio.get_running_loop().getaddrinfo( bind_host, bind_port, 0, socket.SOCK_STREAM) if bindinfo[0][0] == socket.AF_INET: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)