Commit 31d39f31 authored by Philippe Caseiro's avatar Philippe Caseiro
Browse files

Merge branch '59_execution_commande' into 'develop'

59 execution commande

See merge request !4
parents a13ff09d a3566724
......@@ -38,7 +38,7 @@ RUN git clone "${CONTAINERPILOT_REPO_URL}" "/tmp/orchestrate" \
# API messages description
ARG MESSAGES_API_REPO_URL=https://gitlab.mim.ovh/EOLE/Zephir/messages-api.git
ARG MESSAGES_API_REPO_REF=9f534509
ARG MESSAGES_API_REPO_REF=0.0.3-dev
RUN git clone "${MESSAGES_API_REPO_URL}" "/tmp/messages-api" \
&& cd /tmp/messages-api \
......
......@@ -27,7 +27,7 @@ from server.serverselection.error import (ServerSelectionError,
ServerSelectionErrorUnknownServerSelectionId,
ServerSelectionErrorDuplicateServerSelectionName,
ServerSelectionEmptyRecordDatabaseError)
from zephir.config import ServiceConfig
......@@ -59,7 +59,6 @@ class ServerRunner(ZephirCommonController):
@register_wamp('v1.server.describe', notification_uri=None, database=True)
async def describe_server(self, cursor, serverid, configuration):
try:
server = self.server.describe_server(cursor, serverid)
if configuration:
......@@ -99,19 +98,19 @@ class ServerRunner(ZephirCommonController):
@register_wamp('v1.server.create', notification_uri='v1.server.created', database=True)
async def create_server(self, cursor, _session_user, servername, serverdescription, servermodelid, serverpassphrase):
try:
result = self.server.create_server(cursor, servername, serverdescription, servermodelid)
return_code = await self.call('v1.vault.secret.set',
secretkey="{}_passphrase".format(result['serverid']),
secret={"passphrase" : serverpassphrase})
if return_code:
if return_code:
defaultserverselection = self._default_user_serverselection(cursor, _session_user)
self.serverselection.add_server_to_selection(cursor, result['serverid'], defaultserverselection['serverselectionid'])
return result
else:
raise ServerError('put passphrase return code status not available')
raise ServerError('put passphrase return code status not available')
except ServerErrorDatabaseNotAvailable as err:
raise ApplicationError('server.error.database-not-available', reason=str(err))
......@@ -191,6 +190,9 @@ class ServerRunner(ZephirCommonController):
@register_wamp('v1.server.exec.command', notification_uri='v1.server.executed', database=True)
async def exec_cmd_on_server(self, cursor, server_id, command):
return await self._exec_cmd_on_server(cursor, server_id, command)
async def _exec_cmd_on_server(self, cursor, server_id, command):
"""
Transfer command transmitted to automation (salt, ...)
"""
......@@ -261,6 +263,7 @@ class ServerRunner(ZephirCommonController):
if automation == 'salt':
results = await self.call('v1.execution.salt.job.describe',
jid=str(job_id))
else:
raise Exception(_('Automation engine not supported: {}').format(automation))
ret = []
......@@ -521,5 +524,29 @@ class ServerRunner(ZephirCommonController):
except ServerSelectionError as err:
raise ApplicationError('serverselection.error', reason=str(err))
@register_wamp('v1.serverselection.exec.command', notification_uri=None, database=True) #FIXME notification
async def exec_cmd_on_serverserverselection(self, cursor, serverselection_id, command):
"""
Transfer command transmitted to automation (salt, ...)
"""
servers = self.serverselection.describe_serverselection(cursor, serverselection_id)['serverselectionserversid']
ret = []
for server_id in servers:
try:
ret.append(await self._exec_cmd_on_server(cursor, server_id, command))
except ServerErrorUnknownServerId as err:
ret.append({'job_id': '',
'server_id': server_id,
'command': command,
'automation': 'salt',
'executed': True,
'success': False,
'retcode': 1,
'return': str(err)})
return ret
if __name__ == '__main__':
run(ServerRunner)
......@@ -160,7 +160,7 @@ def fetch_server_dict(cursor, serverid: int):
def fetch_server(cursor, serverid: int):
fetched = fetchone(cursor, FETCH_SERVER, (serverid,))
if fetched is None:
raise Exception(_('unable to find a server with ID {}').format(serverid))
raise ServerErrorUnknownServerId(_('unable to find a server with ID {}').format(serverid))
return fetched
......
Supports Markdown
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