7 #planetlab authentication structure
8 pl_auth = {'Username': 'ssevinc@princeton.edu', # User account
9 'AuthMethod': 'password', # Type of auth this is. Can be password, session ...
10 'AuthString': 'Ss3928Ee' # the password for this account
19 cnx = DB(dbname, address, port=port, user=user, passwd=password)
22 #copy the pl db info to requester
23 def get_plDB_info(dst):
25 dst.address = 'localhost'
31 #determines the database info of a given hrn
32 #if the hrn does not exist in the tree hierarchy None is returned
33 def determine_dbinfo(hrn, tree):
34 info = tree.tree_lookup(hrn)
38 db_info = info.node_data['db_info']
39 cnx = DB(db_info.db_name, db_info.address, port = db_info.port, user = db_info.user, passwd = db_info.password)
40 tablename = db_info.table_name
41 return [cnx, tablename]
43 #convert the parameter list to query string suitable for supplying to database queries
44 #input: query type, table name and field-value pairs
45 def generate_querystr(type, table, dict):
50 for i in range(1, len(keys)):
51 str1 = str1 + ','+ keys[i]
53 for i in range(len(keys)-1):
54 if isinstance(dict[keys[i]],str):
55 str2 = str2 + "'" + dict[keys[i]] + "', "
57 str2 = str2 + str(dict[keys[i]]) + ", "
58 if isinstance(dict[keys[len(keys)-1]],str):
59 str2 = str2 + "'" + dict[keys[len(keys)-1]] + "'"
61 str2 = str2 + str(dict[keys[len(keys)-1]])
62 querystr = "INSERT INTO "+table+ "(" + str1 + ") VALUES(" + str2 + ")"
63 elif type == 'UPDATE':
66 for i in range(len(keys)-1):
68 if isinstance(dict[keys[i]],str):
69 str1 = str1 + keys[i] + " = '" + dict[keys[i]] + "', "
71 str1 = str1 + keys[i] + " = " + dict[keys[i]] + ", "
72 if keys[len(keys)-1] != 'hrn':
73 if isinstance(dict[keys[len(keys)-1]],str):
74 str1 = str1 + keys[len(keys)-1] + " = '" + dict[keys[len(keys)-1]] + "'"
76 str1 = str1 + keys[len(keys)-1] + " = '" + dict[keys[len(keys)-1]]
77 querystr = "UPDATE "+table+ " SET " + str1 + " WHERE hrn = '"+get_leaf(dict["hrn"])+"'"
78 elif type == 'DELETE':
79 querystr = "DELETE FROM "+table+" WHERE hrn = '"+get_leaf(dict["hrn"])+"'"