#!/usr/bin/python
#-*-encoding:utf-8-*-
#author: asher
#date: 20160429 on train D909

# this scripts useed for add server ip to webvirtmgr 
# if not , each server must add by website,it's too slow, and very not interesting.
# use this , it's make you feel very happy

import sqlite3

try:
    conn = sqlite3.connect('../webvirtmgr.sqlite3')
    cur = conn.cursor()
    print "Input the server ip address like:"
    ips = raw_input("Ips 172.23.32:").strip()
    ips1 = int(raw_input("Input start last ip num: 1:>").strip())
    ips2 = int(raw_input("Input end ip num: 100:>").strip())
#    jifang = str(raw_input("DataCenter like:jxq:>").strip())
#    login = str(raw_input("User:admin or others:>").strip())
#    password = str(raw_input("Password:>").strip())
    while True:
        if ips1 <= ips2:
            ips1 = str(ips1)
            newip = ips + "." + ips1
#            jifang1 = jifang + "_" + newip
            print "Del %s into database\n" % newip
            cur.execute("delete from servers_compute where hostname == '%s'" % newip)
            ips1 = int(ips1)
            ips1 += 1
            conn.commit()
        else:
	    break
finally:
	allservers = cur.execute("select id,name,hostname,login,type from servers_compute").fetchall()
	for i in allservers:
	    print i
	conn.close()
