예제 #1
0
    def _set_pg_mon_conn(self):
	try:
	    self.pg_mon_conn=psycopg2.connect(settings.custom_dsn('pg_mon'))
	except Exception as e:
	    logger.critical("Cannot connect to pg_mon DB: {0}".format(e))
	    return False
	logger.debug("Successfully connected to pg_mon database")
	return True
예제 #2
0
args=parser.parse_args()

ip_regexp = r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
hostname_regexp = r"^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$";

ip_address_pattern=re.compile(ip_regexp)
hostname_pattern=re.compile(hostname_regexp)

if not re.match(ip_address_pattern,args.ip_address):
    print "Wrong IP address format"
    sys.exit(1)
if not re.match(hostname_pattern,args.hostname):
    print "Wrong hostname format"


conn=psycopg2.connect(settings.custom_dsn('pg_mon'))
hc=hostcluster.HostCluster(conn)

string="hc.add('"+args.ip_address+"','"+args.hostname+"'"

del(args.hostname)
del(args.ip_address)

for a,v in vars(args).iteritems():
    if v:
	string += ","+a+"="
	if type(v) is str:
	    string += "'"+str(v)+"'"
	elif type(v) is int or bool:
	    string+=str(v)
string+=")"
예제 #3
0
parser.add_argument('-s',nargs=1,choices=['file','SQLite'],default='file',dest='source',
    help="Source for updates. SQLite is not supported currently")
parser.add_argument('-v','--verbose',action='store_true',default=False,help="Show additional info on terminal")
parser.add_argument('-l','--last',dest='last_applied',action='store_true',default=False,
    help="Show last applied update number and exit")

args=parser.parse_args()




if args.install:
    args.dry_run=True

try:
    conn=psycopg2.connect(settings.custom_dsn('db_handler_1'))
except Exception as e:
    print "ERROR! Cannot connect to database {0}".format(e)
    sys.exit(1)


db_st=DbState(conn)

installed=db_st.get_installed()
#last_applied=db_st.get_last_applied()

#if last_applied == -1:
#    conn.close()
#    sys.exit()