1818 along with Atomic App. If not, see <http://www.gnu.org/licenses/>.
1919"""
2020import anymarkup
21- import copy
2221import logging
2322import os
2423import yaml
3837 NAME_KEY ,
3938 INHERIT_KEY ,
4039 ARTIFACTS_KEY ,
41- DEFAULT_PROVIDER )
40+ NAMESPACE_SEPARATOR )
4241from atomicapp .utils import Utils
4342from atomicapp .requirements import Requirements
4443from atomicapp .nulecule .lib import NuleculeBase
@@ -76,7 +75,7 @@ def __init__(self, id, specversion, graph, basepath, metadata=None,
7675 metadata (dict): Nulecule metadata
7776 requirements (dict): Requirements for the Nulecule application
7877 params (list): List of params for the Nulecule application
79- config (dict ): Config data for the Nulecule application
78+ config (atomicapp.nulecule.config.Config ): Config data
8079 namespace (str): Namespace of the current Nulecule application
8180
8281 Returns:
@@ -88,7 +87,7 @@ def __init__(self, id, specversion, graph, basepath, metadata=None,
8887 self .metadata = metadata or {}
8988 self .graph = graph
9089 self .requirements = requirements
91- self .config = config or {}
90+ self .config = config
9291
9392 @classmethod
9493 def unpack (cls , image , dest , config = None , namespace = GLOBAL_CONF ,
@@ -101,7 +100,7 @@ def unpack(cls, image, dest, config=None, namespace=GLOBAL_CONF,
101100 image (str): A Docker image name.
102101 dest (str): Destination path where Nulecule data from Docker
103102 image should be extracted.
104- config (dict): Dictionary, config data for Nulecule application.
103+ config: An instance of atomicapp.nulecule.config.Config
105104 namespace (str): Namespace for Nulecule application.
106105 nodeps (bool): Don't pull external Nulecule dependencies when
107106 True.
@@ -115,7 +114,7 @@ def unpack(cls, image, dest, config=None, namespace=GLOBAL_CONF,
115114 if Utils .running_on_openshift ():
116115 # pass general config data containing provider specific data
117116 # to Openshift provider
118- op = OpenshiftProvider (config .get ( 'general' , {}) , './' , False )
117+ op = OpenshiftProvider (config .globals , './' , False )
119118 op .artifacts = []
120119 op .init ()
121120 op .extract (image , APP_ENT_PATH , dest , update )
@@ -138,7 +137,8 @@ def load_from_path(cls, src, config=None, namespace=GLOBAL_CONF,
138137
139138 Args:
140139 src (str): Path to load Nulecule application from.
141- config (dict): Config data for Nulecule application.
140+ config (atomicapp.nulecule.config.Config): Config data for
141+ Nulecule application.
142142 namespace (str): Namespace for Nulecule application.
143143 nodeps (bool): Do not pull external applications if True.
144144 dryrun (bool): Do not make any change to underlying host.
@@ -231,25 +231,23 @@ def load_config(self, config=None, ask=False, skip_asking=False):
231231 It updates self.config.
232232
233233 Args:
234- config (dict ): Existing config data, may be from ANSWERS
235- file or any other source.
234+ config (atomicapp.nulecule.config.Config ): Existing config data,
235+ may be from ANSWERS file or any other source.
236236
237237 Returns:
238238 None
239239 """
240+ if config is None :
241+ config = self .config
240242 super (Nulecule , self ).load_config (
241243 config = config , ask = ask , skip_asking = skip_asking )
242- if self .namespace == GLOBAL_CONF and self .config [GLOBAL_CONF ].get ('provider' ) is None :
243- self .config [GLOBAL_CONF ]['provider' ] = DEFAULT_PROVIDER
244- logger .info ("Provider not specified, using default provider - {}" .
245- format (DEFAULT_PROVIDER ))
244+
246245 for component in self .components :
247246 # FIXME: Find a better way to expose config data to components.
248247 # A component should not get access to all the variables,
249248 # but only to variables it needs.
250- component .load_config (config = copy . deepcopy ( self . config ) ,
249+ component .load_config (config = config ,
251250 ask = ask , skip_asking = skip_asking )
252- self .merge_config (self .config , component .config )
253251
254252 def load_components (self , nodeps = False , dryrun = False ):
255253 """
@@ -270,8 +268,8 @@ def load_components(self, nodeps=False, dryrun=False):
270268 node_name = node [NAME_KEY ]
271269 source = Utils .getSourceImage (node )
272270 component = NuleculeComponent (
273- node_name , self .basepath , source ,
274- node .get (PARAMS_KEY ), node .get (ARTIFACTS_KEY ),
271+ self . _get_component_namespace ( node_name ) , self .basepath ,
272+ source , node .get (PARAMS_KEY ), node .get (ARTIFACTS_KEY ),
275273 self .config )
276274 component .load (nodeps , dryrun )
277275 components .append (component )
@@ -294,6 +292,24 @@ def render(self, provider_key=None, dryrun=False):
294292 for component in self .components :
295293 component .render (provider_key = provider_key , dryrun = dryrun )
296294
295+ def _get_component_namespace (self , component_name ):
296+ """
297+ Get a unique namespace for a Nulecule graph item, by concatinating
298+ the namespace of the current Nulecule (which could be the root Nulecule
299+ app or a child or external Nulecule app) and name of the Nulecule
300+ graph item.
301+
302+ Args:
303+ component_name (str): Name of the Nulecule graph item
304+
305+ Returns:
306+ A string
307+ """
308+ current_namespace = '' if self .namespace == GLOBAL_CONF else self .namespace
309+ return (
310+ '%s%s%s' % (current_namespace , NAMESPACE_SEPARATOR , component_name )
311+ if current_namespace else component_name )
312+
297313
298314class NuleculeComponent (NuleculeBase ):
299315
@@ -356,12 +372,13 @@ def load_config(self, config=None, ask=False, skip_asking=False):
356372 """
357373 Load config for the Nulecule component.
358374 """
375+ if config is None :
376+ config = self .config
359377 super (NuleculeComponent , self ).load_config (
360378 config , ask = ask , skip_asking = skip_asking )
361379 if isinstance (self ._app , Nulecule ):
362- self ._app .load_config (config = copy . deepcopy ( self .config ) ,
380+ self ._app .load_config (config = self .config ,
363381 ask = ask , skip_asking = skip_asking )
364- self .merge_config (self .config , self ._app .config )
365382
366383 def load_external_application (self , dryrun = False , update = False ):
367384 """
@@ -384,7 +401,8 @@ def load_external_application(self, dryrun=False, update=False):
384401 'Found existing external application: %s '
385402 'Loading: ' % self .name )
386403 nulecule = Nulecule .load_from_path (
387- external_app_path , dryrun = dryrun , update = update )
404+ external_app_path , dryrun = dryrun , update = update ,
405+ namespace = self .namespace )
388406 elif not dryrun :
389407 logger .info ('Pulling external application: %s' % self .name )
390408 nulecule = Nulecule .unpack (
@@ -436,7 +454,7 @@ def render(self, provider_key=None, dryrun=False):
436454 raise NuleculeException (
437455 "Data for provider \" %s\" are not part of this app"
438456 % provider_key )
439- context = self .get_context ( )
457+ context = self .config . context ( self . namespace )
440458 for provider in self .artifacts :
441459 if provider_key and provider != provider_key :
442460 continue
0 commit comments