def criarConta(obj): cursor = conn.connection() cursor.execute('INSERT INTO Conta VALUES (?,?,?,?,?)', obj.numero, obj.tipo, obj.dono, obj.saldo, obj.status) cursor.commit() cursor.close()
def runScript(self, scripts): pub.dbg(21, 'connecting '+self.get('name')+' @ '+str(self.get('ip'))) session = conn.connection(self.get('ip')) if session.ready(): pub.dbg(25, 'writing '+self.get('name')) for x in scripts: pub.dbg(4, '>>>'+x) return session.write(scripts) return 2
def avaiable(self, obj_str=None): if self.get('ip') == None: # virtual device return True session = conn.connection(self.get('ip')) if not session.ready(): return False if obj_str!=None: result = session.expect('get '+obj_str+' oper', 'up') session.close() return result
def pagarMensal(obj): if (obj.tipo == 1): obj.saldo -= 12 else: obj.saldo -= 20 cursor = conn.connection() cursor.execute('UPDATE Conta SET saldo = ? WHERE numero = ?', obj.saldo, obj.numero) cursor.commit() cursor.close()
def fecharConta(obj): if (obj.saldo == 0): obj.status = False cursor = conn.connection() cursor.execute('UPDATE Conta SET status = 0 WHERE numero = ?', obj.numero) cursor.commit() cursor.close() return True return False
def checaNumero(obj): cursor = conn.connection() cursor.execute('SELECT numero FROM Conta WHERE numero = ?',obj.numero) reader = cursor.fetchone() x = False if reader: x = True cursor.close() return x
def pegaRegistro(obj): cursor = conn.connection() cursor.execute('SELECT * FROM Conta WHERE numero = ?',obj.numero) reader = cursor.fetchone() if reader: obj.tipo = reader[1] obj.dono = reader[2] obj.saldo = reader[3] obj.status = reader[4] cursor.close()
def isPortAvaiable(self, name, loc): p = self.query(name=name, loc=loc) n = self.query(name=p.get('loc')) obj_str="interfaces/eth/"+p.get('name') if n.get('ip') == None: # virtual device return True session = conn.connection(n.get('ip')) if not session.ready(): return False result = session.expect('show '+obj_str+' all', 'oper: up') session.close() return result
def sacar(obj, x): if (x <= obj.saldo): obj.saldo -= x cursor = conn.connection() cursor.execute('UPDATE Conta SET saldo = ? WHERE numero = ?', obj.saldo, obj.numero) cursor.commit() cursor.close() return True return False
def abrirConta(obj): if (obj.status == False): obj.status = True if (obj.tipo == 1): obj.saldo = 50 else: obj.saldo = 150 cursor = conn.connection() cursor.execute('UPDATE Conta SET status = 1, saldo = ? WHERE numero = ?', obj.saldo, obj.numero) cursor.commit() cursor.close() return True return False
def askfor_old(self, typ): if typ=='elanid': i=0 for x in self.get('elanoccupied_list'): session = conn.connection(self.get('ip')) if session.expect('get ccc/'+self.get('elan_list')[i]+' admin', 'down'): x=True continue if x==False: x=True return self.get('elan_list')[i] i+=1 return None if typ=='action_id': i=0 for x in self.get('action_list'): if self.get('action_occupied_list')[i]==False: return self.get('elan_list')[i] i+=1 return None else: assert()
from conn import connection connection()