2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
22 #Scheduler is like a satellite for dispatcher
23 from shinken
.satellitelink
import SatelliteLink
, SatelliteLinks
24 from shinken
.util
import to_int
, to_bool
, to_split
25 from shinken
.property import UnusedProp
, BoolProp
, IntegerProp
, FloatProp
, CharProp
, StringProp
, ListProp
27 from shinken
.pyro_wrapper
import Pyro
30 class SchedulerLink(SatelliteLink
):
33 #Ok we lie a little here because we are a mere link in fact
37 'scheduler_name': StringProp(
38 fill_brok
=['full_status']),#, 'pythonize': None},
39 'address': StringProp(
40 fill_brok
=['full_status']),#, 'pythonize': to_bool},
43 fill_brok
=['full_status']),
46 fill_brok
=['full_status']),
49 'weight': IntegerProp(
51 fill_brok
=['full_status']),
52 'manage_arbiters': IntegerProp(
54 'use_timezone': StringProp(
57 'timeout': IntegerProp(
59 fill_brok
=['full_status']),
60 'data_timeout': IntegerProp(
62 fill_brok
=['full_status']),
63 'max_check_attempts': IntegerProp(
65 fill_brok
=['full_status']),
66 'realm' : StringProp(default
=''),
68 running_properties
= {'con': StringProp(
72 fill_brok
=['full_status']), # DEAD or not
73 'attempt': StringProp(
75 fill_brok
=['full_status']), # the number of failed attempt
76 'reachable': StringProp(
78 fill_brok
=['full_status']), # can be network ask or not (dead or check in timeout or error)
81 'need_conf': StringProp(
85 'configuration_errors' : StringProp(default
=[]),
91 return self
.scheduler_name
94 def run_external_command(self
, command
):
96 self
.create_connexion()
99 print "Send command", command
101 self
.con
.run_external_command(command
)
102 except Pyro
.errors
.URIError
, exp
:
105 except Pyro
.errors
.ProtocolError
, exp
:
108 except TypeError , exp
:
109 print ''.join(Pyro
.util
.getPyroTraceback(exp
))
110 except Pyro
.errors
.CommunicationError
, exp
:
116 def register_to_my_realm(self
):
117 self
.realm
.schedulers
.append(self
)
120 def give_satellite_cfg(self
):
121 return {'port' : self
.port
, 'address' : self
.address
, 'name' : self
.scheduler_name
, 'instance_id' : self
.id, 'active' : self
.conf
!=None}
124 #Some parameters can give as 'overriden parameters' like use_timezone
125 #so they will be mixed (in the scheduler) with the standard conf send by the arbiter
126 def get_override_configuration(self
):
128 properties
= self
.__class
__.properties
129 for prop
in properties
:
130 entry
= properties
[prop
]
132 r
[prop
] = getattr(self
, prop
)
135 class SchedulerLinks(SatelliteLinks
):
136 name_property
= "name"
137 inner_class
= SchedulerLink