Revision 0645820e
mise à niveau maj_bdd
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2963 b22e2e97-25c9-44ff-b637-2e5ceca36478
maj_bdd.py | ||
---|---|---|
7 | 7 |
import tg |
8 | 8 |
|
9 | 9 |
tg.config = paste.deploy.appconfig('config:%s/%s' % (os.getcwd(), 'development.ini')) |
10 |
from vigilo.models.configure import DBSession, configure_db |
|
11 |
configure_db(tg.config, 'sqlalchemy.') |
|
10 |
from vigilo.models.session import DBSession |
|
11 |
from vigilo.models.configure import configure_db |
|
12 |
configure_db(tg.config, 'sqlalchemy.', tg.config['db_basename']) |
|
12 | 13 |
|
13 | 14 |
def commit_on_exit(): |
14 | 15 |
""" |
... | ... | |
20 | 21 |
|
21 | 22 |
atexit.register(commit_on_exit) |
22 | 23 |
|
23 |
from vigilo.models import Host, HostGroup |
|
24 |
from vigilo.models import LowLevelService, ServiceGroup |
|
25 |
from vigilo.models import PerfDataSource, Graph |
|
26 |
from vigilo.models import Ventilation, VigiloServer, Application |
|
27 |
|
|
28 |
|
|
29 |
# Groupe d'hôtes (HostGroup) |
|
30 |
def create_HostGroup(name, parent=None): |
|
31 |
g = DBSession.query(HostGroup).filter(HostGroup.name == name).first() |
|
32 |
if not g: |
|
33 |
if parent: |
|
34 |
g = HostGroup(name=name, idparent=parent.idgroup) |
|
35 |
else: |
|
36 |
g = HostGroup(name=name) |
|
37 |
print "Ajout du Groupe: ", name |
|
38 |
DBSession.add(g) |
|
24 |
from vigilo.models.tables import Host, SupItemGroup |
|
25 |
from vigilo.models.tables import LowLevelService |
|
26 |
from vigilo.models.tables import PerfDataSource, Graph |
|
27 |
from vigilo.models.tables import Ventilation, VigiloServer, Application |
|
28 |
|
|
29 |
|
|
30 |
# Groupe d'hôtes (SupItemGroup) |
|
31 |
def create_SupItemGroup(name, parent=None): |
|
32 |
g = SupItemGroup.create(name, parent) |
|
39 | 33 |
return g |
40 | 34 |
|
41 | 35 |
# Hôte (Host) |
... | ... | |
61 | 55 |
.filter(Host.name == hostname) \ |
62 | 56 |
.first() |
63 | 57 |
|
64 |
# Ajout d'un hôte dans un groupe d'hôtes (Host -> HostGroup)
|
|
65 |
def add_Host2HostGroup(host, group):
|
|
66 |
if host not in group.hosts:
|
|
58 |
# Ajout d'un hôte dans un groupe d'hôtes (Host -> SupItemGroup)
|
|
59 |
def add_Host2SupItemGroup(host, group):
|
|
60 |
if host not in group.get_hosts():
|
|
67 | 61 |
print "Ajout de l'hote: %(h)s dans le group: %(g)s" % \ |
68 | 62 |
{'h': host.name, |
69 | 63 |
'g': group.name} |
70 |
group.hosts.append(host)
|
|
64 |
host.groups.append(group)
|
|
71 | 65 |
|
72 | 66 |
def create_LowLevelService(hostname, servicename): |
73 | 67 |
s = DBSession.query(LowLevelService) \ |
... | ... | |
84 | 78 |
DBSession.add(s) |
85 | 79 |
return s |
86 | 80 |
|
87 |
# Groupe de services (ServiceGroup) |
|
88 |
def create_ServiceGroup(name, parent=None): |
|
89 |
g = DBSession.query(ServiceGroup).filter(ServiceGroup.name == name).first() |
|
90 |
if not g: |
|
91 |
if parent: |
|
92 |
g = ServiceGroup(name=name, idparent=parent.idgroup) |
|
93 |
else: |
|
94 |
g = ServiceGroup(name=name) |
|
95 |
print "Ajout du Groupe: ", name |
|
96 |
DBSession.add(g) |
|
97 |
return g |
|
98 | 81 |
|
99 |
# Ajout d'un hôte dans un groupe d'hôtes (Host -> HostGroup)
|
|
100 |
def add_LowLevelService2ServiceGroup(service, group):
|
|
101 |
if service not in group.services:
|
|
82 |
# Ajout d'un hôte dans un groupe d'hôtes (Host -> SupItemGroup)
|
|
83 |
def add_LowLevelService2SupItemGroup(service, group):
|
|
84 |
if service not in group.get_services():
|
|
102 | 85 |
print "Ajout du service: %(s)s dans le group: %(g)s" % \ |
103 | 86 |
{'s': service.servicename, |
104 | 87 |
'g': group.name} |
105 |
group.services.append(service)
|
|
88 |
service.groups.append(group)
|
|
106 | 89 |
|
107 | 90 |
def _get_service(hostname, servicename): |
108 | 91 |
""" Return Host object from hostname, None if not available""" |
... | ... | |
112 | 95 |
.filter(LowLevelService.servicename == servicename) \ |
113 | 96 |
.first() |
114 | 97 |
|
115 |
#Recherche de l'objet ServiceGroup à partir du name
|
|
116 |
def get_ServiceGroup(name):
|
|
117 |
return DBSession.query(ServiceGroup).filter(ServiceGroup.name == name).first()
|
|
98 |
#Recherche de l'objet SupItemGroup à partir du name
|
|
99 |
def get_SupItemGroup(name):
|
|
100 |
return DBSession.query(SupItemGroup).filter(SupItemGroup.name == name).first()
|
|
118 | 101 |
|
119 | 102 |
#Recherche de l'objet LowLevelService à partir du name |
120 | 103 |
def get_LowLevelService(hostname, servicename): |
... | ... | |
152 | 135 |
def create_Server(name, description): |
153 | 136 |
s = DBSession.query(VigiloServer).filter(VigiloServer.name == name).first() |
154 | 137 |
if not s: |
155 |
s = VigiloServer(name=name, description=description)
|
|
138 |
s = VigiloServer(name=name) |
|
156 | 139 |
print "Ajout du Server Vigilo: %s - %s" % (name, description) |
157 | 140 |
DBSession.add(s) |
158 | 141 |
return s |
... | ... | |
179 | 162 |
return v |
180 | 163 |
|
181 | 164 |
|
182 |
hg1 = create_HostGroup(u'Serveurs')
|
|
183 |
hg2 = create_HostGroup(u'Telecoms')
|
|
184 |
hg3 = create_HostGroup(u'Serveurs Linux', hg1)
|
|
185 |
hg4 = create_HostGroup(u'NORTEL', hg2)
|
|
186 |
hg5 = create_HostGroup(u'CISCO', hg2)
|
|
165 |
hg1 = create_SupItemGroup(u'Serveurs')
|
|
166 |
hg2 = create_SupItemGroup(u'Telecoms')
|
|
167 |
hg3 = create_SupItemGroup(u'Serveurs Linux', hg1)
|
|
168 |
hg4 = create_SupItemGroup(u'NORTEL', hg2)
|
|
169 |
hg5 = create_SupItemGroup(u'CISCO', hg2)
|
|
187 | 170 |
|
188 | 171 |
h1 = create_Host(u'proto4.si.c-s.fr') |
189 | 172 |
h2 = create_Host(u'messagerie.si.c-s.fr') |
... | ... | |
191 | 174 |
h4 = create_Host(u'proto6.si.c-s.fr') |
192 | 175 |
h5 = create_Host(u'par.linux0') |
193 | 176 |
|
194 |
add_Host2HostGroup(h1, hg3)
|
|
195 |
add_Host2HostGroup(h2, hg3)
|
|
196 |
add_Host2HostGroup(h3, hg4)
|
|
197 |
add_Host2HostGroup(h4, hg5)
|
|
198 |
add_Host2HostGroup(h4, hg3)
|
|
199 |
add_Host2HostGroup(h5, hg3)
|
|
177 |
add_Host2SupItemGroup(h1, hg3)
|
|
178 |
add_Host2SupItemGroup(h2, hg3)
|
|
179 |
add_Host2SupItemGroup(h3, hg4)
|
|
180 |
add_Host2SupItemGroup(h4, hg5)
|
|
181 |
add_Host2SupItemGroup(h4, hg3)
|
|
182 |
add_Host2SupItemGroup(h5, hg3)
|
|
200 | 183 |
|
201 |
sg1 = create_ServiceGroup(u'Général')
|
|
202 |
sg2 = create_ServiceGroup(u'Interface Réseau')
|
|
203 |
sg3 = create_ServiceGroup(u'Performance')
|
|
204 |
sg4 = create_ServiceGroup(u'Partitions')
|
|
205 |
sg5 = create_ServiceGroup(u'Processus')
|
|
184 |
sg1 = create_SupItemGroup(u'Général')
|
|
185 |
sg2 = create_SupItemGroup(u'Interface Réseau')
|
|
186 |
sg3 = create_SupItemGroup(u'Performance')
|
|
187 |
sg4 = create_SupItemGroup(u'Partitions')
|
|
188 |
sg5 = create_SupItemGroup(u'Processus')
|
|
206 | 189 |
|
207 | 190 |
s1 = create_LowLevelService(h1.name, u'Interface eth0') |
208 | 191 |
s2 = create_LowLevelService(h1.name, u'Interface eth1') |
... | ... | |
210 | 193 |
s4 = create_LowLevelService(h4.name, u'Interface') |
211 | 194 |
s5 = create_LowLevelService(h5.name, u'Interface Linux') |
212 | 195 |
|
213 |
add_LowLevelService2ServiceGroup(s1, sg2)
|
|
214 |
add_LowLevelService2ServiceGroup(s2, sg2)
|
|
215 |
add_LowLevelService2ServiceGroup(s3, sg1)
|
|
216 |
add_LowLevelService2ServiceGroup(s4, sg2)
|
|
217 |
add_LowLevelService2ServiceGroup(s5, sg2)
|
|
218 |
add_LowLevelService2ServiceGroup(s5, sg3)
|
|
196 |
add_LowLevelService2SupItemGroup(s1, sg2)
|
|
197 |
add_LowLevelService2SupItemGroup(s2, sg2)
|
|
198 |
add_LowLevelService2SupItemGroup(s3, sg1)
|
|
199 |
add_LowLevelService2SupItemGroup(s4, sg2)
|
|
200 |
add_LowLevelService2SupItemGroup(s5, sg2)
|
|
201 |
add_LowLevelService2SupItemGroup(s5, sg3)
|
|
219 | 202 |
|
220 | 203 |
gr1 = create_graph(u'graph1',u'Graph1', None) |
221 | 204 |
gr2 = create_graph(u'graph2',u'Graph2', None) |
Also available in: Unified diff