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.
14 from __future__ import print_function
20 from cmframework.apis import cmerror
23 class CMFlagFile(object):
24 CM_FLAGFILE_DIR = '/mnt/config-manager'
26 def __init__(self, name):
27 logging.debug('CMFlagFile constructor called, name=%s', name)
29 self._name = '{}/{}'.format(CMFlagFile.CM_FLAGFILE_DIR, name)
31 def __nonzero__(self):
35 logging.debug('is_set called')
37 return os.path.exists(self._name)
40 logging.debug('set called')
44 with open(self._name, 'w') as f:
45 os.chmod(self._name, stat.S_IRUSR | stat.S_IWUSR)
49 except IOError as exp:
50 raise cmerror.CMError(str(exp))
53 logging.debug('unset called')
58 except IOError as exp:
59 raise cmerror.CMError(str(exp))