summary refs log tree commit diff stats
path: root/results/classifier/007/other/42613410
blob: 4d3ce0dfece42b5c22dc809a2ac5d114a5311845 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
vnc: 0.400
KVM: 0.381
permissions: 0.373
device: 0.342
other: 0.332
graphic: 0.330
semantic: 0.327
performance: 0.324
debug: 0.311
network: 0.284
PID: 0.276
files: 0.264
socket: 0.190
boot: 0.187

[Qemu-devel] [PATCH, Bug 1612908] scripts: Add TCP endpoints for qom-* scripts

From: Carl Allendorph <address@hidden>

I've created a patch for bug #1612908. The current docs for the scripts
in the "scripts/qmp/" directory suggest that both unix sockets and
tcp endpoints can be used. The TCP endpoints don't work for most of the
scripts, with notable exception of 'qmp-shell'. This patch attempts to
refactor the process of distinguishing between unix path endpoints and
tcp endpoints to work for all of these scripts.

Carl Allendorph (1):
  scripts: Add ability for qom-* python scripts to target tcp endpoints

 scripts/qmp/qmp-shell | 22 ++--------------------
 scripts/qmp/qmp.py    | 23 ++++++++++++++++++++---
 2 files changed, 22 insertions(+), 23 deletions(-)

--
2.7.4

From: Carl Allendorph <address@hidden>

The current code for QEMUMonitorProtocol accepts both a unix socket
endpoint as a string and a tcp endpoint as a tuple. Most of the scripts
that use this class don't massage the command line argument to generate
a tuple. This patch refactors qmp-shell slightly to reuse the existing
parsing of the "host:port" string for all the qom-* scripts.

Signed-off-by: Carl Allendorph <address@hidden>
---
 scripts/qmp/qmp-shell | 22 ++--------------------
 scripts/qmp/qmp.py    | 23 ++++++++++++++++++++---
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 0373b24..8a2a437 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -83,9 +83,6 @@ class QMPCompleter(list):
 class QMPShellError(Exception):
     pass
 
-class QMPShellBadPort(QMPShellError):
-    pass
-
 class FuzzyJSON(ast.NodeTransformer):
     '''This extension of ast.NodeTransformer filters literal "true/false/null"
     values in an AST and replaces them by proper "True/False/None" values that
@@ -103,28 +100,13 @@ class FuzzyJSON(ast.NodeTransformer):
 #       _execute_cmd()). Let's design a better one.
 class QMPShell(qmp.QEMUMonitorProtocol):
     def __init__(self, address, pretty=False):
-        qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
+        qmp.QEMUMonitorProtocol.__init__(self, address)
         self._greeting = None
         self._completer = None
         self._pretty = pretty
         self._transmode = False
         self._actions = list()
 
-    def __get_address(self, arg):
-        """
-        Figure out if the argument is in the port:host form, if it's not it's
-        probably a file path.
-        """
-        addr = arg.split(':')
-        if len(addr) == 2:
-            try:
-                port = int(addr[1])
-            except ValueError:
-                raise QMPShellBadPort
-            return ( addr[0], port )
-        # socket path
-        return arg
-
     def _fill_completion(self):
         for cmd in self.cmd('query-commands')['return']:
             self._completer.append(cmd['name'])
@@ -400,7 +382,7 @@ def main():
 
         if qemu is None:
             fail_cmdline()
-    except QMPShellBadPort:
+    except qmp.QMPShellBadPort:
         die('bad port number in command-line')
 
     try:
diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py
index 62d3651..261ece8 100644
--- a/scripts/qmp/qmp.py
+++ b/scripts/qmp/qmp.py
@@ -25,21 +25,23 @@ class QMPCapabilitiesError(QMPError):
 class QMPTimeoutError(QMPError):
     pass
 
+class QMPShellBadPort(QMPError):
+    pass
+
 class QEMUMonitorProtocol:
     def __init__(self, address, server=False, debug=False):
         """
         Create a QEMUMonitorProtocol class.
 
         @param address: QEMU address, can be either a unix socket path (string)
-                        or a tuple in the form ( address, port ) for a TCP
-                        connection
+                        or a TCP endpoint (string in the format "host:port")
         @param server: server mode listens on the socket (bool)
         @raise socket.error on socket connection errors
         @note No connection is established, this is done by the connect() or
               accept() methods
         """
         self.__events = []
-        self.__address = address
+        self.__address = self.__get_address(address)
         self._debug = debug
         self.__sock = self.__get_sock()
         if server:
@@ -47,6 +49,21 @@ class QEMUMonitorProtocol:
             self.__sock.bind(self.__address)
             self.__sock.listen(1)
 
+    def __get_address(self, arg):
+        """
+        Figure out if the argument is in the port:host form, if it's not it's
+        probably a file path.
+        """
+        addr = arg.split(':')
+        if len(addr) == 2:
+            try:
+                port = int(addr[1])
+            except ValueError:
+                raise QMPShellBadPort
+            return ( addr[0], port )
+        # socket path
+        return arg
+
     def __get_sock(self):
         if isinstance(self.__address, tuple):
             family = socket.AF_INET
-- 
2.7.4