4
4
from eayunstack_tools .sys_utils import ssh_connect , ssh_connect2
5
5
from eayunstack_tools .utils import get_controllers_hostname
6
6
from eayunstack_tools .doctor .utils import run_doctor_cmd_on_node
7
+ from eayunstack_tools .pythonclient import PythonClient
7
8
import logging
8
9
import commands
9
10
import json
@@ -22,39 +23,6 @@ def run_command(cmd):
22
23
reval = out
23
24
return reval
24
25
25
-
26
- # FIXME: some neutronclient does not support json output, hack it
27
- def csv2dict (csv ):
28
- """Convert result format from csv to dict:
29
- csv format:
30
- "id","name","mac_address"
31
- "596afd3e-b60a-41f5-97c3-39495979e6d8","","fa:16:3e:3a:ee:97"
32
- "70cb55cd-d5cb-4c12-8ad2-8edf18c2fa94","","fa:16:3e:f7:e9:8c"
33
-
34
- dict format:
35
- [{"id": "596afd3e", "name": "", "mac_address": "fa:16:3e:3a:ee:97"},
36
- {"id": "70cb55cd", "name": "", "mac_address": "fa:16:3e:f7:e9:8c"}]
37
- """
38
- field = csv .split ('\n ' )[0 ]
39
- p = re .compile (r'"(.*)"' )
40
- column = []
41
- for i in field .split (',' ):
42
- column .append (p .match (i ).groups ()[0 ])
43
- routers = []
44
- out = csv .split ('\n ' )[1 :]
45
- for r in out :
46
- router = {}
47
- r = r .split (',' )
48
- index = 0
49
- for index in range (len (column )):
50
- try :
51
- router [column [index ]] = p .match (r [index ]).groups ()[0 ]
52
- except AttributeError :
53
- router [column [index ]] = r [index ]
54
- routers .append (router )
55
- return routers
56
-
57
-
58
26
def vrouter_get_gw_remote (l3_host , rid ):
59
27
cmd = "ip netns exec qrouter-%s ip route show | " \
60
28
"grep 'default' | awk '{print $3}'" % (rid )
@@ -164,11 +132,10 @@ def port_log(device_owner, s):
164
132
LOG .debug ('this port is normal port, do not need to check gateway' )
165
133
166
134
def vrouter_check_one (rid ):
167
- cmd = 'neutron router-port-list %s -f csv -F id -F name' % (rid )
168
- out = run_command (cmd )
169
- ports = []
170
- if out :
171
- ports = csv2dict (out )
135
+ logging .disable (logging .INFO )
136
+ pc = PythonClient ()
137
+ ports = pc .neutron_router_port_list (rid )
138
+ logging .disable (logging .NOTSET )
172
139
173
140
l3_host = vrouter_get_l3_host (rid )
174
141
if l3_host :
@@ -180,11 +147,12 @@ def vrouter_check_one(rid):
180
147
181
148
182
149
def vrouter_get_l3_host (rid ):
183
- cmd = "neutron l3-agent-list-hosting-router -f csv %s" \
184
- % (rid )
185
- out = run_command (cmd ).strip ('\r \n ' )
186
- if out :
187
- hosts = csv2dict (out )
150
+ logging .disable (logging .INFO )
151
+ pc = PythonClient ()
152
+ hosts = pc .neutron_l3_agent_list_hosting_router (rid )
153
+ logging .disable (logging .NOTSET )
154
+
155
+ if hosts :
188
156
return hosts [0 ]['host' ]
189
157
else :
190
158
LOG .error ('can not get l3 host for router %s' % (rid ))
@@ -198,13 +166,11 @@ def _vrouter_check(parser):
198
166
vrouter_check_one (parser .rid )
199
167
else :
200
168
# 1) Get valid routers list
201
- cmd = 'neutron router-list -f csv -F id -F name'
202
- if parser .tid :
203
- cmd += ' --tenant-id %s' % (parser .tid )
204
- out = run_command (cmd )
205
- routers = []
206
- if out :
207
- routers = csv2dict (out )
169
+ tenant_id = parser .tid
170
+ logging .disable (logging .INFO )
171
+ pc = PythonClient ()
172
+ routers = pc .neutron_router_list (tenant_id )
173
+ logging .disable (logging .NOTSET )
208
174
209
175
# 2) Check every router one by one: .e.g. status, ip address ..., this
210
176
# is done on neutron node which namespace belong to.
0 commit comments