Tideway Community Forum

forgot password?
   
 
Sharing table lookups between TPL modules
Posted: 05 June 2008 12:37 PM   [ Ignore ]  
Newbie
Rank
Total Posts:  4
Joined  2008-06-05

You may not know that you can share table definitions between modules. You can see examples of this in TKU (see the SupportingFiles.Tables module).

For example, define a module with a table definition:

tpl 1.0 module TEST1;

// Define a table to be shared in other modules
table LookupPath 1.0
  
'sudo' -> ['/sbin/sudo''/usr/local/bin/suexec'];
end table

This allows a value to be returned by the table based on a key (in this case a list of strings). In one or more other modules, “import” the table in module scope with the command:

from TEST1 import LookupPath 1.0

and then the table can be used in a pattern this second module as normal:

tpl 1.0 module TEST2;

from TEST1 import LookupPath 1.0;

pattern TEST2 1.0
  
'''
  Test pattern to use imported table
  '''
  
  
overview
    tags TEST
;
  
end overview;

  
triggers
    on device 
:= DeviceInfo;
  
end triggers;
  
  
body
    host 
:= model.host(device);
    if 
not host then
      log
.error('No host node for: % device.name%');
      
stop;
    
end if;
    
    for 
val in LookupPath['sudo'do
      
log.info('>>> Possible path: % val%');
    
end for;
  
end body;
end pattern

Profile
 
 
Posted: 18 June 2008 04:39 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  132
Joined  2008-01-25

I’d recommend if you take this approach to move the Tables you want to share into a dedicated Pattern Module and importing as shown above and in the TKU approach.

Avoid “borrowing” a table from another Pattern Module directly otherwise.

There is no technical difference, but the “borrow” approach is open to problems with different authors updating patterns. With the explicitly separate approach it is clear to everyone what is going on.

Don’t forget that if you follow this advice you can view what Pattern Modules are using the Table simply by viewing the Pattern Module node in the UI and looking at the “Depended Upon By” list. If you have an appliance handy with a TKU loaded then simply type “supportingfiles” into the general search box and then click on “Pattern Module” -> “SupportingFiles.Tables” to see this.

Profile