def get(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) access_token = data['access_token'][0] user = check_token(access_token) if 'processor_id' in data: processor = ComputeNodes.objects(owner=user['email'], id=data['processor_id']) if processor != None: for p in processor: data = { "name": p.name, "id": str(p.id), "key": p.key, } else: data = {'error': 'error'} encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def get(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) access_token = data['access_token'][0] check = check_token(access_token) check_user = MyUsers.objects(email=check['email']).first() if check_user['permission'] == 'admin': nodes = ComputeNodes.objects() c_node = [] for c in nodes: c_node.append({ "name": c.name, "id": str(c.id), "online": c.online, "memory": { "used": c.memory.used, "free": c.memory.free, "total": c.memory.total }, "disk": { "used": c.disk.used, "free": c.disk.free, "total": c.disk.total }, "cpu": { "used_per_cpu": c.cpu.used_per_cpu, "used": c.cpu.used }, "owner": c.owner, "create_date": str(c.create_date), "update_date": str(c.update_date), "memory_used_percent": int(c.memory.used / c.memory.total * 100), "disk_used_percent": int(c.disk.used / c.disk.total * 100), }) data = {"data": c_node} encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")} else: encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def post(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) access_token = data['access_token'][0] user = check_token(access_token) lettersAndDigits = string.ascii_letters + string.digits key = ''.join(random.choice(lettersAndDigits) for i in range(10)) compute = ComputeNodes(name=data['name'], owner=user['email'], key=key) compute.save() compute = ComputeNodes.objects(owner=user['email'], name=data['name']).first() com_id = str(compute.id) for c_id in data['cameras']: camera = Cameras.objects(id=c_id).first() camera.update(set__compute_id=com_id) encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def post(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) id = data['id'] lettersAndDigits = string.ascii_letters + string.digits key = ''.join(random.choice(lettersAndDigits) for i in range(10)) compute = ComputeNodes.objects(id=id).first() compute.update(set__key=key) data = {"key": key, "id": id} encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def delete(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) access_token = data['access_token'][0] user = check_token(access_token) processor_id = data['processor_id'] processor = ComputeNodes.objects(id=processor_id).first() cameras = Cameras.objects(owner=user['email'], compute_id=processor_id) for camera in cameras: camera.update(set__compute_id='None') processor.delete() encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def get(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) access_token = data['access_token'][0] if len(access_token) < 5: access_token = data['access_token'] user = check_token(access_token) user = MyUsers.objects(email=user['email']).first() try: nodes = ComputeNodes.objects(owner=user['email']) c_node = [] for c in nodes: c_node.append({ "name": c.name, "id": str(c.id), "online": c.online, "memory": { "used": c.memory.used, "free": c.memory.free, "total": c.memory.total }, "disk": { "used": c.disk.used, "free": c.disk.free, "total": c.disk.total }, "cpu": { "used_per_cpu": c.cpu.used_per_cpu, "used": c.cpu.used }, "update_date": str(c.update_date), }) data = {"compute_node": c_node} except: data = {"processors": " ", "compute_node": " "} encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def put(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) access_token = data['access_token'][0] user = check_token(access_token) compute = ComputeNodes.objects(id=data['id'], owner=user['email']).first() compute.update(set__name=data['name']) com_id = str(compute.id) cameras = Cameras.objects(owner=user['email'], compute_id=data['id']) for camera in cameras: camera.update(set__compute_id='None') for c_id in data['cameras']: camera = Cameras.objects(id=c_id).first() camera.update(set__compute_id=com_id) print(c_id) return {'status': "200"}
def put(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) name = data['name'] owner = data['owner'] key = data['key'] compute = ComputeNodes.objects(name=name, owner=owner, key=key).first() compute.update(set__online=data['online']) compute.update(set__update_date=datetime.now()) compute.update(set__memory__used=data['memory']['used']) compute.update(set__memory__free=data['memory']['free']) compute.update(set__memory__total=data['memory']['total']) compute.update(set__disk__used=data['disk']['used']) compute.update(set__disk__free=data['disk']['free']) compute.update(set__disk__total=data['disk']['total']) compute.update(set__cpu__used=data['cpu']['used']) compute.update(set__cpu__used_per_cpu=data['cpu']['used_per_cpu']) encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}
def get(self): p = request.form['data'] data = p.encode('utf8') data = jwt.decode(data, salt, algorithms=['HS256']) encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) access_token = data['access_token'][0] if len(access_token) < 5: access_token = data['access_token'] user = check_token(access_token) user = MyUsers.objects(email=user['email']).first() # if user['permission'] == 'admin': # nk = nokkhum_client() # processors = nk.admin.processors.list() # compute_nodes = nk.admin.compute_nodes.list() # nodes = [] # for c in compute_nodes: # nodes.append(nk.admin.compute_nodes.get(c.id)) # ps = [] # for p in processors: # ps.append({ # "name":p.name, # "id":p.id, # "compute_id":p.processor_operating['compute_node']['id'] # }) # processors = Cameras.objects(owner=user['email']) # for p in processors: # ps.append({ # "name":p.name, # "id":str(p.id), # "compute_id":p.compute_id, # "group_name":p.group_name # }) # c_node = [] # for c in nodes: # c_node.append({ # "name": c.name, # "id": c.id, # "online":c.online, # "memory":{ # "used":c.memory.used, # "free":c.memory.free, # "total":c.memory.total # }, # "disk":{ # "used":c.disk.used, # "free":c.disk.free, # "total":c.disk.total # }, # "cpu":{ # "used_per_cpu":c.cpu.used_per_cpu, # "used":c.cpu.used # } # }) # nodes = ComputeNodes.objects(owner=user['email']) # for c in nodes: # c_node.append({ # "name": c.name, # "id": str(c.id), # "online":c.online, # "memory":{ # "used":c.memory.used, # "free":c.memory.free, # "total":c.memory.total # }, # "disk":{ # "used":c.disk.used, # "free":c.disk.free, # "total":c.disk.total # }, # "cpu":{ # "used_per_cpu":c.cpu.used_per_cpu, # "used":c.cpu.used # } # }) # data = { # "processors": ps, # "compute_node": c_node # } # else: try: processors = Cameras.objects(owner=user['email']) ps = [] for p in processors: ps.append({ "name": p.name, "id": str(p.id), "compute_id": p.compute_id, "group_name": p.group_name, }) nodes = ComputeNodes.objects(owner=user['email']) c_node = [] for c in nodes: c_node.append({ "name": c.name, "id": str(c.id), "online": c.online, "key": c.key, "memory": { "used": c.memory.used, "free": c.memory.free, "total": c.memory.total }, "disk": { "used": c.disk.used, "free": c.disk.free, "total": c.disk.total }, "cpu": { "used_per_cpu": c.cpu.used_per_cpu, "used": c.cpu.used } }) data = {"processors": ps, "compute_node": c_node} except: data = {"processors": " ", "compute_node": " "} encoded_jwt = jwt.encode(data, salt, algorithm='HS256', headers={'message': 'OK'}) return {"test": encoded_jwt.decode("utf-8")}