应用Public API配置XenMobile Server
来源:互联网 发布:做视频短片的软件 编辑:程序博客网 时间:2024/06/06 03:44
XenMobile Server提供了XenMobile Public API for REST Services 可以对Server 进行相应的配置。鉴于平时用UI一遍一遍配置XMS还是比较费劲的。踌躇之时,在Citrix官网上看到有Public APIS可以用,经过研究,基本功能达成。
所有程序分成三类:
1. 主程序,主要用来调用各功能模块。
2. 功能模块,主要是完成Public API的功能模块中运行的所有功能,一个Feature一个模块,一个功能一个类。
3. 登陆模块,主要功能为登陆XMS, 并且获取XMS登陆Token
主程序:
#Script to add no. of local users to XMS#Instructions to use :#import all the feature mode here.from device import lock_devicefrom local_users import add_local_user#Instructions to use :#Check your xms database table, replace [18] with the devices's id that you want to lock.e.g.[18]#if you have multiple device to lock. replace [18] with data format like [1,2,3]lo = lock_device([18])lo.lock_device()#Instructions to use :#replace below user18 with the username that you want.add = add_local_user(10)for i in range(300, 300 + add.usernumber): # print(lo.post_headers['auth_token']) add.add_user("user19{0}".format(i))
Local User 模块
#Script to add no. of local users to XMS#Instructions to use :#1. Provide your server's IP, admin username and password in the #constructor parameters.import jsonfrom urllib import request,parsefrom login_logout import login_xms# login XMSlo = login_xms()lo.login()#add XMS local userclass add_local_user: def __init__(self,usernumber = 100): self.usernumber = usernumber print('===Start to add user===') def add_user(self, username="userXx1", asuseremail="userX@xmstest.net", password="1234", role="USER", groups=["MSP"], mobile="4695557854", company="CitrixTest", badpwdcount=4): ADD_USER_URL_PATH = "xenmobile/api/v1/localusersgroups" add_user_post_data_dict = { "attributes": { "badpwdcount": badpwdcount, "asuseremail": asuseremail, "company": company, "mobile": mobile }, "groups": groups, "role": role, "username": username, "password": password } add_user_url = "{0}://{1}:{2}/{3}".format(lo.protocol,lo.server_url,lo.management_port, ADD_USER_URL_PATH) add_user_post_data = json.dumps(add_user_post_data_dict).encode() add_user_request = request.Request(add_user_url, add_user_post_data,lo.post_headers) add_user_response_dict = request.urlopen(add_user_request) response_string = (add_user_response_dict.read().decode()) response_string = response_string.replace('null','None') response_string = response_string.replace('false', 'False') response_string = response_string.replace('true', 'True') response_dict = eval(response_string) if (response_dict['message'] == 'Success'): print('\033[1;31;40madded user successfully!\033[0m') returnif __name__ == "__main__": add = add_local_user(10) for i in range(300,300+add.usernumber): #print(lo.post_headers['auth_token']) add.add_user("user422{0}".format(i))
Device 模块
#Script to lock device in XMS#Instructions to use :#1. This script is based on login_logout moduleimport jsonfrom urllib import request,parsefrom login_logout import login_xms# login XMSlo = login_xms()lo.login()#lock deviceclass lock_device: def __init__(self,device_id_list = [19]): print('===Start to lock device===') self.device_id_list = device_id_list def lock_device(self): LOCK_DEVICE_URL_PATH = "/xenmobile/api/v1/device/lock" lock_device_post_data_list = self.device_id_list lock_device_url = "{0}://{1}:{2}/{3}".format(lo.protocol, lo.server_url, lo.management_port, LOCK_DEVICE_URL_PATH) lock_device_post_data = json.dumps(lock_device_post_data_list).encode() lock_device_request = request.Request(lock_device_url, lock_device_post_data, lo.post_headers) lock_device_response_dict = request.urlopen(lock_device_request) response_dict_decode = eval(lock_device_response_dict.read().decode()) if(response_dict_decode['message'] == 'Success'): print('\033[1;31;40mlock device successfully!\033[0m') returnif __name__ == "__main__": lock = lock_device([18]) lock.lock_device()
登录模块
#Script to log into XMS and obtain token#Instructions to use :#1. Provide default value for your server's protocol,host address,management port, admin username and password in below server_url_and_crentia dict.import jsonfrom urllib import request#default value for your server's protocol,host address,management port, admin username and passwordserver_url_and_crential ={ 'protocol':'https', 'server_url':'hfco0518.xs.citrix.com', 'management_port':'4443', 'admin_name':'admin', 'password':'@WSX3edc'}#device_id_list = [18]#custom value for your serverdef get(msg = "Please input value: ",default_value = "I am default value"): input_value = input(msg) if input_value=='': return default_value return input_value#Log into xms and obtain auth_tokenclass login_xms: post_headers = { 'auth_token': 'placeholder', 'content-type': 'application/json', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'} def __init__(self): print('===Start to log into xms===') self.protocol = server_url_and_crential['protocol'] self.server_url = server_url_and_crential['server_url'] self.management_port = server_url_and_crential['management_port'] self.admin_name = server_url_and_crential['admin_name'] self.password = server_url_and_crential['password'] def login(self): LOGIN_URL_PATH = "xenmobile/api/v1/authentication/login" login_post_data_dict = { 'login': self.admin_name, 'password': self.password } login_url = "{0}://{1}:{2}/{3}".format(self.protocol, self.server_url, self.management_port, LOGIN_URL_PATH) login_post_data = json.dumps(login_post_data_dict).encode() login_request = request.Request(login_url, login_post_data, self.post_headers) auth_token_dict = eval(request.urlopen(login_request).read().decode()) self.post_headers['auth_token'] = auth_token_dict['auth_token'] if('auth_token' in auth_token_dict.keys()): print('\033[1;31;40mlog into XMS successfully!\033[0m') returnif __name__ == "__main__": l = login_xms() l.login() print(l.post_headers['auth_token'])
阅读全文
0 0
- 应用Public API配置XenMobile Server
- MDM API - MobileIron, XenMobile
- 设计Public API
- 设计Public API
- Public Yum Server
- ArcGis Server Javascript API 安装配置实录
- iphonewax框架下上传应用出现non-public API usage ...... waxsim:SBApplication 解决办法
- sql server 2005 外围应用配置器
- SQL Server 外围应用配置器
- SQL Server 外围应用配置器问题
- Sql Server 2005外围应用应用配置器打不开了怎么办
- oracle-public -yum 配置使用
- FFMPEG学习【libavformat】:Public Metadata API
- ArcGIS API For Javascript之服务端配置与应用
- server no password by public key
- WebSphere Application Server 环境配置与应用部署最佳实践
- Solaris10下Ftp Server的配置与应用
- ArGoSoft Mail Server邮件服务器应用配置一览
- spring Boot上传文件报错。
- [考试]周测(2017/10/27)
- tensorboard可视化
- ubuntu16.04系统gcc下降和升级
- ListView实现下拉刷新(一)
- 应用Public API配置XenMobile Server
- 完整的支付体系
- 成员变量和类变量的区别?
- mybatis 配置错误 XML document structures must start and end within the same entity
- 一些sb题(day1下)
- S32K144 EVB之UART
- Reverse Integer算法研究
- java 基础--问题收集
- C++中ANSI、Unicode16、UTF-8字符串之间的互转