def delete(cls, where=None, params=None): sql = 'DELETE FROM `%s`' % cls._tbl if not where: return db.update(sql) sql += ' WHERE ' + where return db.update(sql, params)
def bind_host_id(cls, group_id, host_id): if not Host.get(host_id): return 'no such host_id' if cls.exists('grp_id = %s and host_id = %s', [group_id, host_id]): return 'already existent' if db.update('insert into grp_host(grp_id, host_id) values(%s, %s)', [group_id, host_id]) <= 0: return 'failure' return ''
def bind(cls, group_id, hostname): h = Host.read('hostname = %s', [hostname]) if not h: return 'no such host' if cls.exists('grp_id = %s and host_id = %s', [group_id, h.id]): return 'already existent' if db.update('insert into grp_host(grp_id, host_id) values(%s, %s)', [group_id, h.id]) <= 0: return 'failure' return ''
def bind(cls, group_id, hostname): h = Host.read('hostname = %s', [hostname]) if not h: Host.create(hostname) h = Host.read('hostname = %s', [hostname]) if not h: return 'host auto add failed' if cls.exists('grp_id = %s and host_id = %s', [group_id, h.id]): return 'already existent' if db.update('insert into grp_host(grp_id, host_id) values(%s, %s)', [group_id, h.id]) <= 0: return 'failure' return ''
def update(cls, clause=None, params=None): sql = 'UPDATE `%s` SET %s' % (cls._tbl, clause) return db.update(sql, params)
def delete_one(cls, pk=None): sql = 'DELETE FROM `%s` WHERE %s = %%s' % (cls._tbl, cls._id) return db.update(sql, [pk])