mirror of
https://github.com/veops/cmdb.git
synced 2025-08-07 12:10:31 +08:00
add command init-cache
This commit is contained in:
24
api/commands/click_cmdb.py
Normal file
24
api/commands/click_cmdb.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
|
||||
import json
|
||||
|
||||
import click
|
||||
from flask.cli import with_appcontext
|
||||
|
||||
import api.lib.cmdb.ci
|
||||
from api.extensions import rd
|
||||
from api.models.cmdb import CI
|
||||
|
||||
|
||||
@click.command()
|
||||
@with_appcontext
|
||||
def init_cache():
|
||||
cis = CI.get_by(to_dict=False)
|
||||
for ci in cis:
|
||||
m = api.lib.cmdb.ci.CIManager()
|
||||
ci = m.get_ci_by_id_from_db(ci.id, need_children=False, use_master=False)
|
||||
if rd.get([ci.id]):
|
||||
return
|
||||
rd.delete(ci.id)
|
||||
rd.add({ci.id: json.dumps(ci)})
|
Reference in New Issue
Block a user