ipam.py 3.1 KB

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