Skip to content

Commit

Permalink
Add deleted field
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Oct 31, 2024
1 parent 41ce20d commit d3d3750
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions IM/InfrastructureList.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _save_data_to_db(db_url, inf_list, inf_id=None):
return None

@staticmethod
def _gen_where_from_auth(auth):
def _gen_where_from_auth(auth, deleted=0):
like = ""
if auth:
for elem in auth.getAuthInfo('InfrastructureManager'):
Expand All @@ -260,12 +260,12 @@ def _gen_where_from_auth(auth):
like += "auth like '%%\"" + elem.get("username") + "\"%%'"

if like:
return "where deleted = 0 and (" + like + ")"
return "where deleted = %d and (%s)" % (deleted, like)
else:
return "where deleted = 0"
return "where deleted = %d" % deleted

@staticmethod
def _gen_filter_from_auth(auth):
def _gen_filter_from_auth(auth, deleted=0):
like = ""
if auth:
for elem in auth.getAuthInfo('InfrastructureManager'):
Expand All @@ -275,9 +275,9 @@ def _gen_filter_from_auth(auth):
like += '"%s"' % elem.get("username")

if like:
return {"deleted": 0, "auth": {"$regex": like}}
return {"deleted": deleted, "auth": {"$regex": like}}
else:
return {"deleted": 0}
return {"deleted": deleted}

@staticmethod
def _get_inf_ids_from_db(auth=None):
Expand Down
10 changes: 8 additions & 2 deletions IM/Stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _get_data(str_data, init_date=None, end_date=None):
resp['cloud_type'] = None
resp['cloud_host'] = None
resp['hybrid'] = False
resp['deleted'] = True if 'deleted' in dic and dic['deleted'] else False
for str_vm_data in dic['vm_list']:
vm_data = json.loads(str_vm_data)
cloud_data = json.loads(vm_data["cloud"])
Expand Down Expand Up @@ -104,16 +105,21 @@ def get_stats(init_date="1970-01-01", end_date=None, auth=None):
'hybrid': False,
'im_user': '__OPENID__mcaballer',
'inf_id': '1',
'deleted': False,
'last_date': '2022-03-23'}
"""
stats = []
db = DataBase(Config.DATA_DB)
if db.connect():
if db.db_type == DataBase.MONGO:
filt = InfrastructureList._gen_filter_from_auth(auth)
filt = InfrastructureList._gen_filter_from_auth(auth, 1)
if end_date:
filt["date"] = {"$lte": end_date}
res = db.find("inf_list", filt, {"id": True, "data": True, "date": True}, [('id', -1)])
else:
where = InfrastructureList._gen_where_from_auth(auth)
where = InfrastructureList._gen_where_from_auth(auth, 1)
if end_date:
where += " and date <= '%s'" % end_date
res = db.select("select data, date, id from inf_list %s order by rowid desc" % where)

for elem in res:
Expand Down
1 change: 1 addition & 0 deletions IM/swagger_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ paths:
cloud_type: 'OSCAR'
cloud_host: 'server.com'
hybrid: false
deleted: false
im_user: 'username'
inf_id: '1'
last_date: '2022-03-23'
Expand Down
1 change: 1 addition & 0 deletions doc/source/REST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ GET ``http://imserver.com/stats``
"cloud_type": "OSCAR",
"cloud_host": "server.com",
"hybrid": false,
"deleted": false,
"im_user": "username",
"inf_id": "1",
"last_date": "2022-03-23"}
Expand Down
1 change: 1 addition & 0 deletions doc/source/xmlrpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ This is the list of method names:
"cloud_type": "OSCAR",
"cloud_host": "server.com",
"hybrid": false,
"deleted": false,
"im_user": "username",
"inf_id": "1",
"last_date": "2022-03-23"}
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_im_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ def test_get_stats(self, check_auth_data, DataBase):
'cloud_type': 'OSCAR',
'cloud_host': 'sharp-elbakyan5.im.grycap.net',
'hybrid': False,
'deleted': False,
'im_user': '__OPENID__mcaballer',
'inf_id': '1',
'last_date': '2022-03-23'}]
Expand Down

0 comments on commit d3d3750

Please sign in to comment.