def createUser(new_user): user = Entity() user.PartitionKey = partition user.RowKey = new_user["email"] user.password = new_user["password"] user.firstname = new_user["firstname"] user.lastname = new_user["lastname"] user.priority = priority user.app_count = str(0) try: ts.insert_entity(table,user) return True except Exception, e: print e return False
def saveApplication(application): app = Entity() app.PartitionKey = application['partition'] #uiquely identifies a partition of entities app.RowKey = str(next(unique_sequence)) # app.RowKey = "kjlhajkdlhfjhasdnfasdkjflnasdf" app.package_type = application['apptype'] app.name = application['name'] app.reigon = application['reigon'] app.port = str(services.get_port()) app.priority = priority app.requests = str(0) app.cost = str(0) user = user_services.get_user_by_email(application['partition']) #get the current user if user is not None: app_count = int(user.app_count) #get app count an convert to int try: if app_count >= 0 : #if there is a valid amount of apps ts.insert_entity(table,app) #add new app print "new app created" app_count+=1 #increase the count user.app_count = str(app_count) #convert count back to str if user_services.update_user(application['partition'], user): #update the user count print "user app count updated" print "notifying that a new app was created..." temp = { "partition" : app.PartitionKey, "rowkey" : app.RowKey, "package_type" : app.package_type, "status" : "created" } notifying.notify_client("http://146.148.74.93:3000/update_package", temp) print " success" return app_count else : return -1 # return True except Exception, e: return -1