1010See README for documentation
1111
1212Configuration:
13- - hubblestack:nova:dir
13+ - hubblestack:nova:module_dir
14+ - hubblestack:nova:profile_dir
1415 - hubblestack:nova:saltenv
1516 - hubblestack:nova:autoload
1617 - hubblestack:nova:autosync
@@ -299,7 +300,8 @@ def top(topfile='top.nova',
299300 Arguments:
300301
301302 topfile
302- The path of the topfile, relative to your hubblestack_nova directory.
303+ The path of the topfile, relative to your hubblestack_nova_profiles
304+ directory.
303305
304306 verbose
305307 Whether to show additional information about audits, including
@@ -413,21 +415,27 @@ def top(topfile='top.nova',
413415 return results
414416
415417
416- def sync ():
418+ def sync (clean = False ):
417419 '''
418- Sync the nova audit modules from the saltstack fileserver.
420+ Sync the nova audit modules and profiles from the saltstack fileserver.
419421
420422 The modules should be stored in the salt fileserver. By default nova will
421- search the base environment for a top level ``hubblestack_nova`` directory,
422- unless otherwise specified via pillar or minion config
423- (``hubblestack:nova:dir ``)
423+ search the base environment for a top level ``hubblestack_nova_modules``
424+ directory, unless otherwise specified via pillar or minion config
425+ (``hubblestack:nova:module_dir ``)
424426
425- Modules will just be cached in the normal minion cachedir
427+ The profiles should be stored in the salt fileserver. By default nova will
428+ search the base environment for a top level ``hubblestack_nova_profiles``
429+ directory, unless otherwise specified via pillar or minion config
430+ (``hubblestack:nova:profile_dir``)
426431
427- Returns the minion's path to the cached directory
432+ Modules and profiles will be cached in the normal minion cachedir
428433
429- NOTE: This function will also clean out existing files at the cached
430- location, as cp.cache_dir doesn't clean out old files
434+ Returns a boolean representing success
435+
436+ NOTE: This function will optionally clean out existing files at the cached
437+ location, as cp.cache_dir doesn't clean out old files. Pass ``clean=True``
438+ to enable this behavior
431439
432440 CLI Examples:
433441
@@ -437,35 +445,44 @@ def sync():
437445 salt '*' nova.sync saltenv=hubble
438446 '''
439447 log .debug ('syncing nova modules' )
440- nova_dir = __salt__ ['config.get' ]('hubblestack:nova:dir' , 'salt://hubblestack_nova' )
448+ nova_profile_dir = __salt__ ['config.get' ]('hubblestack:nova:profile_dir' ,
449+ 'salt://hubblestack_nova_profiles' )
450+ nova_module_dir = __salt__ ['config.get' ]('hubblestack:nova:module_dir' ,
451+ 'salt://hubblestack_nova_modules' )
441452 saltenv = __salt__ ['config.get' ]('hubblestack:nova:saltenv' , 'base' )
442453
443- # Support optional salt:// in config
444- if 'salt://' in nova_dir :
445- path = nova_dir
446- _ , _ , nova_dir = nova_dir .partition ('salt://' )
447- else :
448- path = 'salt://{0}' .format (nova_dir )
449-
450454 # Clean previously synced files
451- __salt__ ['file.remove' ](_hubble_dir ())
452- # Sync the files
453- cached = __salt__ ['cp.cache_dir' ](path , saltenv = saltenv )
454-
455- if cached and isinstance (cached , list ):
456- # Success! Trim the paths
457- cachedir = _hubble_dir ()
458- ret = [relative .partition (cachedir )[2 ] for relative in cached ]
459- return ret
460- else :
461- if isinstance (cached , list ):
462- # Nothing was found
463- return cached
455+ if clean :
456+ for nova_dir in _hubble_dir ():
457+ __salt__ ['file.remove' ](nova_dir )
458+
459+ synced = []
460+ for i , nova_dir in enumerate ((nova_module_dir , nova_profile_dir )):
461+ # Support optional salt:// in config
462+ if 'salt://' in nova_dir :
463+ path = nova_dir
464+ _ , _ , nova_dir = nova_dir .partition ('salt://' )
465+ else :
466+ path = 'salt://{0}' .format (nova_dir )
467+
468+ # Sync the files
469+ cached = __salt__ ['cp.cache_dir' ](path , saltenv = saltenv )
470+
471+ if cached and isinstance (cached , list ):
472+ # Success! Trim the paths
473+ cachedir = os .path .dirname (_hubble_dir ()[i ])
474+ ret = [relative .partition (cachedir )[2 ] for relative in cached ]
475+ synced .extend (ret )
464476 else :
465- # Something went wrong, there's likely a stacktrace in the output
466- # of cache_dir
467- raise CommandExecutionError ('An error occurred while syncing: {0}'
468- .format (cached ))
477+ if isinstance (cached , list ):
478+ # Nothing was found
479+ synced .extend (cached )
480+ else :
481+ # Something went wrong, there's likely a stacktrace in the output
482+ # of cache_dir
483+ raise CommandExecutionError ('An error occurred while syncing: {0}'
484+ .format (cached ))
485+ return synced
469486
470487
471488def load ():
@@ -474,8 +491,10 @@ def load():
474491 '''
475492 if __salt__ ['config.get' ]('hubblestack:nova:autosync' , True ):
476493 sync ()
477- if not os .path .isdir (_hubble_dir ()):
478- return False , 'No synced nova modules found'
494+
495+ for nova_dir in _hubble_dir ():
496+ if not os .path .isdir (nova_dir ):
497+ return False , 'No synced nova modules/profiles found'
479498
480499 log .debug ('loading nova modules' )
481500
@@ -491,18 +510,28 @@ def load():
491510
492511def _hubble_dir ():
493512 '''
494- Generate the local minion directory to which nova modules are synced
513+ Generate the local minion directories to which nova modules and profiles
514+ are synced
515+
516+ Returns a tuple of two paths, the first for nova modules, the second for
517+ nova profiles
495518 '''
496- nova_dir = __salt__ ['config.get' ]('hubblestack:nova:dir' , 'hubblestack_nova' )
519+ nova_profile_dir = __salt__ ['config.get' ]('hubblestack:nova:profile_dir' ,
520+ 'salt://hubblestack_nova_profiles' )
521+ nova_module_dir = __salt__ ['config.get' ]('hubblestack:nova:module_dir' ,
522+ 'salt://hubblestack_nova_modules' )
523+ dirs = []
497524 # Support optional salt:// in config
498- if 'salt://' in nova_dir :
499- _ , _ , nova_dir = nova_dir .partition ('salt://' )
500- saltenv = __salt__ ['config.get' ]('hubblestack:nova:saltenv' , 'base' )
501- cachedir = os .path .join (__opts__ .get ('cachedir' ),
502- 'files' ,
503- saltenv ,
504- nova_dir )
505- return cachedir
525+ for nova_dir in (nova_module_dir , nova_profile_dir ):
526+ if 'salt://' in nova_dir :
527+ _ , _ , nova_dir = nova_dir .partition ('salt://' )
528+ saltenv = __salt__ ['config.get' ]('hubblestack:nova:saltenv' , 'base' )
529+ cachedir = os .path .join (__opts__ .get ('cachedir' ),
530+ 'files' ,
531+ saltenv ,
532+ nova_dir )
533+ dirs .append (cachedir )
534+ return tuple (dirs )
506535
507536
508537def _calculate_compliance (results ):
@@ -526,7 +555,7 @@ def _get_top_data(topfile):
526555 '''
527556 Helper method to retrieve and parse the nova topfile
528557 '''
529- topfile = os .path .join (_hubble_dir (), topfile )
558+ topfile = os .path .join (_hubble_dir ()[ 1 ] , topfile )
530559
531560 try :
532561 with open (topfile ) as handle :
@@ -558,7 +587,7 @@ class NovaLazyLoader(LazyLoader):
558587 '''
559588
560589 def __init__ (self ):
561- super (NovaLazyLoader , self ).__init__ ([ _hubble_dir ()] ,
590+ super (NovaLazyLoader , self ).__init__ (_hubble_dir (),
562591 opts = __opts__ ,
563592 tag = 'nova' )
564593 self .__data__ = {}
@@ -597,6 +626,14 @@ def refresh_file_mapping(self):
597626 # Nova only supports .py and .yaml
598627 if ext not in ['.py' , '.yaml' ]:
599628 continue
629+ # Python only in the modules directory, yaml only
630+ # in the profiles directory. This is hacky but was a
631+ # quick fix.
632+ nova_module_cache , nova_profile_cache = _hubble_dir ()
633+ if ext == '.py' and fpath .startswith (nova_profile_cache ):
634+ continue
635+ if ext == '.yaml' and fpath .startswith (nova_module_cache ):
636+ continue
600637 if f_withext in self .disabled :
601638 #log.trace(
602639 # 'Skipping {0}, it is disabled by configuration'.format(
0 commit comments