-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpen5GS_subscriber.py
More file actions
66 lines (53 loc) · 2.11 KB
/
Open5GS_subscriber.py
File metadata and controls
66 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#This script was taken by: https://github.com/open5gs/open5gs/blob/main/misc/db/python/Open5GS.py
import mongo
import pymongo
import random
import bson
class Open5GS:
def __init__(self, server, port):
self.server = server
self.port = port
def GetSubscribers(self):
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
mydb = myclient["open5gs"]
mycol = mydb["subscribers"]
subs_list = []
for x in mycol.find():
print(x)
subs_list.append(x)
pass
return subs_list
def GetSubscriber(self, imsi):
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
mydb = myclient["open5gs"]
mycol = mydb["subscribers"]
myquery = { "imsi": str(imsi)}
mydoc = mycol.find(myquery)
for x in mydoc:
print(x)
return x
def AddSubscriber(self, sub_data):
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
mydb = myclient["open5gs"]
mycol = mydb["subscribers"]
x = mycol.insert_one(sub_data)
print("Added subscriber with Inserted ID : " + str(x.inserted_id))
return x.inserted_id
def UpdateSubscriber(self, imsi, sub_data):
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
mydb = myclient["open5gs"]
mycol = mydb["subscribers"]
print("Attempting to update IMSI " + str(imsi))
newvalues = { "$set": sub_data }
myquery = { "imsi": str(imsi)}
x = mycol.update_one(myquery, newvalues)
print(x)
return True
def DeleteSubscriber(self, imsi):
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
mydb = myclient["open5gs"]
mycol = mydb["subscribers"]
myquery = { "imsi": str(imsi)}
x = mycol.delete_many(myquery)
print(x.deleted_count, " subscribers deleted.")
return x.deleted_count