forked from RedHatInsights/ros-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.py
28 lines (23 loc) · 832 Bytes
/
seed.py
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
import json
import logging
from ros.lib.models import Rule
from ros.extensions import db
from ros.lib.utils import get_or_create
LOG = logging.getLogger(__name__)
class Seed():
def run(self):
self.seed_rule_data()
def seed_rule_data(self):
with open("seed.d/rules.json") as f:
rules = json.loads(f.read())
for data in rules:
get_or_create(
db.session, Rule, 'rule_id',
rule_id=data['rule_id'],
description=data['description'],
reason=data['reason'],
resolution=data['resolution'],
condition=data['condition']
)
db.session.commit()
LOG.info("Seeding completed successfully. ROS rules added to database")