def verify_object_before_delete(self, pycl_object): if not pycl_object.name: raise InvalidRequest( 'Cluster configuration name must be specified.') if pycl_object.name == 'global': raise InvalidRequest( 'Global cluster configuration cannot be deleted.') return
def check_user_provided_keys(self): """ Checks for presence of all data keys that must be provided by user. :raises: **InvalidRequest** - in case object's data is not a dictionary, or if any of the required keys are missing. """ if type(self.data) != dict: raise InvalidRequest('Data object is not a dictionary: %s.' % str(self.data)) for key in self.USER_PROVIDED_KEYS: if not self.data.get(key): raise InvalidRequest('Input data is missing required object key: %s.' % str(key))
def __get_object_class_from_uge_version(cls, uge_version, class_name, base_module_name=None): if not uge_version: raise InvalidRequest('Cannot generate %s object: UGE version must be specified.' % class_name) if uge_version not in UGE_RELEASE_OBJECT_MAP: raise QconfException('Unsupported UGE version: %s.' % uge_version) release_map = UGE_RELEASE_OBJECT_MAP.get(uge_version) object_version = release_map.get(class_name) return cls.__get_object_class_from_object_version(object_version, class_name, base_module_name)
def __get_object_class_from_object_version(cls, object_version, class_name, base_module_name=None): if not object_version: raise InvalidRequest('Object version not supplied for class %s.' % (class_name)) if base_module_name is None: base_module_name = cls.__get_object_base_module_name(class_name) module_name = ('%s_v%s' % (base_module_name, object_version)).replace('.', '_') module_file = '%s/%s.py' % ('/'.join(__file__.split('/')[:-1]), module_name) module = imp.load_source('uge.objects.%s' % module_name, module_file) object_class = getattr(module, class_name) return object_class
def update_with_required_data_defaults(self): """ Updates object with default values for required data keys. :raises: **InvalidArgument** - in case object's data is not a dictionary. """ if type(self.data) != dict: raise InvalidRequest('Data object is not a dictionary: %s.' % str(self.data)) for (key, value) in list(self.get_required_data_defaults().items()): if key not in self.data: if type(value) == bytes: for env_var in ['SGE_ROOT', 'SGE_CELL']: value = value.replace(env_var, os.environ[env_var]) self.data[key] = value
def remove_optional_keys(self): """ Removes values for keys that are not required from object's data. :raises: **InvalidRequest** - in case object's data is not a dictionary. """ if self.OPTIONAL_KEYS_ALLOWED: return if type(self.data) != dict: raise InvalidRequest('Data object is not a dictionary: %s.' % str(self.data)) removed_keys = [] for (key, value) in list(self.data.items()): if key not in self.get_required_data_defaults(): if key not in self.USER_PROVIDED_KEYS and not key.startswith('#'): removed_keys.append(key) for key in removed_keys: del self.data[key]
def list_objects(self): raise InvalidRequest( 'This method is not supported for scheduler configuration.')
def delete_object(self): raise InvalidRequest('Scheduler configuration cannot be deleted.')
def add_object(self, pycl_object=None, data=None, metadata=None, json_string=None): raise InvalidRequest('Scheduler configuration object cannot be added.')
def check_input_args(self): if not self.options.input_file: raise InvalidRequest('Missing input file.') if self.options.output_format not in ['json', 'uge']: raise InvalidRequest('Output format may be either json or uge.')
def delete_object(self): raise InvalidRequest('Complex configuration cannot be deleted.')