def GetFile(self, map_name, dst_file, current_file, location=None): """Retrieve a file from this source. Args: map_name: A string representation of the map whose file you want dst_file: Temporary filename to write to. current_file: Path to the current cache. location: optional field used by automounts to indicate a specific map Returns: path to new file Raises: UnsupportedMap: for unknown source maps """ if map_name == config.MAP_PASSWORD: return self.GetPasswdFile(dst_file, current_file) elif map_name == config.MAP_GROUP: return self.GetGroupFile(dst_file, current_file) elif map_name == config.MAP_SHADOW: return self.GetShadowFile(dst_file, current_file) elif map_name == config.MAP_NETGROUP: return self.GetNetgroupFile(dst_file, current_file) elif map_name == config.MAP_AUTOMOUNT: return self.GetAutomountFile(dst_file, current_file, location=location) raise error.UnsupportedMap('Source can not fetch %s' % map_name)
def GetMap(self, map_name, since=None, location=None): """Get a specific map from this source. Args: map_name: A string representation of the map you want since: optional timestamp for incremental query location: optional field used by automounts to indicate a specific map Returns: A Map child class for the map requested. Raises: UnsupportedMap: for unknown source maps """ if map_name == config.MAP_PASSWORD: return self.GetPasswdMap(since) elif map_name == config.MAP_SSHKEY: return self.GetSshkeyMap(since) elif map_name == config.MAP_GROUP: return self.GetGroupMap(since) elif map_name == config.MAP_SHADOW: return self.GetShadowMap(since) elif map_name == config.MAP_NETGROUP: return self.GetNetgroupMap(since) elif map_name == config.MAP_AUTOMOUNT: return self.GetAutomountMap(since, location=location) raise error.UnsupportedMap('Source can not fetch %s' % map_name)
def __init__(self, conf, map_name, automount_mountpoint=None): """Initialise the Cache object. Args: conf: A dictionary of key/value pairs map_name: A string representation of the map type automount_mountpoint: A string containing the automount mountpoint, used only by automount maps. Raises: UnsupportedMap: for map types we don't know about """ super(Cache, self).__init__() # Set up a logger for our children self.log = logging.getLogger(self.__class__.__name__) # Store config info self.conf = conf self.output_dir = conf.get('dir', '.') self.automount_mountpoint = automount_mountpoint self.map_name = map_name # Setup the map we may be asked to load our cache into. if map_name == config.MAP_PASSWORD: self.data = passwd.PasswdMap() elif map_name == config.MAP_SSHKEY: self.data = sshkey.SshkeyMap() elif map_name == config.MAP_GROUP: self.data = group.GroupMap() elif map_name == config.MAP_SHADOW: self.data = shadow.ShadowMap() elif map_name == config.MAP_NETGROUP: self.data = netgroup.NetgroupMap() elif map_name == config.MAP_AUTOMOUNT: self.data = automount.AutomountMap() else: raise error.UnsupportedMap('Cache does not support %s' % map_name)