]> Git Repo - qemu.git/blob - python/qemu/utils/__init__.py
Merge remote-tracking branch 'remotes/jsnow-gitlab/tags/python-pull-request' into...
[qemu.git] / python / qemu / utils / __init__.py
1 """
2 QEMU development and testing utilities
3
4 This package provides a small handful of utilities for performing
5 various tasks not directly related to the launching of a VM.
6 """
7
8 # Copyright (C) 2021 Red Hat Inc.
9 #
10 # Authors:
11 #  John Snow <[email protected]>
12 #  Cleber Rosa <[email protected]>
13 #
14 # This work is licensed under the terms of the GNU GPL, version 2.  See
15 # the COPYING file in the top-level directory.
16 #
17
18 import re
19 from typing import Optional
20
21 # pylint: disable=import-error
22 from .accel import kvm_available, list_accel, tcg_available
23
24
25 __all__ = (
26     'get_info_usernet_hostfwd_port',
27     'kvm_available',
28     'list_accel',
29     'tcg_available',
30 )
31
32
33 def get_info_usernet_hostfwd_port(info_usernet_output: str) -> Optional[int]:
34     """
35     Returns the port given to the hostfwd parameter via info usernet
36
37     :param info_usernet_output: output generated by hmp command "info usernet"
38     :return: the port number allocated by the hostfwd option
39     """
40     for line in info_usernet_output.split('\r\n'):
41         regex = r'TCP.HOST_FORWARD.*127\.0\.0\.1\s+(\d+)\s+10\.'
42         match = re.search(regex, line)
43         if match is not None:
44             return int(match[1])
45     return None
This page took 0.030057 seconds and 4 git commands to generate.