Commit 67cca5bd authored by Matthieu Lamalle's avatar Matthieu Lamalle
Browse files

execute commande on serverselection's servers

parent a13ff09d
......@@ -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 self._exec_cmd_on_server(cursor, server_id, command)
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,19 @@ 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:
ret.append(self._exec_cmd_on_server(cursor, server_id, command))
return ret
if __name__ == '__main__':
run(ServerRunner)
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