/
mc_macros.py
executable file
·845 lines (737 loc) · 25.1 KB
/
mc_macros.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
# -*- coding: utf-8 -*-
'''
.. _module_mc_macros:
mc_macros / macros helpers
============================================
'''
# Import salt libs
import msgpack
import os
import copy
import json
import tempfile
import hashlib
import logging
import time
import traceback
import yaml
from salt.utils import yamldumper
from salt.renderers.yaml import get_yaml_loader
from salt.exceptions import SaltException
from salt.utils.odict import OrderedDict
from mc_states.api import _GLOBAL_KINDS
from mc_states.api import _SUB_REGISTRIES
import mc_states.api
import mc_states.saltapi
# retrocompat
from mc_states.saltapi import NoRegistryLoaderFound
six = mc_states.api.six
# cache variable
_REGISTRY = {}
_default_activation_status = object()
_LOCAL_REG_CACHE = {}
NOT_SHARED = [] # retrocompat
log = logging.getLogger(__name__)
DEFAULT_SUF = 'makina-states.local'
DEFAULT_LOCAL_REG_NAME = '{0}.{{0}}'.format(DEFAULT_SUF)
RKEY = 'mcreg_{0}_{1}'
REGISTRY_FORMATS = ['pack', 'yaml', 'json']
_default = object()
def get_registry_formats():
return copy.deepcopy(REGISTRY_FORMATS)
# normally not more used
# def registry_kind_get(kind):
# if not kind in _REGISTRY:
# _REGISTRY[kind] = {}
# return _REGISTRY[kind]
# def registry_kind_set(kind, value):
# _REGISTRY[kind] = value
def is_item_active(registry_name,
item,
default_status=False,
grains_pref=None,
force=False):
'''
Look in pillar/grains/localconfig for registry
activation status
'''
if not grains_pref:
grains_pref = 'makina-states.{0}'.format(registry_name)
local_reg = get_local_registry(registry_name)
for config_entry in [
grains_pref + ".is." + item,
grains_pref + "." + item
]:
if force:
val = default_status
else:
val = __salt__['mc_utils.get'](config_entry,
_default,
local_registry=local_reg)
if val is not _default:
break
if val is _default:
val = default_status
return val
def get_lock_name(registry_name, registry_format):
lockp = 'localregistry_{0}_{1}'.format(registry_name, registry_format)
return lockp
def load_kind_registries(kind):
# load all registries
if kind not in _REGISTRY:
_REGISTRY[kind] = {}
for registry in _SUB_REGISTRIES:
if registry in _REGISTRY[kind]:
continue
try:
_REGISTRY[kind][registry] = __salt__[
'mc_{0}.{1}'.format(kind, registry)]()
except KeyError:
trace = traceback.format_exc()
raise mc_states.saltapi.NoRegistryLoaderFound(
'mc_{0}.{1} is unavailable\n{2}'.format(kind, registry, trace))
return _REGISTRY[kind]
def load_registries():
# load all registries
for kind in _GLOBAL_KINDS:
load_kind_registries(kind)
return sorted([a for a in _REGISTRY])
def kinds():
# py3 compatible dict keys()
return [a for a in _GLOBAL_KINDS]
def metadata(kind, grain=None, state=None, bases=None):
if bases is None:
bases = []
return {'kind': kind, 'bases': bases}
def is_active(registry, name):
'''
Is the queried service active in the registry
'''
try:
return name in registry['actives']
except:
return False
def get_registry_paths(name=None, registry_format='pack'):
w = os.path.join(
os.path.dirname(os.path.abspath(__opts__['config_dir'])),
'makina-states')
confs = {'global': w, 'context': w}
return confs # RETROCOMPAT
def get_registry_path(name,
registry_format='yaml',
registryf=None,
context=None):
confs = get_registry_paths()
return os.path.join(
confs["global"], "{0}.{1}".format(name, registry_format))
def json_load_local_registry(name, registryf=None):
try:
with open(
get_registry_path(name,
registryf=registryf,
registry_format='json')
) as f:
registry = __salt__['mc_utils.json_load'](f.read())
except IOError:
pass
if not registry:
registry = {}
return registry
def json_dump_local_registry(registry):
content = __salt__['mc_utils.json_dump'](registry,
pretty=True)
return content
def yaml_load_local_registry(name, registryf=None):
registry = __salt__['mc_utils.yaml_load'](
get_registry_path(name,
registryf=registryf,
registry_format='yaml'),
is_file=True)
if not registry:
registry = {}
return registry
def yaml_dump_local_registry(registry):
content = __salt__['mc_utils.yaml_dump'](registry,
nonewline=False)
return content
def pack_load_local_registry(name, registryf=None):
value = {}
regpath = get_registry_path(name,
registryf=registryf,
registry_format='pack')
try:
if os.path.exists(regpath):
with open(regpath) as fic:
rvalue = fic.read()
value = __salt__['mc_utils.msgpack_load'](
rvalue)
except (msgpack.exceptions.UnpackValueError,
msgpack.exceptions.ExtraData):
log.error('decoding error, removing stale {0}'.format(regpath))
os.unlink(regpath)
value = {}
return value
def pack_dump_local_registry(registry):
'''
encode in a file using msgpack backend
'''
return __salt__['mc_utils.msgpack_dump'](registry)
def encode_local_registry(name, registry, registry_format='yaml'):
lockp = get_lock_name(name, registry_format)
with mc_states.api.wait_lock(lockp):
registryf = get_registry_path(
name, registry_format=registry_format)
dregistry = os.path.dirname(registryf)
content = __salt__[
'mc_macros.{0}_dump_local_registry'.format(
registry_format)](registry)
sync = False
if os.path.exists(registryf):
with open(registryf) as fic:
old_content = fic.read()
if old_content != content:
sync = True
else:
sync = True
if sync:
if not os.path.exists(dregistry):
os.makedirs(dregistry)
with open(registryf, 'w') as fic:
fic.write(content)
os.chmod(registryf, 0700)
def _get_local_registry(name,
cached=True,
cachetime=60,
registry_format='yaml'):
'''
Get local registry
Masteralt & Salt share all the local registries
unless for the main ones:
- controllers
- services
- nodetypes
- localsettings
- cloud
For backward compatibility, we take care to load and merge
shared registries in salt prefix if any is found.
'''
# cache local registries one minute
key = '{0}_{1}'.format('mcreg', name)
to_load = ['context']
def _do(name, to_load, registry_format):
registryfs = get_registry_paths()
registry = OrderedDict()
for prefix in to_load:
registryf = registryfs[prefix]
rp = get_registry_path(
name, registry_format=registry_format,
registryf=registryf)
if os.path.exists(rp):
data = __salt__[
'mc_macros.{0}_load_local_registry'.format(
registry_format)](name, registryf)
registry = __salt__['mc_utils.dictupdate'](registry, data)
_unprefix(registry, name)
return registry
cache_key = RKEY.format(key, registry_format)
force_run = not cached
lockp = get_lock_name(name, registry_format)
with mc_states.api.wait_lock(lockp):
return __salt__['mc_utils.memoize_cache'](
_do, [name, to_load, registry_format], {},
cache_key, cachetime, use_memcache=False,
force_run=force_run)
def _unprefix(registry, name):
# unprefix local simple registries
loc_k = DEFAULT_LOCAL_REG_NAME.format(name)
for k in [t for t in registry if t.startswith(loc_k)]:
spl = loc_k + '.'
nk = spl.join(k.split(spl)[1:])
registry[nk] = registry[k]
registry.pop(k)
return registry
def get_local_registry(name,
cached=True,
cachetime=60,
registry_format='yaml'):
local_registry = _get_local_registry(
name,
cached=cached,
cachetime=cachetime,
registry_format=registry_format)
# try to find the localreg in another format
if not local_registry:
formats = [
a
for a in get_registry_formats()
if not a == registry_format]
for f in formats:
local_registry = _get_local_registry(
name,
cached=cached,
cachetime=cachetime,
registry_format=f)
if local_registry:
break
_unprefix(local_registry, name)
return local_registry
def update_registry_params(registry_name, params, registry_format='yaml'):
'''
Update the desired local registry
'''
__salt__['mc_utils.invalidate_memoize_cache'](
RKEY.format(registry_name, registry_format))
registry = get_local_registry(registry_name,
cached=False,
registry_format=registry_format)
changes = {}
topreg_name = 'mc_{0}.registry'.format(registry_name)
default = True
if topreg_name in __salt__:
registry_obj = __salt__[topreg_name]()
pref = registry_obj['grains_pref']
default = False
else:
pref = DEFAULT_LOCAL_REG_NAME.format(registry_name)
for param, value in six.iteritems(params):
gparam = param
if (
not param.startswith(pref) and
not param.startswith('makina-states.')
):
gparam = '{0}.{1}'.format(pref, param)
reg_value = registry.get(gparam, _default)
if reg_value != value:
for data in changes, registry:
data.update({gparam: value})
if (
default and
(not param.startswith('makina-states.')) and
(param in registry)
):
del registry[param]
if changes:
encode_local_registry(
registry_name, registry, registry_format=registry_format)
__salt__['mc_utils.invalidate_memoize_cache'](
RKEY.format(registry_name, registry_format))
return changes
def update_local_registry(registry_name, params, registry_format='yaml'):
'''
Alias to update_local_registry
'''
ret = update_registry_params(registry_name,
params,
registry_format=registry_format)
return ret
def get_registry(registry_configuration):
'''
Mangle a registry of activated/unactived states to be run
as part of the automatic highstate inclusion.
::
{
'kind': 'foo',
'bases': ['localsettings'],
'defaults': {
'foo': {'active': False},
'bar': {'active': False},
'moo': {'active': True}
}
}
}
Will activate the 'makina-states.controllers.salt_master' and
deactivate all other states to be automaticly run
EG, for automatic activation of firewalld,
lookup in Configs for this key (pillar, grains, reg)::
makina-states.services.is.firewall.firewalld: true
makina-states.services.firewall.firewalld: true
Idea why for the dict containing 'active', i did not choosed
a simple boolean is to support other data in the near future.
We return here a registry in the form::
{
'kind': 'foo',
'bases': ['localsettings'],
'states_pref': 'makina-states.foo',
'grains_pref': 'makina-states.foo',
'activated': {'salt_master': {'active': True}},
'unactivated': {
'foo': {'active': False},
'bar': {'active': False},
'moo': {'active': False},
},
'defaults': {
'foo': {'active': False},
'bar': {'active': False},
'moo': {'active': False},
'boo': {'active': True}
}
}
}
'''
registry = registry_configuration.copy()
registry.setdefault('is', {})
registry['grains_pref'] = 'makina-states.{0}'.format(registry['kind'])
registry['states_pref'] = 'makina-states.{0}'.format(registry['kind'])
registry.setdefault('actives', {})
registry.setdefault('unactivated', {})
registry.setdefault('availables', {})
for item, data in registry['defaults'].items():
activation_status = _default_activation_status
if isinstance(data, dict):
activation_status = __salt__[
'mc_macros.is_item_active'](
registry['kind'],
item,
default_status=data.get('active',
activation_status),
force=data.get('force', False))
if activation_status is not _default_activation_status:
if activation_status:
registry['actives'][item] = data
registry['is'][item] = True
else:
registry['unactivated'][item] = data
registry['is'][item] = False
else:
registry['availables'][item] = data
# synonym has for is
registry['has'] = registry['is']
return registry
def construct_registry_configuration(name, defaults=None):
'''
Helper to factorise registry mappings
'''
metadata_reg = __salt__['mc_{0}.metadata'.format(name)]()
if not defaults:
defaults = {}
return __salt__['mc_macros.get_registry']({
'kind': metadata_reg['kind'],
'bases': metadata_reg['bases'],
'defaults': defaults})
def unregister(kind, slss, data=None, suf=''):
'''
Unregister a/some service(s) in the local registry
'''
state = '\n'
if isinstance(slss, basestring):
slss = [slss]
if slss is None:
slss = []
data = locals()
if slss:
data['name'] = '-'.join(slss)
state += (
'makina-states-unregister.{kind}'
'.{name}{suf}:\n').format(**data)
state += ' mc_registry.absent:\n'
state += ' - name: {kind}\n'.format(**data)
state += ' - slss:\n'
for sls in slss:
state += ' - {0}\n'.format(sls)
state += ' - order: 9999\n'
state += '\n'
return state
def register(kind, slss, data=None, suf=''):
'''
Register a/some service(s) in the local registry
'''
state = '\n'
if isinstance(slss, basestring):
slss = [slss]
if slss is None:
slss = []
data = locals()
if slss:
data['name'] = '-'.join(slss)
state += 'makina-states-register.{kind}.{name}{suf}:\n'.format(**data)
state += ' mc_registry.present:\n'
state += ' - name: {kind}\n'.format(**data)
state += ' - slss:\n'
for sls in slss:
state += ' - {0}\n'.format(sls)
state += ' - order: 9999\n'
state += '\n'
return state
def autoinclude(reg, additional_includes=None):
'''
Helper to autoload & (un)register services in a top file
'''
sls = ''
if not additional_includes:
additional_includes = []
bases = reg.get('bases', [])
includes = []
slses = []
for base in bases:
includes.append(' - makina-states.{base}\n'.format(base=base))
slses.append('makina-states.{base}\n'.format(base=base))
for state, data in reg.get('actives', {}).items():
includes.append(' - {rstatesPref}.{state}\n'.format(
rstatesPref=reg['states_pref'], state=state))
slses.append('{rstatesPref}.{state}\n'.format(
rstatesPref=reg['states_pref'], state=state))
includes.extend([' - {0}\n'.format(a)
for a in additional_includes])
slses.extend(['{0}\n'.format(a) for a in additional_includes])
if includes:
includes.insert(0, 'include:\n')
sls += ''.join(includes)
# more harm than good, cycle errors are too easilly triggered
# between kinds
#sls += '''
#{kind}-postinstall-hook:
# mc_proxy.hook:
# - watch:
#{requires}
#'''.format(kind=reg['kind'], requires='\n'.join(
# [' - sls: {0}'.format(s) for s in slses]))
slss = []
for state, data in reg.get('actives', {}).items():
slss.append(state)
sls += '\n{0}\n'.format(
__salt__['mc_macros.register'](reg['kind'], slss, suf='auto'))
slss = []
for state, data in reg.get('unactivated', {}).items():
slss.append(state)
sls += '\n{0}\n'.format(
__salt__['mc_macros.unregister'](reg['kind'], slss, suf='auto'))
return sls
def get_local_cache_key(key):
return mc_states.saltapi.get_cache_key(key, __opts__)
def _cache_entry(local_reg, key, ttl=1):
data = local_reg.get(key, OrderedDict())
if not isinstance(data, dict):
data = OrderedDict()
data.setdefault('ttl', ttl)
data.setdefault('value', _default)
data.setdefault('time', time.time())
return data
def default_cache_value():
return _default
def store_local_cache(registry, local_reg, ttl=1):
now = time.time()
# expire old entries
for k in [a for a in local_reg]:
data = _cache_entry(local_reg, k)
if now > data['time'] + data['ttl']:
local_reg.pop(k, None)
__salt__['mc_macros.update_local_registry'](
registry, local_reg, registry_format='pack')
local_reg = __salt__['mc_macros.get_local_registry'](
registry, registry_format='pack')
return local_reg
def save_local_cached_entry(value,
key=None,
sha1_key=None,
ttl=1,
registry='disk_cache'):
if not (key or sha1_key):
raise ValueError('provide at least key or sha1_key')
if not sha1_key:
sha1_key = get_local_cache_key(key)
local_reg = __salt__['mc_macros.get_local_registry'](
registry, registry_format='pack')
data = _cache_entry(local_reg, sha1_key, ttl=ttl)
now = time.time()
if (now > data['time'] + ttl) or (value is not _default):
data['ttl'] = ttl
data['time'] = now
data['value'] = value
local_reg[sha1_key] = data
local_reg = store_local_cache(registry,
local_reg,
ttl=ttl)
return local_reg
def get_local_cached_entry(key,
default=_default,
ttl=1,
soft=False,
registry='disk_cache'):
local_reg = __salt__['mc_macros.get_local_registry'](
registry, registry_format='pack')
sha1_key = get_local_cache_key(key)
data = _cache_entry(local_reg, sha1_key, ttl=ttl)
now = time.time()
value = _default
if ttl and (now <= data['time'] + ttl):
value = data['value']
data['value'] = value
if value is _default and not soft:
raise KeyError(key)
return data
def filecache_fun(func,
args=None,
kwargs=None,
registry='disk_cache',
prefix=None,
ttl=1):
'''
Execute a function and store the result in a filebased cache
func
func to execute
args
positional args to func
kwargs
kwargs to func
registry
name of the file inside /etc/makina-states
prefix
cache key
ttl
if 0: do not use cache
'''
if isinstance(kwargs, dict):
kwargs = copy.deepcopy(kwargs)
for k in [a for a in kwargs]:
if k.startswith('__pub_'):
kwargs.pop(k, None)
if not prefix:
prefix = '{0}'.format(func)
key = '{0}_'.format(prefix)
try:
key += json.dumps(args)
except TypeError:
try:
key += '{0}'.format(repr(args))
except Exception:
key += ''
try:
key += json.dumps(kwargs)
except TypeError:
try:
key += '{1}'.format(repr(kwargs))
except Exception:
key += ''
data = get_local_cached_entry(key, ttl=ttl, soft=True)
value = data['value']
# if value is default, we have either no value
# or the cache entry was expired
if value is _default:
if args is not None and kwargs is not None:
value = func(*args, **kwargs)
elif args is not None and (kwargs is None):
value = func(*args)
elif (args is None) and kwargs is not None:
value = func(**kwargs)
else:
value = func()
try:
save_local_cached_entry(value,
key,
registry=registry,
ttl=ttl)
except Exception:
log.error(traceback.format_exc())
# dont fail for a failed cache set
else:
log.garbage('Using filecache !')
return value
def glob_dump():
try:
return copy.deepcopy(_GLOBAL_KINDS)
except (TypeError, ValueError):
return _GLOBAL_KINDS
def sub_dump():
try:
return copy.deepcopy(_SUB_REGISTRIES)
except (TypeError, ValueError):
return _SUB_REGISTRIES
def dump():
try:
return copy.deepcopy(_REGISTRY)
except (TypeError, ValueError):
return _REGISTRY
def add_pillar_dirs(pillars, proot, id_):
_o = __opts__
pillar = pillars.setdefault(id_, [])
dirs = [
os.path.join(
proot,
'overrides/{0}.pillar.d'.format(id_)),
os.path.join(
proot, '{0}.pillar.d'.format(id_))]
if id_ == _o['id']:
dirs.extend([
os.path.join(
proot, 'overrides/private.pillar.d'),
os.path.join(
proot, 'private.pillar.d')
])
for i in dirs:
if i not in pillar:
pillar.append(i)
return pillars
def get_pillar_dss(ids_=None):
_s = __salt__
_o = __opts__
if ids_ and isinstance(ids_, six.string_types):
ids_ = ids_.split(',')
if not ids_:
ids_ = [_o['id']]
ids_ = ids_[:]
locs = _s['mc_locations.settings']()
proot = locs['pillar_root']
pillars = OrderedDict([
('*', [
os.path.join(
proot, 'overrides/pillar.d'),
os.path.join(
proot, 'pillar.d')])
])
for id_ in ids_:
add_pillar_dirs(pillars, proot, id_)
if os.path.exists(proot):
for i in os.listdir(proot):
ai = os.path.join(proot, i)
if not os.path.isdir(ai):
continue
if (
not i.endswith('private.pillar.d') and
i != 'pillar.d' and
i.endswith('.pillar.d')
):
id_ = i.split('.pillar.d')[0]
add_pillar_dirs(pillars, proot, id_)
return pillars
def get_pillar_top_files(pillar_autoincludes=None,
mc_projects=None,
refresh_projects=None):
_o = __opts__
_s = __salt__
top = {__opts__['id']: set(), '*': set()}
locs = _s['mc_locations.settings']()
pdir = os.path.join(locs['pillar_root'], 'makina-projects')
pillar_dss = get_pillar_dss()
# we can autoinclude only what is registered
# under the pillar_roots directive (private & global)
# we can only feed wia the json extpillar
# data per host which is not the current host
for section, pillar_ds in six.iteritems(pillar_dss):
if section not in ['*', _o['id']]:
continue
for pillar_d in pillar_ds:
if _o['id'] in pillar_d:
continue
if not os.path.exists(pillar_d):
continue
for sf in os.listdir(pillar_d):
f = os.path.join(pillar_d, sf)
if (
f.endswith('.sls') and
(os.path.isfile(f) or
(os.path.islink(f) and os.path.isfile(os.readlink(f))))
):
top[section].add(sf.split('.sls', 1)[0])
if refresh_projects is not False:
_s['mc_project.link_projects']()
if mc_projects is not False:
projects = _s['mc_project.list_projects']()
for pj, cfg in six.iteritems(projects):
pdir = cfg['wired_pillar_root']
initsls = os.path.join(pdir, 'init.sls')
if os.path.exists(initsls):
top['*'].add('makina-projects.{0}'.format(pj))
for s in [a for a in top]:
top[s] = [a for a in top[s]]
return top
# vim:set ai: