def getJobsInfoFiltered(self, cols=None): info = {} if cols == None: return info if not isList(cols): raise "Unsupported data type for cols. Should be None or list" if len(cols) == 0: return info cmd = 'onevm list all --list %s' % (string.join(cols)).replace(' ',',') rc, stdout, stderr = iexe_cmd(cmd) for line in stdout: entry = line.split() if (len(entry) == len(cols)) and (representsInt(entry[0])): info[entry[0]] = {} for i in range(len(cols)): info[entry[0]][cols[i]] = entry[i] return info
def getJobsInfoFiltered(self, cols=None): info = {} if cols == None: return info if not isList(cols): raise "Unsupported data type for cols. Should be None or list" if len(cols) == 0: return info cmd = 'onevm list all --list %s' % (string.join(cols)).replace( ' ', ',') rc, stdout, stderr = iexe_cmd(cmd) for line in stdout: entry = line.split() if (len(entry) == len(cols)) and (representsInt(entry[0])): info[entry[0]] = {} for i in range(len(cols)): info[entry[0]][cols[i]] = entry[i] return info
def getJobsInfo(self, vm_ids=None): """ For the list of VM IDs get detail info about the VMs and return a dictionary keyed on ID """ info = {} if vm_ids == None: #vm_ids = self.getJobIds() cmd = 'onevm list all --xml' else: cmd = 'onevm show --xml %s' % ' '.join(map(str, vm_ids)) if not isList(vm_ids): raise "Unsupported data type for vm_ids. Should be None or list" rc, stdout, stderr = iexe_cmd(cmd) cols = ['ID', 'USER', 'STAT'] if self.version == 'OpenNebula 2': cols = ['id', 'user', 'stat'] # Just to get the username information filtered_info = self.getJobsInfoFiltered(cols=cols) vm_id = None vm_info = {} in_history = False for line in stdout: l = line.strip() if l == '<HISTORY>': in_history = True continue if l == '</HISTORY>': in_history = False continue for field in self.fields: s_str = '<%s>' % field e_str = '</%s>' % field if l.startswith(s_str) and l.endswith(e_str): f_info = l.replace(s_str, '').replace(e_str, '') if f_info.startswith('<![CDATA['): field_info = f_info.replace('<![CDATA[', '').replace(']]>', '') if field == 'MEMORY': info[vm_id]['MEMORY_REQ(MB)'] = field_info break else: field_info = f_info if field == 'ID': vm_id = field_info info[vm_id] = {} uid = 0 #if filtered_info.has_key(vm_id): # if filtered_info[vm_id].has_key('user'): # info[vm_id]['USERNAME'] = filtered_info[vm_id]['user'] # elif filtered_info[vm_id].has_key('USER'): # info[vm_id]['USERNAME'] = filtered_info[vm_id]['USER'] #if not info[vm_id].has_key('USERNAME'): # if info[vm_id][uid] == 0: # info[vm_id]['USERNAME'] = '******' if field == 'USERNAME': break if field == 'UID': try: info[vm_id]['USERNAME'] = self.userManager.users[ field_info] except: info[vm_id]['USERNAME'] = '******' if field == 'STATE': info[vm_id]['STATE_STR'] = self.vmStateMap[field_info] if field == 'LCM_STATE': info[vm_id]['LCM_STATE_STR'] = self.lcmStateMap[ field_info] if field in self.historyFields: if in_history == True: if field not in ('STIME', 'ETIME'): info[vm_id]['HISTORY_%s' % field] = field_info break else: if field in ('STIME', 'ETIME'): info[vm_id][field] = field_info info[vm_id]['HISTORY_%s' % field] = field_info break info[vm_id][field] = field_info break return info
def getJobsInfo(self, vm_ids=None): """ For the list of VM IDs get detail info about the VMs and return a dictionary keyed on ID """ info = {} if vm_ids == None: #vm_ids = self.getJobIds() cmd = 'onevm list all --xml' else: cmd = 'onevm show --xml %s' % ' '.join(map(str, vm_ids)) if not isList(vm_ids): raise "Unsupported data type for vm_ids. Should be None or list" rc, stdout, stderr = iexe_cmd(cmd) cols=['ID','USER','STAT'] if self.version == 'OpenNebula 2': cols=['id','user','stat'] # Just to get the username information filtered_info = self.getJobsInfoFiltered(cols=cols) vm_id = None vm_info = {} in_history = False for line in stdout: l = line.strip() if l == '<HISTORY>': in_history = True continue if l == '</HISTORY>': in_history = False continue for field in self.fields: s_str = '<%s>' % field e_str = '</%s>' % field if l.startswith(s_str) and l.endswith(e_str): f_info = l.replace(s_str, '').replace(e_str, '') if f_info.startswith('<![CDATA['): field_info = f_info.replace('<![CDATA[', '').replace(']]>', '') if field == 'MEMORY': info[vm_id]['MEMORY_REQ(MB)'] = field_info break else: field_info = f_info if field == 'ID': vm_id = field_info info[vm_id] = {} uid = 0 #if filtered_info.has_key(vm_id): # if filtered_info[vm_id].has_key('user'): # info[vm_id]['USERNAME'] = filtered_info[vm_id]['user'] # elif filtered_info[vm_id].has_key('USER'): # info[vm_id]['USERNAME'] = filtered_info[vm_id]['USER'] #if not info[vm_id].has_key('USERNAME'): # if info[vm_id][uid] == 0: # info[vm_id]['USERNAME'] = '******' if field == 'USERNAME': break if field == 'UID': try: info[vm_id]['USERNAME'] = self.userManager.users[field_info] except: info[vm_id]['USERNAME'] = '******' if field == 'STATE': info[vm_id]['STATE_STR'] = self.vmStateMap[field_info] if field == 'LCM_STATE': info[vm_id]['LCM_STATE_STR'] = self.lcmStateMap[field_info] if field in self.historyFields: if in_history == True: if field not in ('STIME', 'ETIME'): info[vm_id]['HISTORY_%s'%field] = field_info break else: if field in ('STIME', 'ETIME'): info[vm_id][field] = field_info info[vm_id]['HISTORY_%s'%field] = field_info break info[vm_id][field] = field_info break return info