3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from cmframework.apis import cmchangestate
19 from cmframework.server import cmeventletrwlock
22 class CMChangeMonitorState(object):
24 self.state = cmchangestate.CM_CHANGE_STATE_ONGOING
25 self.failed_plugins = {}
28 class CMChangeMonitor(object):
31 self.lock = cmeventletrwlock.CMEventletRWLock()
33 def start_change(self):
34 with self.lock.writer():
35 changestate = CMChangeMonitorState()
36 uuid_value = str(uuid.uuid4())
37 self.changes[uuid_value] = changestate
40 def change_nok(self, uuid_value, failed_plugins):
41 with self.lock.writer():
42 if uuid_value in self.changes:
43 self.changes[uuid_value].state = cmchangestate.CM_CHANGE_STATE_NOK
44 self.changes[uuid_value].failed_plugins = failed_plugins
46 logging.warning('Invalid change uuid %s', uuid_value)
48 def change_ok(self, uuid_value):
49 with self.lock.writer():
50 if uuid_value in self.changes:
51 self.changes[uuid_value].state = cmchangestate.CM_CHANGE_STATE_OK
53 logging.warning('Invalid change uuid %s', uuid_value)
55 def get_change_state(self, uuid_value):
56 with self.lock.reader():
57 return self.changes[uuid_value]
59 def get_all_changes_states(self):
60 with self.lock.reader():
61 return copy.deepcopy(self.changes)