Exemplo n.º 1
0
 def insert(self, machine: Machine):
     with DbConnection(self.config) as con:
         con.execute(machines.insert().values(
             id=str(machine.id),
             lab_id=str(machine.lab_id),
             default_name=machine.default_name,
             display_name=machine.display_name))
 def get_by_id(self, lab_id) -> Lab:
     with DbConnection(self.config) as con:
         result = con.execute(labs.select().where(labs.c.id == lab_id))
         lab_row = result.fetchone()
         if lab_row is None:
             raise Exception("Lab not found")
         return Lab(*lab_row)
 def get(self, id: int) -> User:
     with DbConnection(self.config) as con:
         result = con.execute(users.select().where(users.c.id == id))
         user_row = result.fetchone()
         if user_row is None:
             raise UserNotFoundException()
         return User(*user_row)
 def get_by_lab_name(self, lab_name) -> LabTemplate:
     with DbConnection(self.config) as con:
         result = con.execute(lab_templates.select().where(
             lab_templates.c.lab_name == lab_name))
         template_row = result.fetchone()
         if template_row is None:
             raise TemplateNotFoundException()
         return LabTemplate(*template_row)
Exemplo n.º 5
0
 def get_by_id(self, worker_id):
     with DbConnection(self.config) as con:
         result = con.execute(
             workers.select().where(workers.c.id == worker_id))
         worker_row = result.fetchone()
         if worker_row is None:
             raise WorkerNotFoundException("Worker not found")
         return Worker(*worker_row)
 def get_by_username(self, username: str) -> User:
     with DbConnection(self.config) as con:
         result = con.execute(
             users.select().where(users.c.username == username).limit(1))
         user_row = result.fetchone()
         if user_row is None:
             raise UserNotFoundException()
         return User(*user_row)
 def insert(self, lab: Lab):
     with DbConnection(self.config) as con:
         con.execute(labs.insert().values(
             id=str(lab.id),
             name=lab.name,
             worker_id=lab.worker_id,
             user_id=lab.user_id,
             created_date=lab.created_date,
             lab_template_id=lab.lab_template_id,
             start_date=lab.start_date,
             expiration_date=lab.expiration_date,
             vm_count=lab.vm_count,
             description=lab.description))
Exemplo n.º 8
0
 def insert_or_update(self, worker: Worker):
     with DbConnection(self.config) as con:
         with Session(con) as session:
             vals = dict(state=worker.state,
                         host=worker.host,
                         port=worker.api_port,
                         last_updated=worker.last_update)
             ret = session.query(
                 exists().where(workers.c.id == worker.worker_id)).scalar()
             if ret:
                 session.execute(workers.update().where(
                     workers.c.id == worker.worker_id).values(**vals))
             else:
                 session.execute(workers.insert().values(
                     id=worker.worker_id, **vals))
             session.commit()
 def get_all_by_user(self, user_id):
     with DbConnection(self.config) as con:
         result = con.execute(
             labs.select().where(labs.c.user_id == str(user_id)))
         rows = result.fetchall()
         return [Lab(*r) for r in rows]
 def get_all(self):
     with DbConnection(self.config) as con:
         result = con.execute(labs.select())
         rows = result.fetchall()
         return [Lab(*r) for r in rows]
 def get_all(self) -> [LabTemplate]:
     with DbConnection(self.config) as con:
         result = con.execute(lab_templates.select())
         rows = result.fetchall()
         return [LabTemplate(*r) for r in rows]
Exemplo n.º 12
0
 def get_all_running(self):
     with DbConnection(self.config) as con:
         result = con.execute(workers.select().where(workers.c.state == 1))
         rows = result.fetchall()
         print(rows)
         return [Worker(*r) for r in rows]
Exemplo n.º 13
0
 def get_by_lab_id(self, lab_id) -> [Machine]:
     with DbConnection(self.config) as con:
         result = con.execute(
             machines.select().where(machines.c.lab_id == lab_id))
         rows = result.fetchall()
         return [Machine(*r) for r in rows]