def _cache_path(cls, fsname): """Build and check a cache file path from filesystem name.""" fs_conf_dir = os.path.expandvars(Globals().get_conf_dir()) if not os.path.exists(fs_conf_dir): raise ConfigException("Cache directory does not exist '%s'" % fs_conf_dir) return "%s/%s.xmf" % (os.path.normpath(fs_conf_dir), fsname)
def get_target_from_tag_and_type(self, target_tag, target_type): """ This function aims to retrieve a target look for it's type and it's tag. """ target = None if target_type == 'MGT' or target_type == 'MGS': # The target is the MGT target = self.get_target_mgt() elif target_type == 'MDT': # The target is the MDT target = self.get_target_mdt() elif target_type == 'OST': # The target is an OST. Walk through the list of # OSTs to retrieve the right one. for current_ost in self.iter_targets_ost(): if current_ost.get_tag() == target_tag: # The ost tag match the searched one. # save the target and break the loop target = current_ost break else: # The target type is currently not supported by the # configuration raise ConfigException("Unknown target type %s" % target_type) return target
def get_default_mount_path(self): """ Return the default client mount path or raise a ConfigException if it does not exist. """ if not 'mount_path' in self._fs.model: raise ConfigException("mount_path not specified") return self._fs.get('mount_path')
def get_nid(self, node): try: return self.nid_map[node] except KeyError: raise ConfigException("Cannot get NID for %s, aborting. Please " "verify `nid_map' configuration." % node)
def compare(self, otherfs): """ Compare the FileSystem model with another FileSystem and return a dictionnary describing the needed actions. """ actions = {} added, changed, removed = self.model.diff(otherfs.model) anyset = set(changed.iterkeys()) | set(added.iterkeys()) \ | set(removed.iterkeys()) # Read-only keys: fs_name readonly = set(['fs_name']) if readonly & anyset: raise ConfigException("%s could not be changed" % ", ".join(readonly & anyset)) # Need to reformat targets reformatkeys = set([ 'mgt_mkfs_options', 'mdt_mkfs_options', 'ost_mkfs_options', 'mgt_format_params', 'mdt_format_params', 'ost_format_params' ]) if reformatkeys & anyset: actions['reformat'] = True # Need a tunefs.lustre tunefskeys = set([ 'quota', 'quota_type', 'quota_bunit', 'quota_iunit', 'quota_btune', 'quota_itune', 'stripe_size', 'stripe_count' ]) if tunefskeys & anyset: actions['tunefs'] = True # Need a writeconf writeconfkeys = set(['nid_map']) if writeconfkeys & anyset: # Note: Target removal could also set this flag. actions['writeconf'] = True # Need to unmount then remount clients remountkeys = set(['mount_options', 'mount_path']) if remountkeys & anyset: actions['copyconf'] = True # Could be improved if doing this only on clients without specific # path or options. if self.model.get('client'): actions['unmount'] = [ Clients(cli) for cli in self.model.get('client') ] if otherfs.model.get('client'): actions['mount'] = [ Clients(cli) for cli in otherfs.model.get('client') ] # Need to restart targets restartkeys = set([ 'mgt_mount_path', 'mdt_mount_path', 'ost_mount_path', 'mgt_mount_options', 'mdt_mount_options', 'ost_mount_options' ]) if restartkeys & anyset: actions['restart'] = True # Only need to update cache file copykeys = set(['description']) if copykeys & anyset: actions['copyconf'] = True # Clients have changed if 'client' in removed: actions.setdefault('unmount', []) actions['unmount'] += [ Clients(elem) for elem in removed.elements('client') ] if 'client' in added: actions.setdefault('mount', []) actions['mount'] += [ Clients(elem) for elem in added.elements('client') ] if 'client' in changed: for elem in changed.elements('client'): actions.setdefault('unmount', []).append(Clients(elem.old)) actions.setdefault('mount', []).append(Clients(elem)) # Router has changed if 'router' in removed: actions.setdefault('stop', []).extend( [Routers(elem) for elem in removed.elements('router')]) if 'router' in added: actions.setdefault('start', []).extend( [Routers(elem) for elem in added.elements('router')]) assert 'router' not in changed, 'Router change is not supported' # Some targets have changed for tgt in ['mgt', 'mdt', 'ost']: if tgt in removed: actions['writeconf'] = True actions.setdefault('stop', []).extend( [Target(tgt, elem) for elem in removed.elements(tgt)]) actions.setdefault('remove', []).extend( [Target(tgt, elem) for elem in removed.elements(tgt)]) if tgt in added: actions.setdefault('format', []).extend( [Target(tgt, elem) for elem in added.elements(tgt)]) actions.setdefault('start', []).extend( [Target(tgt, elem) for elem in added.elements(tgt)]) if tgt in changed: for elem in changed.elements(tgt): if set(['ha_node', 'network', 'node', 'dev']) & \ elem.chgkeys: actions.setdefault('stop', []).append(Target(tgt, elem.old)) actions.setdefault('start', []).append(Target(tgt, elem)) if set(['ha_node', 'network', 'node']) & elem.chgkeys: actions['writeconf'] = True if set(['tag', 'group']) & elem.chgkeys: actions['copyconf'] = True if 'active' in elem.chgkeys: actions['tune'] = True if 'jdev' in elem.chgkeys: raise ConfigException("'jdev' change is not supported") # If some actions is required, we need to update config files. if len(actions) > 0: actions['copyconf'] = True return actions
def __init__(self, nodes, nids): ConfigException.__init__(self, "Erroneous NID map") self.nodes = nodes self.nids = nids