MCPcopy Create free account
hub / github.com/adobe/Marinus / insert_ipv6_range

Method insert_ipv6_range

python3_cron_scripts/libs3/IPManager.py:841–908  ·  view source on GitHub ↗

Insert a CIDR range

(self, ip, mask, source="manual", notes=None)

Source from the content-addressed store, hash-verified

839 )
840
841 def insert_ipv6_range(self, ip, mask, source="manual", notes=None):
842 """
843 Insert a CIDR range
844 """
845
846 result = self.ip_zones_collection.find_one({"zone": ip + "/" + mask})
847
848 if result is None:
849 new_entry = {}
850 new_entry["updated"] = datetime.now()
851 new_entry["created"] = datetime.now()
852 new_entry["status"] = "unconfirmed"
853 new_entry["sources"] = [{"source": source, "updated": datetime.now()}]
854 new_entry["zone"] = ip + "/" + mask
855 if notes is None:
856 new_entry["notes"] = []
857 else:
858 new_entry["notes"] = [notes]
859
860 self._mongo_connector.perform_insert(self.ipv6_zones_collection, new_entry)
861 else:
862 found = False
863 for entry in result["sources"]:
864 if entry["source"] == source:
865 found = True
866
867 if found:
868 self.ipv6_zones_collection.update_one(
869 {"_id": ObjectId(result["_id"])},
870 {"$set": {"updated": datetime.now()}},
871 )
872 self.ipv6_zones_collection.update_one(
873 {
874 "_id": ObjectId(result["_id"]),
875 "sources.source": source,
876 },
877 {
878 "$set": {
879 "sources.$.updated": datetime.now(),
880 }
881 },
882 )
883 else:
884 sources = {"source": source, "updated": datetime.now()}
885 self.ipv6_zones_collection.update_one(
886 {"_id": ObjectId(result["_id"])}, {"$push": {"sources": sources}}
887 )
888 self.ipv6_zones_collection.update_one(
889 {"_id": ObjectId(result["_id"])},
890 {"$set": {"updated": datetime.now()}},
891 )
892
893 if notes is not None:
894 found = False
895 if "notes" in result:
896 for entry in result["notes"]:
897 if entry == notes:
898 found = True

Callers

nothing calls this directly

Calls 2

find_oneMethod · 0.80
perform_insertMethod · 0.80

Tested by

no test coverage detected