Example #1
0
    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 ''
Example #2
0
    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 ''