Package qb :: Package utils :: Module flags
[hide private]
[frames] | no frames]

Source Code for Module qb.utils.flags

  1   
  2  #======================================= 
  3  #  $Revision: #5 $ 
  4  #  $Change: 17898 $ 
  5  #======================================= 
  6   
  7  import logging 
  8   
  9  FLAGS = { 
 10      'job_flags': { 
 11          'uninterruptible': 0x1, 
 12          'memory_hard_limit': 0x2, 
 13          'grid': 0x4, 
 14          'auto_mount': 0x8, 
 15          'export_environment': 0x10, 
 16          'expand': 0x20, 
 17          'thrifty': 0x40, 
 18          'export_job_type': 0x80, 
 19          'host_list': 0x100, 
 20          'elite': 0x200, 
 21          'mail': 0x400, 
 22          'disable_job_object': 0x800, 
 23          'disable_windows_job_object': 0x800, 
 24          'disable_cpu_limit': 0x1000, 
 25          'disable_auto_complete': 0x2000, 
 26          'auto_wrangling': 0x4000, 
 27          'p_agenda': 0x8000, 
 28          'migrate_on_frame_retry': 0x10000, 
 29          'convert_path': 0x20000, 
 30          'enable_job_object': 0x40000, 
 31          'enable_windows_job_object': 0x40000, 
 32          'no_defaults': 0x80000, 
 33      }, 
 34   
 35      'supervisor_flags': { 
 36          'enforce_password': 0x1, 
 37          'host_recontact': 0x2, 
 38          'heartbeat_monitor': 0x4, 
 39          'clone_logs': 0x8, 
 40          'remove_logs': 0x10, 
 41          'master': 0x20, 
 42          'ssl': 0x40, 
 43          'multicast': 0x80, 
 44          'schedule': 0x100, 
 45          'rotate_logs': 0x200, 
 46          'stub_optimize': 0x400, 
 47          'running_monitor': 0x800, 
 48          'retry_busy': 0x1000, 
 49          'ignore_duplicate_peer': 0x2000, 
 50          'enable_max_connections': 0x4000, 
 51          'enable_prediction': 0x8000, 
 52          'disable_submit_check': 0x10000, 
 53          'archive_jobs': 0x20000, 
 54      }, 
 55   
 56      'supervisor_manifest_flags': { 
 57          'job': 0x1, 
 58          'subjob': 0x2, 
 59          'work': 0x4, 
 60      }, 
 61   
 62      'supervisor_log_flags': { 
 63          'job': 0x1, 
 64          'subjob': 0x2, 
 65          'work': 0x4, 
 66          'callback': 0x8, 
 67          'user': 0x10, 
 68          'admin': 0x20, 
 69          'mail': 0x40, 
 70      }, 
 71   
 72      'supervisor_language_flags': { 
 73          'qube': 0x1, 
 74          'perl': 0x2, 
 75          'python': 0x4, 
 76          'post': 0x8, 
 77          'mail': 0x10, 
 78          'dependency': 0x20, 
 79          'auto_wrangling': 0x40, 
 80      }, 
 81   
 82      'worker_flags': { 
 83          'dedicated': 0x1, 
 84          'dynamic': 0x2, 
 85          'auto_mount': 0x4, 
 86          'remove_logs': 0x8, 
 87          'load_profile': 0x10, 
 88          'ssl': 0x20, 
 89          'rotate_logs': 0x40, 
 90          'enable_winbind': 0x80, 
 91          'disable_quickboot': 0x100, 
 92      }, 
 93   
 94      'permissions': { 
 95          'submit_job': 0x1, 
 96          'submit_callback': 0x2, 
 97          'submit_global_callback': 0x4, 
 98          'bump': 0x8, 
 99          'kill': 0x10, 
100          'remove': 0x20, 
101          'modify': 0x40, 
102          'preempt': 0x80, 
103          'block': 0x100, 
104          'interrupt': 0x200, 
105          'complete': 0x400, 
106          'unblock': 0x800, 
107          'suspend': 0x1000, 
108          'resume': 0x2000, 
109          'retry': 0x4000, 
110          'requeue': 0x8000, 
111          'migrate': 0x10000, 
112          'shove': 0x20000, 
113          'fail': 0x40000, 
114          'retire': 0x80000, 
115          'reset': 0x100000, 
116          'all': 0x1fffff, 
117          'lock_host': 0x8000000, 
118          'sudo_admin': 0x10000000, 
119          'impersonate': 0x20000000, 
120          'admin': 0x40000000, 
121          'default': 0x81ffff3, 
122          'group_default': 0x0, 
123          'undefined': 0x80000000, 
124          'full_access': 0xffffffff, 
125      },     
126   
127      'supervisor_verbosity': { 
128          'startup': 0x1, 
129          'work': 0x2, 
130          'subjob': 0x4, 
131          'job': 0x8, 
132          'host': 0x10, 
133          'log': 0x20, 
134          'admin': 0x40, 
135          'command': 0x80, 
136          'query': 0x100, 
137          'sync': 0x200, 
138          'queue': 0x400, 
139          'callback': 0x800, 
140          'debug': 0x1000, 
141          'error': 0x2000, 
142          'warning': 0x4000, 
143          'security': 0x8000, 
144          'auth': 0x10000, 
145          'preempt': 0x20000, 
146          'memory': 0x40000, 
147          'web': 0x80000, 
148          'info': 0x100000, 
149          'license': 0x200000, 
150          'file': 0x400000, 
151      } 
152  } 
153   
154  FLAGS['supervisor_job_flags'] = FLAGS['job_flags'] 
155  FLAGS['client_job_flags'] = FLAGS['job_flags'] 
156  FLAGS['supervisor_default_security'] = FLAGS['permissions'] 
157   
158   
159 -def isFlagSet(configParam, flag, flagVal):
160 ''' 161 @param configParam: configuration parameter name, e.g. C{'supervisor_job_flags'} 162 @type configParam: C{str} 163 164 @param flag: flag to test for 165 @type flag: C{str} 166 167 @param flagVal: value to test against to see if the flag is set, can be a decimal number or a string or any base, e.g. C{'0x1245'} 168 @type: flagVal: C{int} or C{str} 169 170 ''' 171 flagIsSet = False 172 configParam = configParam.lower() 173 174 # convert to decimal if it's a string, radix=0 allows int() to guess at base 175 if isinstance(flagVal, str): 176 flagVal = int(flagVal, 0) 177 178 if configParam in FLAGS: 179 flagDict = FLAGS[configParam] 180 181 if flag not in flagDict: 182 logging.error('qb.utils.flags.flagIsSet: unknown "%s" flag: "%s"' % (configParam, flag)) 183 184 if flagDict.get(flag, 0) & flagVal > 0: 185 flagIsSet = True 186 else: 187 logging.error('qb.utils.flags.flagIsSet: unknown configuration parameter: "%s"' % configParam) 188 189 return flagIsSet
190
191 -def flagIntValToString(configParam, intVal):
192 ''' 193 ''' 194 flagString = '' 195 setFlags = [] 196 # ensure we're dealing with a hex value 197 if isinstance(intVal, str): 198 intVal = int(intVal, 0) 199 200 if configParam in FLAGS: 201 flagDict = FLAGS[configParam] 202 203 for (name, val) in flagDict.items(): 204 if val & intVal: 205 setFlags.append(name) 206 else: 207 logging.error('qb.utils.flags.flagIsSet: unknown configuration parameter: "%s"' % configParam) 208 209 flagString = ','.join(sorted(setFlags)) 210 211 return flagString
212