Exemplo n.º 1
0
def hosts_list():
    db = MysqlDb_Connection(dbconfig)
    hostsform = HostsForm()

    if hostsform.validate_on_submit():
        ip_add = hostsform.ip_address.data
        sql = "select id, ip_eth0, host_name, cpu, sysinfo, disk, cpu_count, cpu_cores, mem, \
                  os_kernel, app_name_cn, app_platform, machine_addr, app_status,description \
                  from app_hosts_info where ip_eth0 = '%s'" % str(ip_add)
        db.query(sql)
        db_result = db.fetchAllRows()
        db.close()
        return render_template('hosts/hosts_list.html',
                               db_result=db_result,
                               hostsform=hostsform)
    else:
        sql = "select id, ip_eth0, host_name, cpu, sysinfo, disk, cpu_count, cpu_cores, mem, \
                  os_kernel, app_name_cn, app_platform, machine_addr, app_status,description \
                  from app_hosts_info"

        db.query(sql)
        db_result = db.fetchAllRows()
        db.close()
        return render_template('hosts/hosts_list.html',
                               db_result=db_result,
                               hostsform=hostsform)
Exemplo n.º 2
0
def update_host():
    db = MysqlDb_Connection(dbconfig)
    hostsform = HostsForm()
    ip_add = request.form.get('ip_add')
    app_name_cn = request.form.get('app_name_cn')
    app_platform = request.form.get('app_platform')
    machine_addr = request.form.get('machine_addr')
    description = request.form.get('description')
    data = {}
    data['ip_add'] = ip_add.encode('utf-8')
    data['app_name_cn'] = app_name_cn.encode('utf-8')
    data['app_platform'] = app_platform.encode('utf-8')
    data['machine_addr'] = machine_addr.encode('utf-8')
    data['description'] = description.encode('utf-8')
    sql = "update app_hosts_info set app_name_cn = %(app_name_cn)s, \
              app_platform = %(app_platform)s, machine_addr = %(machine_addr)s, \
              description = %(description)s where ip_eth0 = %(ip_add)s"

    try:
        db.update(sql, data)
        db_result = db.fetchAllRows()
        db.commit()
    except:
        db.rollback()
    db.close()
    return render_template('hosts/hosts_list.html',
                           db_result=db_result,
                           hostsform=hostsform)
Exemplo n.º 3
0
def add_host():
    db = MysqlDb_Connection(dbconfig)
    hostsform = HostsForm()
    ip_add = request.form.get('ip_add')
    app_name_en = request.form.get('app_name_en')
    app_owner = request.form.get('app_owner')
    app_platform = request.form.get('app_platform')
    description = request.form.get('description')
    data = {}
    data['ip_add'] = ip_add.encode('utf-8')
    data['app_name_en'] = app_name_en.encode('utf-8')
    data['app_owner'] = app_owner.encode('utf-8')
    data['app_platform'] = app_platform.encode('utf-8')
    data['description'] = description.encode('utf-8')
    sql = "insert into app_hosts_info  (ip_eth0, app_name_en, owner, app_platform, description) \
              VALUE (%(ip_add)s, %(app_name_en)s, %(app_owner)s, %(app_platform)s, %(description)s)"

    try:
        db.insert(sql, data)
        db.commit()
    except:
        db.rollback()
    db.close()
    return render_template('application/paycloud_list.html',
                           hostsform=hostsform)
Exemplo n.º 4
0
def del_host():
    db = MysqlDb_Connection(dbconfig)
    hostsform = HostsForm()
    del_ip_add = request.form.get('del_ip_add')
    data = {}
    data['del_ip_add'] = del_ip_add.encode('utf-8')
    sql = "delete from app_hosts_info where ip_eth0 = %(del_ip_add)s"
    try:
        db.insert(sql, data)
        db.commit()
    except:
        db.rollback()
    db.close()
    return render_template('hosts/hosts_list.html', hostsform=hostsform)
Exemplo n.º 5
0
def paycloud():
    db = MysqlDb_Connection(dbconfig)
    hostsform = HostsForm()
    if hostsform.validate_on_submit():
        ip_add = hostsform.ip_address.data
        sql = "select id, ip_eth0, app_name_en, owner, app_platform, description from \
                  app_hosts_info where ip_eth0 = '%s'" % str(ip_add)
        db.query(sql)
        db_result = db.fetchAllRows()
        db.close()
        return render_template('application/paycloud_list.html',
                               db_result=db_result,
                               hostsform=hostsform)
    else:
        sql = "select id, ip_eth0, app_name_en, owner, app_platform, description from \
                  app_hosts_info ahi WHERE ahi.ip_eth0 LIKE '80.1.1.%' OR ahi.ip_eth0 LIKE '80.1.4.%'"

        db.query(sql)
        db_result = db.fetchAllRows()
        db.close()
    return render_template('application/paycloud_list.html',
                           hostsform=hostsform,
                           db_result=db_result)
Exemplo n.º 6
0
def ansible_add_hosts():
    # if __name__ == '__main__':
    play_book = ansible_play('/tools/ansible/test.yml')
    play_book.run()
    play_book.get_result()

    db = MysqlDb_Connection(dbconfig)
    hostsform = HostsForm()
    sql = "select id, ip_eth0, host_name, cpu, sysinfo, disk, cpu_count, cpu_cores, mem, \
                      os_kernel, app_name_cn, app_platform, machine_addr, app_status,description \
                      from app_hosts_info"

    db.query(sql)
    db_result = db.fetchAllRows()
    db.close()
    return render_template('hosts/hosts_list.html',
                           db_result=db_result,
                           hostsform=hostsform)