ipam.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from api.riil.utils import call_api
  2. class IpamApi:
  3. def apply_ip(self, segmentId, _openCLIENT="RIIL", mac=None, user=None, devIp=None, ifIdx=None, department=None):
  4. """
  5. 申请IP接口
  6. """
  7. endpoint = "/ipam/applyIpmacList"
  8. params = {
  9. "segmentId": segmentId,
  10. "mac": mac,
  11. "user": user,
  12. "devIp": devIp,
  13. "ifIdx": ifIdx,
  14. "department": department,
  15. "_openCLIENT": _openCLIENT
  16. }
  17. # Remove any None values
  18. params = {key: value for key, value in params.items() if value is not None}
  19. return call_api(endpoint, method="POST", params=params)
  20. def delete_by_ip(self, ip, _openCLIENT="RIIL"):
  21. """
  22. 根据IP删除基准表记录
  23. """
  24. endpoint = "/ipam/daleteByIp"
  25. params = {
  26. "ip": ip,
  27. "_openCLIENT": _openCLIENT
  28. }
  29. return call_api(endpoint, method="POST", params=params)
  30. def get_all_subnet_info(self, _openCLIENT="RIIL"):
  31. """
  32. 获取所有子网列表信息
  33. """
  34. endpoint = "/ipam/getIpmacAllSegmentList"
  35. params = {
  36. "_openCLIENT": _openCLIENT
  37. }
  38. return call_api(endpoint, method="POST", params=params)
  39. def get_ipmac_list(self, ip, _openCLIENT="RIIL", devIp=None, tableFlag=None):
  40. """
  41. 根据IP查询基准表IPMAC列表
  42. """
  43. endpoint = "/ipam/getIpmacList"
  44. params = {
  45. "ip": ip,
  46. "devIp": devIp,
  47. "tableFlag": tableFlag,
  48. "_openCLIENT": _openCLIENT
  49. }
  50. # Remove any None values
  51. params = {key: value for key, value in params.items() if value is not None}
  52. return call_api(endpoint, method="POST", params=params)
  53. def get_ipmac_location_list(self, _openCLIENT="RIIL"):
  54. """
  55. 获取网段列表信息
  56. """
  57. endpoint = "/ipam/getIpmacLocationList"
  58. params = {
  59. "_openCLIENT": _openCLIENT
  60. }
  61. return call_api(endpoint, method="POST", params=params)
  62. def get_ipmac_segment_list(self, locationId, _openCLIENT="RIIL"):
  63. """
  64. 根据网段获取可用子网列表信息
  65. """
  66. endpoint = "/ipam/getIpmacSegmentList"
  67. params = {
  68. "locationId": locationId,
  69. "_openCLIENT": _openCLIENT
  70. }
  71. return call_api(endpoint, method="POST", params=params)
  72. def modify_ipmac_info(self, ip, _openCLIENT="RIIL", mac=None, user=None, devIp=None, ifIdx=None, department=None):
  73. """
  74. 修改IP信息
  75. """
  76. endpoint = "/ipam/modifyIpmacInfo"
  77. params = {
  78. "ip": ip,
  79. "mac": mac,
  80. "user": user,
  81. "devIp": devIp,
  82. "ifIdx": ifIdx,
  83. "department": department,
  84. "_openCLIENT": _openCLIENT
  85. }
  86. # Remove any None values
  87. params = {key: value for key, value in params.items() if value is not None}
  88. return call_api(endpoint, method="POST", params=params)