Commit 921b6c10 authored by Bruno Boiget's avatar Bruno Boiget Committed by Matthieu Lamalle

426 conf to deploy

parent fa33767a
base:
'*':
- pillars_{{ grains['id'] }}
- pillars_files_{{ grains['id'] }}
......@@ -101,10 +101,29 @@ class SaltRunner(ZephirCommonController):
except SaltJobsErrorUnknownJobId as err:
raise ApplicationError('execution.salt.job.error.unknown-jid', reason=str(err))
def pillar_clear_cache(self, minion_pattern):
self.executor.exec_command(minion_pattern=minion_pattern,
command='saltutil.clear_cache')
@register_wamp('v1.server.configuration.updated', None)
async def configuration_update(self, server_id):
server = await self.call('v1.server.describe',
serverid=server_id,
configuration=True)
pillar_file_path = '/srv/pillar/pillars_{0}.sls'.format(server_id)
with open(pillar_file_path, 'w') as fh:
if json.loads(server['configuration']):
yaml.dump(json.loads(server['configuration']), fh, allow_unicode=True)
else:
yaml.dump({}, fh)
self.pillar_clear_cache(str(server_id))
@register_wamp('v1.execution.salt.configuration.deploy',
notification_uri='v1.execution.salt.configuration.deploy-scheduled')
async def configuration_deploy(self,_session_user, minion_pattern):
await self.download_configuration_files(_session_user,int(minion_pattern))
async def configuration_deploy(self, minion_pattern):
await self.download_configuration_files(int(minion_pattern))
try:
deploy_command = 'state.apply'
......@@ -112,8 +131,7 @@ class SaltRunner(ZephirCommonController):
ret = self.executor.exec_command(minion_pattern=minion_pattern,
command=deploy_command,
arg=deploy_arg)
self.executor.exec_command(minion_pattern=minion_pattern,
command='saltutil.clear_cache')
self.pillar_clear_cache(minion_pattern)
return ret
except SaltExecErrorMissingMinionPattern as err:
......@@ -150,28 +168,18 @@ class SaltRunner(ZephirCommonController):
None,
'local')[server_id]
async def download_configuration_files(self,_session_user,
async def download_configuration_files(self,
server_id):
minion_dir = '{0}{1}'.format(MINION_DIR, server_id)
creolefuncs_file_path = '{0}/config.creolefuncs'.format(minion_dir)
pillar_file_path = '/srv/pillar/pillars_{0}.sls'.format(server_id)
pillar_file_path = '/srv/pillar/pillars_files_{0}.sls'.format(server_id)
creole_files_path = '{0}/creole_files.tar.gz'.format(minion_dir)
server = await self.call('v1.server.describe',
_session_user=_session_user,
serverid=server_id,
configuration=True)
serverid=server_id)
servermodel_id = server['servermodelid']
with open(pillar_file_path, 'w') as fh:
if json.loads(server['configuration']):
yaml.dump(json.loads(server['configuration']), fh, allow_unicode=True)
else:
yaml.dump({}, fh)
fh.close()
del server
servermodel = await self.call('v1.servermodel.describe',
servermodelid=servermodel_id,
......@@ -205,10 +213,9 @@ class SaltRunner(ZephirCommonController):
eoleconfig['eole']['configuration']['files'][pathtofile]['owner'] = 'root'
eoleconfig['eole']['configuration']['files'][pathtofile]['group'] = 'root'
eoleconfig['eole']['configuration']['files'][pathtofile]['mode'] = mode
if json.loads(server['configuration']):
with open(pillar_file_path, 'a') as fh:
fh.write(yaml.dump(eoleconfig, default_flow_style=False))
del server
# if json.loads(server['configuration']):
with open(pillar_file_path, 'w') as fh:
fh.write(yaml.dump(eoleconfig, default_flow_style=False))
self._download_env(server_id, servermodel)
def _download_env(self, server_id, servermodel):
......@@ -221,9 +228,7 @@ class SaltRunner(ZephirCommonController):
async def download_env(self,server_id):
_session_user = {'profil': 'root'}
server = await self.call('v1.server.describe',
_session_user=_session_user,
serverid=server_id)
servermodel = await self.call('v1.servermodel.describe',
servermodelid=server['servermodelid'],
......@@ -234,9 +239,9 @@ class SaltRunner(ZephirCommonController):
self._download_env(server_id, servermodel)
@register_wamp('v1.server.created', notification_uri='v1.execution.salt.peer.registered')
async def peer_register(self,_session_user,serverid):
async def peer_register(self, serverid):
try:
await self.download_configuration_files(_session_user,serverid)
await self.download_configuration_files(serverid)
secret = await self.call('v1.vault.secret.get', secretkey="{}_passphrase".format(serverid))
passphrase = secret["secret"]["passphrase"]
minion_id = str(serverid)
......@@ -247,6 +252,12 @@ class SaltRunner(ZephirCommonController):
"pub_key": pub_key,
"ciphered_priv_key": ciphered_priv_key.decode()}
await self.call('v1.vault.secret.set', secretkey="{}_peeringconf".format(serverid), secret=secrets)
pillar_conf_path = '/srv/pillar/pillars_{0}.sls'.format(serverid)
pillar_file_path = '/srv/pillar/pillars_files_{0}.sls'.format(serverid)
with open(pillar_file_path, 'w'):
pass
with open(pillar_conf_path, 'w'):
pass
return {"serverid": serverid, "automation": "salt"}
except Exception as err:
import traceback
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment