def delete(self, args): """Remove a vendor entry from the database. This will also remove all image files and schedule entries linked to this vendor. Arguments: vendor -- Name of the vendor to be removed """ checks.chk_arg_count(args, 1) vendor, = args vendor = checks.chk_vendor(vendor) self.cursor.execute(''' SELECT vendor_id FROM vendor WHERE vendor_name=?''', (vendor, )) vendorid = self.cursor.fetchone() if vendorid == None: raise ValueError('No such vendor.') self.cursor.execute(''' SELECT image_id FROM image WHERE vendor_id=?''', vendorid) result = self.cursor.fetchall() if result != None: imagelist = () for imageid in result: imagelist += imageid wildcards = ','.join(['?'] * len(imagelist)) self.cursor.execute(''' DELETE FROM host_schedule WHERE image_id IN (%s)''' % wildcards, imagelist) self.cursor.execute(''' DELETE FROM subject_schedule WHERE image_id IN (%s)''' % wildcards, imagelist) self.cursor.execute(''' DELETE FROM image WHERE vendor_id=?''', vendorid) self.cursor.execute('DELETE FROM vendor WHERE vendor_id=?', vendorid) self.connection.commit()
def add(self, args): """Add a new vendor entry to the database. Arguments: vendor -- Name of the vendor to be added """ checks.chk_arg_count(args, 1) vendor, = args vendor = checks.chk_vendor(vendor) try: self.cursor.execute(''' INSERT INTO vendor (vendor_name) VALUES (?)''', (vendor, )) self.connection.commit() except sqlite3.IntegrityError: raise ValueError('Vendor already exists.')
def add(self, args): """Add a new guest image to the database. Arguments: imagename -- Filename of the guest image imgformat -- Format of the guest image vendor -- Vendor or distributor name of the guests OS ostype -- Operating system type of the guest image bitness -- 1 for 64-bit guests, 0 for 32-bit guests bigmem -- 1 for 32-bit PAE and 64-bit guests, otherwise 0 smp -- 1 for SMP guests, otherwise 0 """ checks.chk_arg_count(args, 7) imagename, imgformat, vendor, ostype, bitness, bigmem, smp = args imagename = checks.chk_imagename(imagename) imgformat = checks.chk_imageformat(imgformat) vendor = checks.chk_vendor(vendor) ostype = checks.chk_ostype(ostype) bitness = checks.chk_bitness(bitness) bigmem = checks.chk_bigmem(bigmem) smp = checks.chk_smp(smp) if bitness == 1: bigmem = 1 self.cursor.execute(''' SELECT vendor_id FROM vendor WHERE vendor_name=?''', (vendor, )) row = self.cursor.fetchone() if row == None: raise ValueError('No such vendor.') vendorid = row[0] self.cursor.execute(''' SELECT os_type_id FROM os_type WHERE os_type_name=?''', (ostype, )) row = self.cursor.fetchone() if row == None: raise ValueError('No such OS type.') ostypeid = row[0] try: self.cursor.execute(''' INSERT INTO image (image_name, image_format, vendor_id, os_type_id, is_64bit, is_bigmem, is_smp, is_enabled) VALUES (?,?,?,?,?,?,?,?)''', (imagename, imgformat, vendorid, ostypeid, bitness, bigmem, smp, 1)) except sqlite3.IntegrityError: raise ValueError('Image already exists.') self.cursor.execute(''' INSERT INTO host_schedule (host_id, test_id, image_id) SELECT host_id, test_id, image_id FROM host LEFT JOIN image LEFT JOIN test ON test.os_type_id=image.os_type_id WHERE image_name=? AND host_id NOT NULL AND test_id NOT NULL''', (imagename, )) self.cursor.execute(''' INSERT INTO subject_schedule (subject_id, test_id, image_id) SELECT subject_id, test_id, image_id FROM subject LEFT JOIN image LEFT JOIN test ON test.os_type_id=image.os_type_id WHERE image_name=? AND subject_id NOT NULL AND test_id NOT NULL''', (imagename, )) self.connection.commit()