Beispiel #1
0
    def add(self, args):
        """Add a new host to the database.

        Arguments:
            hostname -- Name of the host system
            memory   -- Amount of memory available on the host system
            cores    -- Amount of CPU cores available on the host system
            bitness  -- Bitness of the host OS (0 = 32-bit, 1 = 64-bit)
        """
        checks.chk_arg_count(args, 4)
        hostname, memory, cores, bitness = args
        hostname = checks.chk_hostname(hostname)
        memory = checks.chk_memory(memory)
        cores = checks.chk_cores(cores)
        bitness = checks.chk_bitness(bitness)
        try:
            self.cursor.execute('''
                    INSERT INTO host
                    (host_name, host_memory, host_cores, is_64bit)
                    VALUES (?,?,?,?)''', (hostname, memory, cores, bitness))
        except sqlite3.IntegrityError:
            raise ValueError('Host 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 host_name=? AND test_id NOT NULL
                AND image_id NOT NULL''', (hostname, ))
        self.connection.commit()
Beispiel #2
0
    def cores(self, args):
        """Set the amount of CPU cores of a system

        Arguments:
            hostname -- Name of the host system
            cores    -- Amount of CPU cores available on the host system
        """
        checks.chk_arg_count(args, 2)
        hostname, cores = args
        hostid = self.__get_host_id(hostname)
        cores = checks.chk_cores(cores)
        self.cursor.execute('''UPDATE host SET host_cores=?
                WHERE host_id=?''', (cores, hostid))
        self.connection.commit()