示例#1
0
 def findAll(cls):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT src,dst FROM paths'):
         ret.append(Path(Host.find(row[0]), Endpoint.find(row[1])))
     c.close()
     return ret
示例#2
0
 def findByDst(cls, dst):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT src,dst FROM paths WHERE dst=?',
                          (dst.getId(), )):
         ret.append(Path(Host.find(row[0]), Endpoint.find(row[1])))
     c.close()
     return ret
示例#3
0
 def find(cls, pathId):
     c = dbConn.get().cursor()
     c.execute('''SELECT src,dst FROM paths WHERE id=?''', (pathId, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return Path(Host.find(row[0]), Endpoint.find(row[1]))
示例#4
0
 def getPath(cls, src, dst):
     if src == None:
         srcId = 0
     else:
         srcId = src.getId()
     dstId = dst.getId()
     chainId = cls.easyPath(srcId, dstId)
     if len(chainId) == 0:
         return None
     chain = []
     for i in range(0, len(chainId) - 1):
         if chainId[i] == 0:
             srcHost = None
         else:
             srcEndpoint = Endpoint.find(chainId[i])
             srcHost = srcEndpoint.getHost()
         chain.append(Path(srcHost, Endpoint.find(chainId[i + 1])))
     return chain
示例#5
0
 def findByCreds(cls, creds):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute(
             'SELECT endpoint,user FROM connections WHERE cred=?',
         (creds.getId(), )):
         ret.append(
             Connection(Endpoint.find(row[0]), User.find(row[1]), creds))
     c.close()
     return ret
示例#6
0
 def findByUser(cls, user):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute(
             'SELECT endpoint,cred FROM connections WHERE user=?',
         (user.getId(), )):
         ret.append(
             Connection(Endpoint.find(row[0]), user, Creds.find(row[1])))
     c.close()
     return ret
示例#7
0
 def find(cls, connectionId):
     c = dbConn.get().cursor()
     c.execute('SELECT endpoint,user,cred FROM connections WHERE id=?',
               (connectionId, ))
     row = c.fetchone()
     c.close()
     if row is None:
         return None
     return Connection(Endpoint.find(row[0]), User.find(row[1]),
                       Creds.find(row[2]))
示例#8
0
 def findBySrc(cls, src):
     if src == None:
         srcId = 0
     else:
         srcId = src.getId()
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT dst FROM paths WHERE src=?', (srcId, )):
         ret.append(Path(src, Endpoint.find(row[0])))
     c.close()
     return ret
示例#9
0
 def __init__(self, name):
     self.name = name
     self.id = None
     self.scope = True
     self.found = None
     c = dbConn.get().cursor()
     c.execute('SELECT id,scope,found FROM users WHERE username=?',
               (self.name, ))
     savedUser = c.fetchone()
     c.close()
     if savedUser is not None:
         self.id = savedUser[0]
         self.scope = savedUser[1] != 0
         if savedUser[2] is not None:
             from baboossh.endpoint import Endpoint
             self.found = Endpoint.find(savedUser[2])
示例#10
0
 def parseOptionsTarget(self):
     user = self.getOption("user")
     if user is None:
         users = self.getUsers(scope=True)
     else:
         users = [User.find(user.getId())]
     endpoint = self.getOption("endpoint")
     if endpoint is None:
         endpoints = self.getEndpoints(scope=True)
     else:
         endpoints = [Endpoint.find(endpoint.getId())]
     cred = self.getOption("creds")
     if cred is None:
         creds = self.getCreds(scope=True)
     else:
         creds = [Creds.find(cred.getId())]
     return (endpoints,users,creds)
示例#11
0
 def __init__(self, credsType, credsContent):
     self.credsType = credsType
     self.credsContent = credsContent
     self.obj = Extensions.getAuthMethod(credsType)(credsContent)
     self.id = None
     self.scope = True
     self.found = None
     c = dbConn.get().cursor()
     c.execute(
         'SELECT id,scope,found FROM creds WHERE type=? AND identifier=?',
         (self.credsType, self.obj.getIdentifier()))
     savedCreds = c.fetchone()
     c.close()
     if savedCreds is not None:
         self.id = savedCreds[0]
         self.scope = savedCreds[1] != 0
         if savedCreds[2] is not None:
             from baboossh.endpoint import Endpoint
             self.found = Endpoint.find(savedCreds[2])