dcim_api.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from api.dcim.alarm_api import AlarmApi
  2. from api.dcim.login_api import LoginApi
  3. from api.dcim.assert_api import AssertApi
  4. from api.riil.utils import save_json
  5. class DcimApi(
  6. LoginApi,
  7. AlarmApi,
  8. AssertApi
  9. ):
  10. def __init__(self):
  11. super().__init__()
  12. self.headers = self.login().get('data')
  13. def save_alarm_current(self):
  14. page_index = 1
  15. alarm_list = []
  16. while True:
  17. data = self.get_alarm_current(page_index=page_index)
  18. alarm_list.extend(data.get('data', []))
  19. if page_index >= data.get('totalPage'):
  20. break
  21. page_index += 1
  22. save_json(alarm_list, "result/dcim/alarm_current.json")
  23. def save_alarm_history(self):
  24. page_index = 1
  25. alarm_list = []
  26. while True:
  27. data = self.get_alarm_current(page_index=page_index, is_history=True)
  28. alarm_list.extend(data.get('data', []))
  29. if page_index >= data.get('totalPage'):
  30. break
  31. page_index += 1
  32. save_json(alarm_list, "result/dcim/alarm_current.json")
  33. def save_capacity(self):
  34. page_index = 1
  35. capacity_list = []
  36. while True:
  37. data = self.get_capacity(page_index=page_index)
  38. capacity_list.extend(data.get('data', []))
  39. if page_index >= data.get('totalPage'):
  40. break
  41. page_index += 1
  42. save_json(capacity_list, "result/dcim/capacity.json")
  43. def save_assert(self):
  44. page_index = 1
  45. assert_list = []
  46. while True:
  47. data = self.get_assert(page_index=page_index)
  48. assert_list.extend(data.get('data', []))
  49. if page_index >= data.get('totalPage'):
  50. break
  51. page_index += 1
  52. save_json(assert_list, "result/dcim/assert.json")
  53. def save_customer_and_rack(self):
  54. page_index = 1
  55. customer_and_rack_list = []
  56. while True:
  57. data = self.get_customer_and_rack(page_index=page_index)
  58. customer_and_rack_list.extend(data.get('data', []))
  59. if page_index >= data.get('totalPage'):
  60. break
  61. page_index += 1
  62. save_json(customer_and_rack_list, "result/dcim/customer_and_rack.json")
  63. def save_customer_and_asset(self):
  64. page_index = 1
  65. customer_and_asset_list = []
  66. while True:
  67. data = self.get_customer_and_asset(page_index=page_index)
  68. customer_and_asset_list.extend(data.get('data', []))
  69. if page_index >= data.get('totalPage'):
  70. break
  71. page_index += 1
  72. save_json(customer_and_asset_list, "result/dcim/customer_and_asset.json")