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 post(self): ''' User Register ''' args = self.reqparse.parse_args(strict=True) username = args.get('username') password = args.get('password') if not username or not password: return my_response( dict(result=False, message='User or Password is None', code=402)) if User.query.filter_by(username=username).first() is not None: return my_response( dict(result=False, message='A user with that username already exists', code=409)) userobj = User(username=username) userobj.hash_password(password) dbadd(userobj) log(level='info', message='Register Sucess: username=%s' % username) return my_response(dict(result=True, message='User Register 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 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 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 get(self): esxi = Esxi_Server.query.all() esxilist = [{ 'Host_Id': i.Host_Id, 'Mac_Address': i.Mac_Address, 'Net_Dev_Name': i.Net_Dev_Name, 'Physical_Cpu_Mhz': i.Physical_Cpu_Mhz, 'Physical_Cpu_Model': i.Physical_Cpu_Model, 'Physical_Memory': i.Physical_Memory, 'Physical_Cpu_Cores': i.Physical_Cpu_Cores, 'Physical_Cpu_Pkgs': i.Physical_Cpu_Pkgs, 'Logical_Cpu_Cores': i.Logical_Cpu_Cores, 'Device_type': i.Device_type, 'Device_uuid': i.Device_uuid, 'Device_Status': i.Device_Status, 'System_Ip': i.System_Ip, 'Device_model': i.Device_model, 'Datastore_Space': i.Datastore_Space, 'Datastore_Free_Space': i.Datastore_Free_Space, 'Datastore_Name': i.Datastore_Name, 'Datastore_Type': i.Datastore_Type, } for i in esxi] da = { "code": 200, "data": esxilist, "message": "Success", "result": True } return my_response(da)
def post(self): ''' ''' args = self.reqparse.parse_args(strict=True) esxi = Esxi_Server(**args) dbadd(esxi) return my_response(dict(result=True, message='NEW IDC add Success'))
def post(self): ''' ''' args = self.reqparse.parse_args(strict=True) vm = Vmware(**args) dbadd(vm) return my_response(dict(result=True, message='NEW VM add Success'))
def get(self): esxi = Vmware.query.all() vmlist = [{ 'Host_Id': i.Host_Id, 'System_Hostname': i.System_Hostname, 'System_Ip': i.System_Ip, 'Device_type': i.Device_type, 'Device_model': i.Device_model, 'System_Kernel': i.System_Kernel, 'System_Version': i.System_Version, 'System_Mac': i.System_Mac, 'Physical_Memory': i.Physical_Memory, 'System_Swap': i.System_Swap, 'Memory_Slots_Number': i.Memory_Slots_Number, 'Logical_Cpu_Cores': i.Logical_Cpu_Cores, 'Physical_Cpu_Cores': i.Physical_Cpu_Cores, 'Physical_Cpu_Model': i.Physical_Cpu_Model, 'Hard_Disk': i.Hard_Disk, 'Ethernet_Interface': i.Ethernet_Interface, 'Device_Sn': i.Device_Sn, 'System_Network_Card': i.System_Network_Card, } for i in esxi] da = { "code": 200, "data": vmlist, "message": "Success", "result": True } return my_response(da)
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 post(self): ''' ''' args = self.reqparse.parse_args(strict=True) asset = Asset(**args) dbadd(addidc) return my_response(dict(result=True, message='NEW IDC add Success'))
def post(self): ''' ''' args = self.reqparse.parse_args(strict=True) vcid = args.get('id') a = Init(vcid) if a[0]: return my_response( dict(result=True, message='Vcenter init Success')) else: if a[2] == "wantry": data = [i for i in a[1]] else: data = [{i: x} for i, x in a[1].items()] return my_response( dict(result=a[0], message='Vcenter init is ERROR', data=data))
def post(self): ''' ''' args = self.reqparse.parse_args(strict=True) vc = vCenter(**args) dbadd(vc) return my_response( dict(result=True, message='NEW vcenter add 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 put(self): ''' ''' args = self.reqparse.parse_args(strict=True) hostid = args.get('Host_Id') Vmware.query.filter_by(Host_Id=hostid).update(args) db.session.commit() return my_response(dict(result=True, message='Vmware update Success'))
def put(self): ''' ''' args = self.reqparse.parse_args(strict=True) vcid = args.get('id') del args['id'] vCenter.query.filter_by(id=vcid).update(args) db.session.commit() return my_response(dict(result=True, message='vcenter update Success'))
def get(self): ''' Get users list ''' userslist = [{ 'id': i.id, 'username': unicode.encode(i.username, "utf-8") } for i in User.query.all()] log(level='info', message='Get User List') return my_response(dict(result=True, data=userslist))
def post(self): ''' ''' args = self.reqparse.parse_args(strict=True) IDCname = args.get('Name') Address = args.get('Address') Contact = args.get('Contact') Phone = args.get('Phone') if IDCname and Address and Contact and Phone: addidc = IDC(Name=IDCname, Address=Address, Contact=Contact, Phone=Phone) dbadd(addidc) '''log''' return my_response( dict(result=True, message='NEW IDC add Success')) else: return my_response( dict(result=False, message='ID is not exist', code=410))
def post(self): ''' Add Perms ''' args = self.reqparse.parse_args() perm = Perm(**args) dbadd(perm) log(level='info', message='Perms add success') return my_response(dict(result=True, message='Perms add success'))
def get(self): ''' Get all Perms ''' permslist = [{ 'id': i.id, 'menu': i.menu, 'type': i.type, 'uri': i.uri, 'method': i.method, 'pid': i.pid } for i in Perm.query.all()] log(level='info', message='Get Perms List') return my_response(dict(result=True, data=permslist))
def get(self): ''' ''' vc = vCenter.query.all() idclist = [{ 'id': i.id, 'host': i.host, 'user': i.user, 'area': i.area } for i in vc] da = { "code": 200, "data": idclist, "message": "Success", "result": True } return my_response(da)
def get(self): ''' ''' idc = IDC.query.all() idclist = [{ 'id': i.id, 'Name': i.Name, 'Address': i.Address, 'Contact': i.Contact, 'Phone': i.Phone } for i in idc] da = { "code": 200, "data": idclist, "message": "Success", "result": True } return my_response(da)
def get(self): ''' ''' a = Esxi_Vmware.query.all() x = [{ "Host_Id": i.Host_Id, "Father_Id": i.Father_Id, "Physical_Cpu_Cores": i.Physical_Cpu_Cores, "Hard_Disk": i.Hard_Disk, "System_Hostname": i.System_Hostname, "System_Uptime": i.System_Uptime, "System_Ip": i.System_Ip, "Ethernet_Cards": i.Ethernet_Cards, "Physical_Memory": i.Physical_Memory, "Power_Status": i.Power_Status, "Guest_Status": i.Guest_Status, "HeartBeatStatus": i.HeartBeatStatus, "Show_Name": i.Show_Name, "Virtual_Disk_Nums": i.Virtual_Disk_Nums, "Tool_Status": i.Tool_Status } for i in a] return x return my_response(da)