2
0

epc.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #!/usr/bin/python
  2. # -*- encoding:utf-8 -*-
  3. import json,pprint
  4. from prettyprinter import prettyPrinter
  5. from kscore.session import get_session
  6. if __name__ == "__main__":
  7. s = get_session()
  8. region='cn-beijing-6'
  9. epcClient = s.create_client("epc", region, use_ssl=True)
  10. # 注:如果参数名中包含.请使用JSON格式数据,如参数名 HostId.N 、 Filter.N.Name 、 Filter.N.Value.1
  11. # ------------------CreateEpc( 创建云物理主机)--------------------------
  12. # param = {
  13. # 'AvailabilityZone': 'cn-shanghai-3b',
  14. # 'ImageId': 'f38624d3-0719-4e5d-970f-cad32095a7cf',
  15. # 'HostName': 'test',
  16. # 'NetworkInterfaceMode': 'single',
  17. # 'SubnetId': '58c57698-4bf0-4af9-a984-fb152e54a866',
  18. # 'SecurityGroupId.1': '251905f6-1316-4533-a599-ac8481a9afae',
  19. # 'SecurityGroupId.2': 'fb76854b-f23a-4354-ac07-4a12aec29c71',
  20. # 'KeyId': '66182581-fe49-41d8-b2c4-1c59ba6d200a',
  21. # 'ChargeType': 'PostPaidByDay',
  22. # 'Password': 'Test@Password1234',
  23. # 'SecurityAgent': 'classic',
  24. # 'CloudMonitorAgent': 'classic',
  25. # 'Raid': 'Raid1',
  26. # 'HostType': 'CAL'
  27. # }
  28. # resp=epcClient.create_epc(**param)
  29. # print(resp)
  30. # ------------------DeleteEpc(删除云物理主机)--------------------------
  31. # param = {
  32. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87'
  33. # }
  34. # resp = epcClient.delete_epc(**param)
  35. # # # 或者
  36. # # resp = epcClient.delete_epc(HostId='a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87')
  37. # print(resp)
  38. # ------------------ModifyEpc(更新云物理主机信息)--------------------------
  39. # param = {
  40. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  41. # 'HostName': 'test1'
  42. # }
  43. # # resp = epcClient.modify_epc(**param)
  44. # # # 或者
  45. # # resp = epcClient.modify_epc(HostId='a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',HostName='test2')
  46. # print(resp)
  47. # ------------------DescribeEpcs(获取云物理主机列表信息)--------------------------
  48. # 简单查询
  49. # resp=epcClient.describe_epcs(MaxResults=7,NextToken=1)
  50. # 复杂查询
  51. param = {
  52. 'HostId.1': 'd25d1261-506b-427b-8637-2fc6f7fcc0e1',
  53. 'HostId.2': 'f3207312-8be0-44d5-af1c-96f899751711',
  54. 'Filter.1.Name': 'host-type',
  55. 'Filter.1.Value.1': 'CAL',
  56. 'Filter.1.Value.2': 'SSD',
  57. 'MaxResults': 20,
  58. 'NextToken': 1
  59. }
  60. resp=epcClient.describe_epcs(**param)
  61. print(resp)
  62. # ------------------StartEpc( 启动云物理主机)--------------------------
  63. # param = {
  64. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87'
  65. # }
  66. # resp = epcClient.start_epc(**param)
  67. # print(resp)
  68. # ------------------StopEpc (关闭云物理主机)--------------------------
  69. # param = {
  70. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87'
  71. # }
  72. # resp = epcClient.stop_epc(**param)
  73. # print(resp)
  74. # ------------------RebootEpc(重启云物理主机)--------------------------
  75. # param = {
  76. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87'
  77. # }
  78. # resp = epcClient.reboot_epc(**param)
  79. # print(resp)
  80. # ------------------ReinstallEpc(重装云物理主机)--------------------------
  81. # param = {
  82. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  83. # 'ImageId': '0b11b872-d8e6-11e8-803a-e8611f1450d8',
  84. # 'KeyId':'66182581 - fe49 - 41d8 - b2c4 - 1c59ba6d200a',
  85. # 'Password':'Test@Password1234',
  86. # 'NetworkInterfaceMode':'bond4',
  87. # 'SecurityAgent':'classic',
  88. # 'CloudMonitorAgent':'classic',
  89. # 'Raid':'Raid1'
  90. # }
  91. # resp = epcClient.reinstall_epc(**param)
  92. # print(resp)
  93. # ------------------ReinstallCustomerEpc(重装托管云物理主机)--------------------------
  94. # param = {
  95. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  96. # 'ServerIp': '127.0.0.1',
  97. # 'Path': '/linux.0'
  98. # }
  99. # resp = epcClient.reinstall_customer_epc(**param)
  100. # print(resp)
  101. # ------------------ReinstallCustomerEpc(重装托管云物理主机)--------------------------
  102. # param = {
  103. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  104. # 'ServerIp': '127.0.0.1',
  105. # 'Path': '/linux.0'
  106. # }
  107. # resp = epcClient.reinstall_customer_epc(**param)
  108. # print(resp)
  109. # ------------------CreateImage(创建自定义镜像)--------------------------
  110. # param = {
  111. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  112. # 'ImageName': 'image-test'
  113. # }
  114. # resp = epcClient.create_image(**param)
  115. # print(resp)
  116. # ------------------ModifyImage(修改自定义镜像信息)--------------------------
  117. # param = {
  118. # 'ImageId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  119. # 'ImageName': 'image-update'
  120. # }
  121. # resp = epcClient.modify_image(**param)
  122. # print(resp)
  123. # ------------------DeleteImage(删除自定义镜像)--------------------------
  124. # param = {
  125. # 'ImageId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87'
  126. # }
  127. # resp = epcClient.delete_image(**param)
  128. # print(resp)
  129. # ------------------DescribeImages(查看云物理主机镜像信息)--------------------------
  130. # param = {
  131. # 'ImageId.1': '9841bf74-1503-11ec-8427-e8611f1450d8',
  132. # 'ImageId.2':'8747e162-1503-11ec-8427-e8611f1450d8',
  133. # 'ImageId.3':'prtba3010e4-b671-40d8-8252-2b77ae292d71',
  134. # 'Filter.1.Name': 'image-type',
  135. # 'Filter.1.Value.1': 'base',
  136. # 'Filter.1.Value.2': 'private',
  137. # 'Filter.2.Name': 'disk-type',
  138. # 'Filter.2.Value.1': 'local',
  139. # }
  140. # resp = epcClient.describe_images(**param)
  141. # print(resp)
  142. # ------------------ModifyNetworkInterfaceAttribute(修改网卡信息)--------------------------
  143. # param = {
  144. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  145. # 'NetworkInterfaceId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  146. # 'SubnetId': '58c57698-4bf0-4af9-a984-fb152e54a866',
  147. # 'IpAddress':'10.10.10.10',
  148. # 'SecurityGroupId.1': '251905f6-1316-4533-a599-ac8481a9afae'
  149. # }
  150. # resp = epcClient.modify_network_interface_attribute(**param)
  151. # print(resp)
  152. # ------------------ModifyDns(修改网卡DNS信息)--------------------------
  153. # param = {
  154. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  155. # 'NetworkInterfaceId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  156. # 'DNS1': '10.10.10.10',
  157. # 'DNS2': '10.10.10.10'
  158. # }
  159. # resp = epcClient.modify_dns(**param)
  160. # print(resp)
  161. # ------------------ModifySecurityGroup(修改网卡安全组信息)--------------------------
  162. # param = {
  163. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  164. # 'NetworkInterfaceId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  165. # 'SecurityGroupId.1': '251905f6-1316-4533-a599-ac8481a9afae'
  166. # }
  167. # resp = epcClient.modify_security_group(**param)
  168. # print(resp)
  169. # ------------------DescribePhysicalMonitor(获取硬件监控信息)--------------------------
  170. # param = {
  171. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87'
  172. # }
  173. # resp = epcClient.describe_physical_monitor(**param)
  174. # print(resp)
  175. # ------------------CreateRemoteManagement(创建带外管理)--------------------------
  176. # param = {
  177. # 'PhoneNumber': '12345678901',
  178. # 'Pin': '111111',
  179. # 'Name': 'test'
  180. # }
  181. # resp = epcClient.create_remote_management(**param)
  182. # print(resp)
  183. # ------------------ModifyRemoteManagement(修改带外管理)--------------------------
  184. # param = {
  185. # 'RemoteManagementId': 'b75c6797-5562-4af4-b96f-38aeb0b4329f',
  186. # 'Name': 'test2'
  187. # }
  188. # resp = epcClient.modify_remote_management(**param)
  189. # print(resp)
  190. # ------------------DeleteRemoteManagement(删除带外管理)--------------------------
  191. # param = {
  192. # 'RemoteManagementId': 'b75c6797-5562-4af4-b96f-38aeb0b4329f'
  193. # }
  194. # resp = epcClient.delete_remote_management(**param)
  195. # print(resp)
  196. # ------------------GetDynamicCode(获取验证码)--------------------------
  197. # param = {
  198. # 'RemoteManagementId': 'b75c6797-5562-4af4-b96f-38aeb0b4329f'
  199. # }
  200. # resp = epcClient.get_dynamic_code(**param)
  201. # print(resp)
  202. # ------------------DescribeRemoteManagements(查询带外管理信息)--------------------------
  203. # param = {
  204. # 'RemoteManagementId.1': '5d6620c1-6a23-40e4-bfd6-9be8ed7afc65'
  205. # }
  206. # resp = epcClient.describe_remote_managements(**param)
  207. # print(resp)
  208. # ------------------DescribeEpcManagements(查询ILO信息)--------------------------
  209. # param = {
  210. # 'RemoteManagementId': '5d6620c1-6a23-40e4-bfd6-9be8ed7afc65',
  211. # 'DynamicCode': '123456',
  212. # 'Pin': '111111',
  213. # 'MaxResults': 20,
  214. # 'NextToken': '1'
  215. # }
  216. # resp = epcClient.describe_epc_managements(**param)
  217. # print(resp)
  218. # ------------------DescribeVpns(查询VPN信息)--------------------------
  219. # param = {
  220. # 'RemoteManagementId': '5d6620c1-6a23-40e4-bfd6-9be8ed7afc65',
  221. # 'DynamicCode': '123456',
  222. # 'Pin': '111111'
  223. # }
  224. # resp = epcClient.describe_vpns(**param)
  225. # print(resp)
  226. # ------------------ModifyHyperThreading(修改超线程)--------------------------
  227. # param = {
  228. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  229. # 'HyperThreadingStatus': 'start'
  230. # }
  231. # resp = epcClient.modify_hyper_threading(**param)
  232. # print(resp)
  233. # ------------------ResetPassword(重置密码)--------------------------
  234. # param = {
  235. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  236. # 'Password': 'Test@Passwrod'
  237. # }
  238. # resp = epcClient.reset_password(**param)
  239. # print(resp)
  240. # ------------------DescribeEpcStocks(查询云物理主机的库存)--------------------------
  241. # param = {
  242. # 'Filter.1.Name': 'host-type',
  243. # 'Filter.1.Value.1': 'CAL',
  244. # 'Filter.1.Value.1': 'SSD'
  245. # }
  246. # resp = epcClient.describe_epc_stocks(**param)
  247. # print(resp)
  248. # ------------------DescribeEpcDeviceAttributes(获取云物理设备列表信息)--------------------------
  249. # param = {
  250. # 'Filter.1.Name': 'host-type',
  251. # 'Filter.1.Value.1': 'CAL',
  252. # 'Filter.1.Value.1': 'SSD'
  253. # }
  254. # resp = epcClient.describe_epc_device_attributes(**param)
  255. # print(resp)
  256. # ------------------DescribeProcesses(查询工单信息)--------------------------
  257. # param = {
  258. # 'OperationProcessId.1': '0a8b50f2-589a-445a-913a-b095fe60a726',
  259. # 'Filter.1.Name': 'sn',
  260. # 'Filter.1.Value.1': 'test-2-46',
  261. # 'MaxResults': 20,
  262. # 'NextToken': '1'
  263. # }
  264. # resp = epcClient.describe_processes(**param)
  265. # print(resp)
  266. # ------------------CreateProcess(创建故障替换工单)--------------------------
  267. # param = {
  268. # 'HostIdentificationType': 'sn',
  269. # 'Confirm': '0',
  270. # 'Content': 'test',
  271. # 'Type': 'fix',
  272. # 'AvailabilityZone': 'cn-shanghai-3b',
  273. # 'Title': 'test',
  274. # 'ProcessId': '79cd4aa4-8373-4387-a59f-ae5b31663671',
  275. # 'Sn': 'PC0KCJXS',
  276. # 'MachineCount': '1'
  277. # }
  278. # resp = epcClient.create_process(**param)
  279. # print(resp)
  280. # ------------------DeleteProcess(删除工单信息)--------------------------
  281. # param = {
  282. # 'OperationProcessId': '0a8b50f2-589a-445a-913a-b095fe60a726',
  283. # }
  284. # resp = epcClient.delete_process(**param)
  285. # print(resp)
  286. # ------------------ReplyProcess(回复工单信息)--------------------------
  287. # param = {
  288. # 'OperationProcessId': '0a8b50f2-589a-445a-913a-b095fe60a726',
  289. # 'Remarks': 'test'
  290. # }
  291. # resp = epcClient.reply_process(**param)
  292. # print(resp)
  293. # ------------------DescribeInspections(物理机巡检信息)--------------------------
  294. # param = {
  295. # 'MaxResults': 20,
  296. # 'NextToken': '1'
  297. # }
  298. # resp = epcClient.describe_inspections(**param)
  299. # print(resp)
  300. # ------------------CreateCabinet (创建机柜)-------------------------
  301. # param = {
  302. # 'CabinetName': 'test',
  303. # 'ChargeType': 'PostPaidByDay',
  304. # 'CabinetType': 'Reserved',
  305. # 'AvailabilityZone': 'cn-shanghai-3a'
  306. # }
  307. # resp = epcClient.create_cabinet(**param)
  308. # print(resp)
  309. # ------------------DescribeCabinets(获取云物理主机托管机柜列表信息)--------------------------
  310. # param = {
  311. # 'CabinetId.1': '597f7731-0359-4604-b2cd-08586d2bcaf4',
  312. # 'MaxResults': 20,
  313. # 'NextToken': '1'
  314. # }
  315. # resp = epcClient.describe_cabinets(**param)
  316. # print(resp)
  317. # ------------------ModifySecurityGroup(修改网卡安全组信息)--------------------------
  318. # param = {
  319. # 'HostId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  320. # 'NetworkInterfaceId': 'a0e64a51-2fb9-4dd6-b5c4-0dcd8ff79b87',
  321. # 'SecurityGroupId.1': '251905f6-1316-4533-a599-ac8481a9afae'
  322. # }
  323. # resp = epcClient.modify_security_group(**param)
  324. # print(resp)