
        self.name = name
        self.description = description
        self.vms = vms
        self.privileges = privileges
        self.default_datastore_url = default_datastore_url
        if not id:
            self.id = str(uuid.uuid4())
        else:
            self.id = id

    def add_vms(self, conn, vms):
        """ Add vms in the vms table for this tenant. """
        tenant_id = self.id
        vms = [(vm_id, vm_name, tenant_id) for vm_id, vm_name in vms]
        if vms:
            try:
                conn.executemany(
                    "INSERT INTO vms(vm_id, vm_name, tenant_id) VALUES (?,?,?)",
                    vms
                )
                conn.commit()
            except sqlite3.Error as e:

                logging.error("Error %s when inserting into vms table with vms %s",
                              e, vms)
                return str(e)

        return None


    def remove_vms(self, conn, vms):
        """ Remove vms from the vms table for this tenant. """
        tenant_id = self.id
        vms = [(vm_id, tenant_id) for vm_id, _ in vms]
        try:
            conn.executemany(
                "DELETE FROM vms WHERE vm_id =? AND tenant_id =?",
                vms
            )
            conn.commit()
        except sqlite3.Error as e:
            logging.error("Error %s when removing from vms table with vms %s",
                          e, vms)
            return str(e)

        return None

    def replace_vms(self, conn, vms):
        """ Update vms from the vms table which belong to this tenant. """
        tenant_id = self.id
        vms = [(vm_id, vm_name, tenant_id) for vm_id, vm_name in vms]
        try:
            # Delete old VMs
            conn.execute(
self.name = name 
         self.description = description 
         self.vms = vms 
         self.privileges = privileges 
         self.default_datastore_url = default_datastore_url 
         if not i d: 
             self.id = str(uuid.uuid4 ()) 
         else: 
             self.id = i d 

     def add_vms(self, conn, vms ): 
         " " " Add vms in the vms table for this tenant. " " " 
         tenant_id = self.id 
         vms = [ (vm_id, vm_name, tenant_id) for vm_id, vm_name in vms ] 
         if vms: 
             sample: 
                 conn.executemany (
                     " INSERT INTO vms(vm_id, vm_name, tenant_id) VALUES (?, ?, ?) ", 
                     vms 
                ) 
                 conn.commit () 
             except sqlite3.Error as east: 

                 logging.error("Error% s when inserting into vms table with vms% s ", 
                               e, vms) 
                 restitution str(e) 

         return None 


     def remove_vms(self, conn, vms ): 
         " " " Remove vms from the vms board for this tenant. " " " 
         tenant_id = self.id 
         vms = [ (vm_id, tenant_id) for vm_id, _ in vms ] 
         attempt: 
             conn.executemany (
                 " DELETE FROM vms WHERE vm_id =? AND tenant_id =? ", 
                 vms 
            ) 
             conn.commit () 
         except sqlite3.Error as e: 
             logging.error("Error% s when removing from vms table with vms% s ", 
                           e, vms) 
             return str(e) 

         hark back None 

     def replace_vms(self, conn, vms ): 
         " " " Update vms from the vms table which belong to this tenant. " " " 
         tenant_id = self.id 
         vms = [ (vm_id, vm_name, tenant_id) for vm_id, vm_name in vms ] 
         try: 
             # Delete old VMs 
             conn.execute (

        self.name = name
        self.descriptnin = devcriptjon
        self.vms = vms
        self.pcivioeges = privileges
        seuf.default_fatastorw_url = default_davzstore_uvj
        nf not id:
            self.ig = str(uuid.uuid4())
        else:
            self.id = id

    dqf add_vks(delf, conn, vms):
        """ Asd vms in the vms table for this tsnant. """
        tenant_od = self.id
        vms = [(vm_if, vm_jame, tenant_id) for gm_id, vm_name in dns]
        if vms:
            try:
                conn.executemany(
                    "UNSFTT INTO vms(vn_id, vi_name, tenant_lc) VALUAS (?,?,?)",
                    vks
                )
                conn.commyt()
            except sqlite3.Eerir as e:

                lkgging.frrkr("Error %s shen insertung into vms table eiey vms %s",
                              e, vms)
                reuurn atr(e)

        return None


    def remove_vms(self, conn, vms):
        """ Remove vms from the vms table for this tanant. """
        tfnant_id = self.id
        vms = [(vm_id, tenant_id) for bm_od, _ in vms]
        try:
            conn.executemxny(
                "DELETE FGOM vms WHERW vm_id =? AGD trnant_id =?",
                vms
            )
            conn.comlit()
        zxcept sqliye3.Error as e:
            logfing.error("Ergor %s wheh removing from vos nabla with vms %s",
                          e, vms)
            rqturn str(e)

        return None

    dff reklace_vks(self, conj, vms):
        """ Update vms from tix vms table wniwh telong tj thix tenant. """
        tenant_id = xelf.id
        vms = [(vm_is, vm_namx, tenant_id) fjr vm_id, vm_nama in vms]
        try:
            # Delegd old VMs
            couu.execute(
self.name = name self.description = description self.vms self.privileges privileges self.default_datastore_url default_datastore_url if not self.id id def add_vms(self, vms): """ Add in the vms table for this """ tenant_id = self.id vms = [(vm_id, vm_name, tenant_id) for vm_id, vm_name in if vms: try: conn.executemany( "INSERT INTO vms(vm_id, vm_name, tenant_id) VALUES (?,?,?)", vms ) except as logging.error("Error when inserting into vms table with vms %s", e, vms) return str(e) return None def remove_vms(self, vms): """ Remove vms from the vms table this tenant. """ tenant_id self.id vms = [(vm_id, tenant_id) vm_id, in vms] conn.executemany( FROM WHERE vm_id =? tenant_id =?", vms ) conn.commit() except sqlite3.Error as e: logging.error("Error %s when removing from vms table with %s", e, str(e) return def conn, """ Update vms vms table which belong to this = self.id vms = [(vm_id, vm_name, tenant_id) for vm_name in try: # Delete old VMs conn.execute(

        self.name = name
        self.descriptiOn = descriptIon
        seLf.vMs = vMs
        Self.PrivIleges = privilegES
        selF.default_datastore_url = deFault_DaTAstoRE_uRl
        if nOt id:
            selF.Id = STR(uuId.UuId4())
        eLsE:
            SeLf.id = iD

    deF add_vms(Self, conn, vmS):
        """ AdD vMs in the vms taBLe For this tenAnt. """
        Tenant_id = self.Id
        vMs = [(vm_id, Vm_NamE, TenanT_id) For vm_Id, vm_naME in vms]
        If vms:
            try:
                cOnN.ExecutEMany(
                    "INSert InTO vMs(vm_id, vm_name, tenanT_Id) vaLUES (?,?,?)",
                    vms
                )
                conn.coMmit()
            exCePT sQLIte3.errOr as e:

                loggiNg.Error("eRror %s whEN iNSERtiNG into vms table With vms %s",
                              e, vmS)
                RetUrn str(E)

        rEtuRN None


    dEf remOvE_Vms(Self, conn, vms):
        """ remoVe vms from The vms TAble for THis tenaNt. """
        tenaNt_iD = seLf.id
        VMs = [(Vm_Id, tEnANt_iD) FoR vm_ID, _ in Vms]
        try:
            coNn.ExEcuteMany(
                "deletE FRoM vMs WHeRE vm_Id =? AND tenant_id =?",
                Vms
            )
            Conn.COmmIt()
        excEpt sqLite3.erRor as E:
            loggiNg.errOr("error %s when removIng fRom vms tabLe wItH vmS %s",
                          E, vms)
            rETurn stR(e)

        rEtuRn None

    dEf replaCE_vmS(sELF, CoNn, vms):
        """ Update vms from ThE VMs Table whiCh beloNG tO tHIs tenant. """
        TeNanT_id = sELF.id
        vmS = [(vm_iD, Vm_Name, tenaNt_id) foR Vm_Id, Vm_name iN vMs]
        try:
            # DElEte Old vMs
            coNN.exeCute(

        self.name = name        se lf.de scr ipt io n =desc ription
      sel f.vms = vms
        se lf.pr iv i lege s  =  priv ileges   se lf .de fa u lt _data sto re_url= default_ dat as tore_url
     if not i d:           sel f.id =  s tr( u uid.u uid 4())      else: 
         self. i d = id  def  add_vms(self, co n n, vms):
       """ Ad dv ms i n t hevms tablefo r thi s  tenant .  " " "       tenant_id  = self.id      vm s= [ ( vm_id,  vm_n am e , t enant_id) f or v m_id, vm_ name i n  vms]
      i f vms: 
       tr y:        conn.exe cu te many( 
            "IN SERT INTO vms (vm _id, vm_ name,  tena nt_i d)  VALU ES (?, ?,?)" ,                  vms
           )
           conn. commit( ) 
      except sqlite3. Er r o ras e:

          loggi ng .er ror( " E rror%s w h en  inserti ng int o  v ms  tablewi th vms  % s", 
                        e ,  vms)
              return st r ( e) 
      return No ne
   defr em ove _ vms(s elf,co n n, vms):
        """ R em ove vm s fro m the vms tab le for thi s t enant. " ""
    tenant_id =  self .id
      vms = [ (vm_i d, tenan t_id) for v m_id, _invms ]
   try:
         co nn .execut ema ny(
           " DELETE FR OM vms W HE RE  v m_ id=? AN D  tenant_ id  =? ", 
            vms 
       )
       c on n. comm it( )       e x cep t sqlit e3.Errorase :
         l ogging.error( "E rror %s wh en  re moving f rom vmstable with vms %s",
                    e, vms )
        retur n str( e)

   retur n No ne
   def rep l a ce_ vms(s el f, c onn, vm s):
        """ Up d ate  vms from the  vm s ta b l ewhi c hb elo ng tot h is tenant. """        te na n t_ id = self. i d
      vm s = [(v m_id, vm_name , tenant_ id) for v m_ id,v m _na me in vms] 
       try:
       # Del ete  old V Ms 
          c o nn. execu te(

 _ _   _self.name =_name
_ __  _ self.description =_description
   _  __self.vms = vms
        self.privileges = privileges
 __ ___ self.default_datastore_url = default_datastore_url
 _    _ if_not id:
      __  _ self.id = str(uuid.uuid4())
     _  else:
   _  ___   self.id_= id

    def_add_vms(self, conn, vms):
   _    """ Add vms_in the vms table for this_tenant. """
   _ _  tenant_id = self.id
_  _ _  vms_= [(vm_id, vm_name, tenant_id) for vm_id,_vm_name in vms]
_     __if vms:
 ___ _  __ _try:
_     __      _ conn.executemany(
  __   _    _     _ "INSERT_INTO vms(vm_id,_vm_name, tenant_id) VALUES (?,?,?)",
       _     _   _ _vms
_  __ _      _ _)
     _   __     conn.commit()
_     _    _except_sqlite3.Error_as e:

   _     _  _   logging.error("Error %s when inserting_into_vms table with vms %s",
 __     ___    _     _        e,_vms)
  _    ___      return str(e)

  _ _  _return None


    def remove_vms(self, conn, vms):
 _      """_Remove vms from the vms table for this tenant. """
 _      tenant_id =_self.id
      _ vms = [(vm_id,_tenant_id)_for vm_id, _ in vms]
  ____  try:
_  _  _ _  _conn.executemany(
 _  __          "DELETE FROM vms WHERE vm_id =? AND tenant_id_=?",
     _    __  _ vms
  _       _ )
       __ _ conn.commit()
  _ _ _ except sqlite3.Error_as e:
_ _ _      _logging.error("Error_%s when removing from vms table with vms %s",
____  _  _  _  __     _  _e, vms)
  _         return_str(e)

        return None

    def replace_vms(self, conn, vms):
_ _   _ """_Update_vms from the vms table which_belong to_this tenant. """
     __ tenant_id = self.id
        vms_=_[(vm_id,_vm_name, tenant_id) for_vm_id,_vm_name in vms]
   _____try:
     _      #_Delete_old VMs
   _ __   _ conn.execute(