def find_an_assignment(filter_by): # return PoolAssignments.query.filter(filter_by).all print("Filter_by is" + filter_by) machine = PoolAssignments.query.filter_by( ipaddress=text(filter_by)).first() machine_schema = PoolAssignmentsSchema() output = machine_schema.dump(machine).data return output
def delete_assignment_tag(id, data): assignment = PoolAssignments.query.get(id) tag = Tags.query.get(data['tag_id']) assignment.assignment_tag.remove(tag) assignment_schema = PoolAssignmentsSchema() output = assignment_schema.dump(assignment).data db.session.commit() return output
def get_all_assignments(): # parser = reqparse.RequestParser() # parser.add_argument('filter', help='Filter using sql where commands') # args = parser.parse_args() # if args['filter']: # print(args['filter']) # filter_by = args['filter'] # print(filter_by) # return PoolAssignments.query.filter(filter_by).all() ips = PoolAssignments.query.all() ip_schema = PoolAssignmentsSchema(many=True) output = ip_schema.dump(ips).data return output
def claim_first_free(rangeid, data): firstFree = PoolAssignments.query.filter_by(rangeid=rangeid, status='0').first() if data['machinename'] != 'string': firstFree.machinename = data['machinename'] ''' set to assigned ''' firstFree.status = '1' else: response_object = { 'status': 'fail', 'message': 'Machine name must be set.', } return response_object, 409 ''' apply the changes ''' db.session.commit() firstFreeSchema = PoolAssignmentsSchema() output = firstFreeSchema.dump(firstFree).data return output
def update_an_assignent(id, data): ''' update an IP assignment item ''' assignment = PoolAssignments.query.get(id) if data['machinename'] != 'string': assignment.machinename = data['machinename'] ''' 0 - unused, 1 - reserved, 2 - used, 3 - gateway''' if data['status'] == 0: assignment.status = data['status'] ''' delete the hostname if setting to unused ''' assignment.machinename = 'string' else: assignment.status = data['status'] ''' apply the changes ''' db.session.commit() net_schema = PoolAssignmentsSchema() output = net_schema.dump(assignment).data return output
def get_first_free(rangeid): firstFree = PoolAssignments.query.filter_by(rangeid=rangeid, status='0').first() firstFreeSchema = PoolAssignmentsSchema() output = firstFreeSchema.dump(firstFree).data return output
def get_an_assignment(id): pool = PoolAssignments.query.filter_by(id=id).first() pool_schema = PoolAssignmentsSchema() output = pool_schema.dump(pool).data return output