C.4. Plugins

Starting with Rocks 5.4, file specific plugins have been introduced into the 411 system. These plugins manipulate the content of files before sending files on the frontend, and after reception of the file on the client nodes. The plugins also mangle name of the file, ownership and mode of the file.

C.4.1. Plugin API

The 411 Plugin architecture follows a very simple API. Each plugin is written in Python and the plugins reside in /opt/rocks/var/plugins/411/. All plugins inherit the rocks.service411.Plugin class.

  1. get_filename:This function returns a the filename on the frontend on which this plugin will function. This is the only required function in the plugin. All other functions are optional.

    import os
    import sys
    import stat
    import rocks.service411
    
    class Plugin(rocks.service411.Plugin):
    	def get_filename(self):
    			return '/etc/auto.master'
  2. filter_name: This function mangles the filename of the file at the destination, and returns the mangled name

    def filter_name(self, fname):
    	if fname == '/etc/auto.master' && self.attrs['os'] == 'sunos':
    		return '/etc/auto_master'
  3. filter_owner: This function takes the Owner UID and group ID of the file as a string argument and returns a mangled version of the "UID.GID" string. This string is in the format that the chown command understands.

    def filter_owner(self, oid): 
    	if self.attrs['os'] == 'linux':
    		return oid
    	if self.attrs['os'] == 'sunos':
    		return '0.0'
  4. filter_mode: This function takes the mode information as a string, and returns a mangled mode information string. This should be in the numerical format that the chmod command understands.

    def filter_mode(self, mode):
    	return '010644'
    	
  5. filter_content: This function takes the contents of the file as a string, manipulates it and returns the final string to be stored in the file. The example below illustrates insertion of a blank line between every line of the input content.

    Example C-1. filter_content

    def filter_content(self, content):
    	new_content = []
    	for line in content.split('\n'):
    		new_content.append(line + '\n' + '\n')
    	return ''.join(new_content).strip()
    	
  6. pre_send: This function manipulates the contents of the file before the file is made available for download over 411. The example below illustrates deletion of all blank lines from the content.

    Example C-2. pre_send

    def pre_send(self, content):
    	new_content = []
    	for line in content.split('\n'):
    		if line.strip() is '':
    			continue
    		else:
    			new_content.append(line)
    	return '\n'.join(new_content).strip()
    	
  7. post: This function is run after the file is received, filtered and written to disk. The example below illustrates restarting the autofs service after a file has been written to disk.

    Example C-3. post

    def post(self):
    	os.system("service autofs restart")