configurationengine/source/cone/action/configroot2flat.py
changeset 9 63964d875993
parent 4 0951727b8815
equal deleted inserted replaced
8:a2e65c705db8 9:63964d875993
    76     The mechanism assumes all includes that end with /root.confml to be layer includes that 
    76     The mechanism assumes all includes that end with /root.confml to be layer includes that 
    77     are layers that are not expanded
    77     are layers that are not expanded
    78     @param config: the configuration object to process. 
    78     @param config: the configuration object to process. 
    79     """
    79     """
    80     includes = []
    80     includes = []
    81     for include in config.list_configurations():
    81     try:
    82         if include.endswith('/root.confml'):
    82         for include in config.list_configurations():
    83             includes.append(utils.resourceref.remove_begin_slash(include))
    83             if include.endswith('/root.confml'):
    84         else:
    84                 includes.append(utils.resourceref.remove_begin_slash(include))
    85             subconfig = config.get_configuration(include)
    85             else:
    86             includes += get_flat_includes(subconfig)
    86                 subconfig = config.get_configuration(include)
       
    87                 includes += get_flat_includes(subconfig)
       
    88     except Exception, e:
       
    89         logger.error('Error getting includes from sub-configuration: %s: %s'
       
    90                      % (e.__class__.__name__, e))
    87     return includes
    91     return includes
    88 
    92 
    89 def get_nested_meta(config, recursion_depth=-1):
    93 def get_nested_meta(config, recursion_depth=-1):
    90     """
    94     """
    91     Get the nested meta data for the given configuration constructed from metadata of all sub configuration meta.
    95     Get the nested meta data for the given configuration constructed from metadata of all sub configuration meta.
    94     all configurations.
    98     all configurations.
    95     @return: a ConfmlMeta object 
    99     @return: a ConfmlMeta object 
    96     """
   100     """
    97     
   101     
    98     meta = confml_model.ConfmlMeta()
   102     meta = confml_model.ConfmlMeta()
    99     if recursion_depth != 0:
   103     try:
   100         # First recurse through all subconfigurations to get their meta     
   104         if recursion_depth != 0:
   101         for subconfig_name in config.list_configurations():
   105             # First recurse through all subconfigurations to get their meta     
   102             subconfig = config.get_configuration(subconfig_name)
   106             for subconfig_name in config.list_configurations():
   103             submeta = get_nested_meta(subconfig, recursion_depth-1)
   107                 subconfig = config.get_configuration(subconfig_name)
   104             
   108                 submeta = get_nested_meta(subconfig, recursion_depth-1)
   105             meta.update( submeta )
   109                 
   106     
   110                 meta.update( submeta )
   107     # lastly, update the meta data of the root configuration
   111         
   108     if config.meta:
   112         # lastly, update the meta data of the root configuration
   109         meta.update(config.meta)
   113         if config.meta:
       
   114             meta.update(config.meta)
       
   115     except Exception, e:
       
   116         logger.error('Error getting metadata from sub-configuration: %s: %s'
       
   117                      % (e.__class__.__name__, e))
   110     return meta
   118     return meta
   111 
   119 
   112 
   120 
   113 class Configroot2FlatFailed(exceptions.ConeException):
   121 class Configroot2FlatFailed(exceptions.ConeException):
   114     pass
   122     pass