def put(self, roleid): ''' update roles ''' abort_if_id_doesnt_exist(Role, id=roleid) args = self.reqparse.parse_args(strict=True) name = args.get('rolename') if not name: return json_message(200, 'error', 'the new rolename is None') query = db.session.query(Role) try: query.filter(Role.id == roleid).update({Role.rolename: name}) query.session.commit() except Exception: return json_message(410, 'error', 'Rolename Change Failed') log(level='info', message='Update role: name=%s id=%s' % (name, roleid)) return json_message(200, 'message', 'Rolnename Change Success')
def delete(self, roleid): ''' delete rolename ''' #prolename=request.form['rolename'] #rolename = request.json.get('rolename', None) args = self.reqparse.parse_args(strict=True) rolename = args.get('rolename') abort_if_id_doesnt_exist(Role, rolename=rolename) role = Role.query.filter_by(id=roleid).first() if rolename == role.rolename: #dbdel(Role, id=roleid) db.session.query(Role).filter_by(id=roleid).delete() db.session.commit() else: return json_message(410, 'error', 'Rolename Change Failed') log(level='warning', message='Delete role: name=%s id=%s' % (rolename, roleid)) return json_message(200, 'message', 'role Delete Success')
def put(self, userid): ''' Update user's password ''' userobj = abort_if_id_doesnt_exist(User, id=userid) if not userobj: return my_response( dict(result=False, message='ID is not exist', code=410)) args = self.reqparse.parse_args(strict=True) password = args.get('password') if not password: return my_response(dict(result=False, message='Password is None')) query = db.session.query(User) newpasswd = pwd_context.encrypt(password) try: query.filter(User.id == userid).update({User.password: newpasswd}) except Exception: log(level='warning', message='Update Userpassword Failed,userid=%s' % userid) return my_response( dict(result=False, message='Password Change Failed')) log(level='info', message='Update Userpassword: userid=%s' % userid) return my_response(dict(result=True, message='Password Change Success'))
def get(self, userid): ''' Get users list ''' userobj = abort_if_id_doesnt_exist(User, id=userid) if not userobj: return my_response( dict(result=False, message='ID is not exist', code=410)) role_list = [{ "roleid": i.id, "rolename": i.rolename } for i in userobj.role.all()] data = { 'username': userobj.username, 'id': userobj.id, 'rolelist': role_list } log(level='info', message='Get User Message: userid=%s' % userid) response = dict(result=True, data=data) return my_response(response)
def del_asset(id): ''' 删除单台服务器信息,移除至回收表,更改状态,并且停监控 ''' if request.method == 'DELETE': host = abort_if_id_doesnt_exist(Asset,host_id=id) if host: #将data新增到回收表中 data = {'idrac_user': host.idrac_user , 'logical_cpu_cores': host.logical_cpu_cores , 'idrac_userpass': host.idrac_userpass , 'system_version': host.system_version , 'idc_un': host.idc_un , 'father_ip': host.father_ip , 'models': host.models , 'system_note': host.system_note , 'device_model': host.device_model , 'hard_disk': host.hard_disk , 'create_time': host.create_time , 'father_id': host.father_id , 'device_type': host.device_type , 'ethernet_interface': host.ethernet_interface , 'physical_memory': host.physical_memory , 'metadata': host.metadata , 'idc_cabinet': host.idc_cabinet , 'system_network_card': host.system_network_card , 'system_hostname': host.system_hostname , 'system_status': host.system_status , 'memory_slots_number': host.memory_slots_number , 'system_userpass': host.system_userpass , 'device_sn': host.device_sn , 'physical_cpu_cores': host.physical_cpu_cores , 'physical_cpu_model': host.physical_cpu_model , 'system_mac': host.system_mac , 'system_ip': host.system_ip , 'group_id': host.group_id , 'system_user': host.system_user , 'system_kernel': host.system_kernel , 'idrac_ip': host.idrac_ip , 'idc_id': host.idc_id , 'system_swap': host.system_swap , 'guarantee_date': host.guarantee_date , 'offline_time': datetime.now() , "app_name": [i.app_name for i in host.cmdb_application.all()] if host.models == 'app' else host.models } #montior_stop(host.System_Ip) dbdel(Asset,host_id=id) db.session.add(Asset_offline(**data)) db.session.commit() #for i in dir(host): # data[i] = i #eval('host.%s' % i) #print(data) return task.json_message_200('Sucess'), 200 else: return task.json_message_404(),404
def delete(self, permid): ''' Delete Perms ''' permobj = abort_if_id_doesnt_exist(Perm, id=permid) if not permobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(Perm, id=permid) log(level='info', message='Delete Perm: id=%s' % permid) return my_response(dict(result=True, message='Perm Delete Success'))
def delete(self, userid): ''' Delete User ''' userobj = abort_if_id_doesnt_exist(User, id=userid) if not userobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(User, id=userid) log(level='info', message='Delete User: userid=%s' % userid) return my_response(dict(result=True, message='User Delete Success'))
def put(self, permid): ''' Update Perms ''' permobj = abort_if_id_doesnt_exist(Perm, id=permid) if not permobj: return my_response( dict(result=False, message='ID is not exist', code=410)) args = self.reqparse.parse_args() dbupdate(Perm, permid, args) log(level='info', message='Update Perm: id=%s' % permid) return my_response(dict(result=True, message='Perm update Success'))
def delete(self): ''' ''' args = self.reqparse.parse_args(strict=True) hostid = args.get('Host_Id') idcobj = abort_if_id_doesnt_exist(Asset, Host_Id=hostid) if not idcobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(Asset, Host_Id=hostid) #log(level='info', message='Delete User: userid=%s' % userid) return my_response( dict(result=True, message='Hard_Disk Delete Success'))
def delete(self): ''' ''' parser = reqparse.RequestParser() parser.add_argument('id', type=str, required=True, location='json') args = parser.parse_args() vcid = args.get('id') idcobj = abort_if_id_doesnt_exist(vCenter, id=vcid) if not idcobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(vCenter, id=vcid) #log(level='info', message='Delete User: userid=%s' % userid) return my_response(dict(result=True, message='vcenter Delete Success'))
def role(): ''' {"rolename":"admin"} ''' if request.method == 'POST': args = request.json if args: abort = abort_if_id_doesnt_exist(Role, rolename=args['rolename']) if abort: data = 'rolename is exist' return task.json_message_401(mes=data), 401 else: db.session.add(Role(**args)) db.session.commit() data = 'ok' return task.json_message_200( data=data, info='Role add ok, rolename :%s ' % args) else: return task.json_message_401(mes='please check '), 401