def read_all(self): ret = collections.OrderedDict() try: with open(self.db, 'r') as f: for l in f: if l.lstrip().startswith('#'): continue if len(l.split()) != 2: continue _id = int(l.split()[0]) f = l.split()[1] ret[_id] = f except IOError: # do nothing, because user first run this script, file has not # been created return ret except Exception as e: LOG.error('open fuel datebase error: %s', fmt_excep_msg(e)) return ret
def read_all(self): ret = collections.OrderedDict() try: with open(self.db, 'r') as f: for l in f: if l.lstrip().startswith('#'): continue if len(l.split()) != 2: continue _id = int(l.split()[0]) f = l.split()[1] ret[_id] = f except IOError: # do nothing, because user first run this script, file has not # been created return ret except Exception as e: LOG.error('open fuel datebase error: %s' % fmt_excep_msg(e)) return ret
def port_result_to_json(out, fmt='json'): detail = dict() if fmt == 'json': _out = json.loads(out) detail = dict(map(lambda d: (d['Field'], d['Value']), _out)) return detail elif fmt == 'shell': """ admin_state_up="True" allowed_address_pairs="" binding:host_id="node-5.eayun.com" """ for l in out.split('\n'): p = re.compile(r'(.*)="(.*)"') try: ret = p.match(l).groups() detail[ret[0]] = ret[1] except Exception as e: LOG.error('failed to get port message: %s' % fmt_excep_msg(e)) return detail