import re
import io
-import time
import logging
+import ipaddress
log = logging.getLogger('pyi2ncommon.dial')
from . import cnfvar
from . import sysmisc
-HAVE_IPADDRESS = True
-try:
- import ipaddress
-except ImportError: # guest
- HAVE_IPADDRESS = False
-
__all__ = (
"arnied_dial_hangup", "arnied_dial_doc", "arnied_dial_permanent", "dialout", "get_wan_address", "DIALOUT_MODE_PERMANENT", "DIALOUT_MODE_MANUAL", "DIALOUT_MODE_DEFAULT", "DIALOUT_MODE_BY_NAME"
)
# compiling this regex needs the provider id and is postponed due to
# the peculiar implementation of the connd online condition
-NEEDLE_MEMO = " \[%s\] :(.*connected online fsm<online>.*)"
+NEEDLE_MEMO = r" \[%s\] :(.*connected online fsm<online>.*)"
NEEDLE_OFFLINE = re.compile("connection map:\nend of connection map")
DIALTOOLS_HANGUP_BIN = "/usr/intranator/bin/hangup"
"""
log.debug("requested arnied_dial_hangup%s",
" (blocking)" if block else "")
- if block is False:
+ if not block:
succ, _, _ = sysmisc.run_cmd_with_pipe([DIALTOOLS_HANGUP_BIN])
return sysmisc.RUN_RESULT_OK if succ is True else sysmisc.RUN_RESULT_FAIL
:rtype: int (dial result as above)
"""
log.debug("requested arnied_dial_doc%s", " (blocking)" if block else "")
- if block is False:
+ if not block:
succ, _, _ = sysmisc.run_cmd_with_pipe([DIALTOOLS_DOC_BIN, prid])
return sysmisc.RUN_RESULT_OK if succ is True else sysmisc.RUN_RESULT_FAIL
res, err = sysmisc.cmd_block_till([DIALTOOLS_DOC_BIN, prid],
store.commit(cnf)
return True, "", None
- if block is False:
+ if not block:
succ, out, _ = aux()
return sysmisc.RUN_RESULT_OK if succ is True else sysmisc.RUN_RESULT_FAIL
log.info("go online with provider")
dmode = None
- if isinstance(mode, int) is True:
+ if isinstance(mode, int):
dmode = mode
- elif isinstance(mode, str) is True:
+ elif isinstance(mode, str):
try:
dmode = DIALOUT_MODE_BY_NAME[mode]
- except Exception:
+ except KeyError:
log.error("invalid online mode name ā%sā requested" % mode)
pass
:type vm: virttest.qemu_vm.VM | None
:returns: The IPv4 address. For correctness, it will use the
- ipaddress module if available. Otherwise it falls back
- on untyped data.
- :rtype: None | (ipaddress.IPv4Address | str)
+ ipaddress module
+ :rtype: None | ipaddress.IPv4Address
"""
log.info("query current lease")
if vm is None:
break
if l.find("connected online fsm<online> IP:") != -1:
addr = l[l.find("IP:")+3:l.find(" )\n")] # beurk
- if HAVE_IPADDRESS is True:
- return ipaddress.IPv4Address(str(addr))
- else:
- return addr
+ return ipaddress.IPv4Address(str(addr))
return None