10
10
See README for documentation
11
11
12
12
Configuration:
13
- - hubblestack:nova:dir
13
+ - hubblestack:nova:module_dir
14
+ - hubblestack:nova:profile_dir
14
15
- hubblestack:nova:saltenv
15
16
- hubblestack:nova:autoload
16
17
- hubblestack:nova:autosync
@@ -299,7 +300,8 @@ def top(topfile='top.nova',
299
300
Arguments:
300
301
301
302
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.
303
305
304
306
verbose
305
307
Whether to show additional information about audits, including
@@ -413,21 +415,27 @@ def top(topfile='top.nova',
413
415
return results
414
416
415
417
416
- def sync ():
418
+ def sync (clean = False ):
417
419
'''
418
- Sync the nova audit modules from the saltstack fileserver.
420
+ Sync the nova audit modules and profiles from the saltstack fileserver.
419
421
420
422
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 ``)
424
426
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``)
426
431
427
- Returns the minion's path to the cached directory
432
+ Modules and profiles will be cached in the normal minion cachedir
428
433
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
431
439
432
440
CLI Examples:
433
441
@@ -437,35 +445,44 @@ def sync():
437
445
salt '*' nova.sync saltenv=hubble
438
446
'''
439
447
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' )
441
452
saltenv = __salt__ ['config.get' ]('hubblestack:nova:saltenv' , 'base' )
442
453
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
-
450
454
# 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 )
464
476
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
469
486
470
487
471
488
def load ():
@@ -474,8 +491,10 @@ def load():
474
491
'''
475
492
if __salt__ ['config.get' ]('hubblestack:nova:autosync' , True ):
476
493
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'
479
498
480
499
log .debug ('loading nova modules' )
481
500
@@ -491,18 +510,28 @@ def load():
491
510
492
511
def _hubble_dir ():
493
512
'''
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
495
518
'''
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 = []
497
524
# 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 )
506
535
507
536
508
537
def _calculate_compliance (results ):
@@ -526,7 +555,7 @@ def _get_top_data(topfile):
526
555
'''
527
556
Helper method to retrieve and parse the nova topfile
528
557
'''
529
- topfile = os .path .join (_hubble_dir (), topfile )
558
+ topfile = os .path .join (_hubble_dir ()[ 1 ] , topfile )
530
559
531
560
try :
532
561
with open (topfile ) as handle :
@@ -558,7 +587,7 @@ class NovaLazyLoader(LazyLoader):
558
587
'''
559
588
560
589
def __init__ (self ):
561
- super (NovaLazyLoader , self ).__init__ ([ _hubble_dir ()] ,
590
+ super (NovaLazyLoader , self ).__init__ (_hubble_dir (),
562
591
opts = __opts__ ,
563
592
tag = 'nova' )
564
593
self .__data__ = {}
@@ -597,6 +626,14 @@ def refresh_file_mapping(self):
597
626
# Nova only supports .py and .yaml
598
627
if ext not in ['.py' , '.yaml' ]:
599
628
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
600
637
if f_withext in self .disabled :
601
638
#log.trace(
602
639
# 'Skipping {0}, it is disabled by configuration'.format(
0 commit comments