New patch submitted by David Naori (dnaori(a)redhat.com)
You can review this change at:
http://gerrit.usersys.redhat.com/671
commit 8f4d660ec410cfb9dbf55f3565111663306a6670
Author: David Naori <dnaori(a)redhat.com>
Date: Thu Jul 7 09:24:20 2011 +0300
BZ#719516 vdsClient: avoid possible race in list table.
Change-Id: I7fc52ac0428fd0a2128376a97d56df0fc41ff8ac
diff --git a/vdsm_cli/vdsClient.py b/vdsm_cli/vdsClient.py
index 903dc46..ddada10 100755
--- a/vdsm_cli/vdsClient.py
+++ b/vdsm_cli/vdsClient.py
@@ -173,34 +173,35 @@ class service:
return self.ExecAndExit(self.s.changeFloppy(vmId, file))
def do_list(self, args):
- table=False
- if len(args):
- if args[0] == 'table':
- table=True
response = self.s.list(True)
- if response['status']['code'] != 0:
- print response['status']['message']
- else:
- if table:
- allStats = {}
- for s in self.s.getAllVmStats()['statsList']:
- allStats[s['vmId']] = s
- for conf in response['vmList']:
- if table:
- id = conf['vmId']
- status = conf['status']
- if allStats[id].get('monitorResponse') == '-1':
- status += '*'
- print "%-36s %6s %-20s %-20s %-20s" % (id,
- conf.get('pid', 'none'),
- conf.get('vmName', '<< NO NAME >>'),
- status, allStats[id].get('guestIPs', '') )
- else:
- if 'sysprepInf' in conf:
- conf['sysprepInf'] = '<<exists>>'
- printConf(conf)
- sys.exit(response['status']['code'])
+ if response['status']['code']:
+ print response['status']['message']
+ return
+
+ allStats = dict()
+
+ if 'table' in args:
+ for s in self.s.getAllVmStats()['statsList']:
+ allStats[ s['vmId'] ] = s
+
+ for conf in response['vmList']:
+ if allStats:
+ id = conf['vmId']
+ if id not in allStats.keys():
+ continue
+ status = conf['status']
+ if allStats[id].get('monitorResponse') == '-1':
+ status += '*'
+ print "%-36s %6s %-20s %-20s %-20s" % ( id,
+ conf.get('pid', 'none'),
+ conf.get('vmName', '<< NO NAME >>'),
+ status, allStats[id].get('guestIPs', '') )
+ else:
+ if 'sysprepInf' in conf:
+ conf['sysprepInf'] = '<<exists>>'
+ printConf(conf)
+ sys.exit(response['status']['code'])
def do_listNames(self, args):
response = self.s.list()