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)
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)
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)
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)
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)
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)