1 |
1 |
# hobo - portal to configure and deploy applications
|
|
2 |
irint action, data
|
2 |
3 |
# Copyright (C) 2015 Entr'ouvert
|
3 |
4 |
#
|
4 |
5 |
# This program is free software: you can redistribute it and/or modify it
|
... | ... | |
14 |
15 |
# You should have received a copy of the GNU Affero General Public License
|
15 |
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 |
17 |
|
|
18 |
import time
|
17 |
19 |
import sys
|
18 |
20 |
import ConfigParser
|
19 |
21 |
import fnmatch
|
... | ... | |
27 |
29 |
|
28 |
30 |
from . import settings
|
29 |
31 |
|
|
32 |
from hobo.agent.common.management.hobo_batch_client import BatchClient
|
|
33 |
|
30 |
34 |
|
31 |
35 |
class BaseService(object):
|
|
36 |
batch_support = True
|
|
37 |
_batch_process = None
|
|
38 |
|
32 |
39 |
def __init__(self, base_url, title, secret_key, **kwargs):
|
33 |
40 |
self.base_url = base_url
|
34 |
41 |
self.title = title
|
... | ... | |
74 |
81 |
stdout = cmd_process.communicate(input=json.dumps(environment))
|
75 |
82 |
|
76 |
83 |
@classmethod
|
|
84 |
def get_batch_process(cls):
|
|
85 |
if not cls._batch_process or cls._batch_process.process.returncode:
|
|
86 |
cls._batch_process = BatchClient(cls.service_manage_cmd + ' hobo_batch')
|
|
87 |
return cls._batch_process
|
|
88 |
|
|
89 |
@classmethod
|
77 |
90 |
def notify(cls, data):
|
78 |
91 |
for audience in data.get('audience', []):
|
79 |
92 |
if cls.is_for_us(audience):
|
... | ... | |
82 |
95 |
return
|
83 |
96 |
if not os.path.exists(cls.service_manage_try_cmd):
|
84 |
97 |
return
|
85 |
|
cmd = cls.service_manage_cmd + ' hobo_notify -'
|
86 |
|
try:
|
87 |
|
cmd_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
|
88 |
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
89 |
|
except OSError:
|
90 |
|
return
|
91 |
|
stdout, stderr = cmd_process.communicate(input=json.dumps(data))
|
92 |
|
if cmd_process.returncode != 0:
|
93 |
|
raise RuntimeError('command "%s" failed: %r %r' % (cmd, stdout, stderr))
|
|
98 |
if cls.batch_support:
|
|
99 |
batch = cls.get_batch_process()
|
|
100 |
returncode, stdout = batch.execute(['hobo_notify', '-'], json.dumps(data))
|
|
101 |
if returncode != 0:
|
|
102 |
raise RuntimeError('command "hobo_notify -" failed: %r %r' % (returncode, stdout))
|
|
103 |
else:
|
|
104 |
cmd = cls.service_manage_cmd + ' hobo_notify -'
|
|
105 |
try:
|
|
106 |
cmd_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
|
|
107 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
108 |
except OSError:
|
|
109 |
return
|
|
110 |
stdout, stderr = cmd_process.communicate(input=json.dumps(data))
|
|
111 |
if cmd_process.returncode != 0:
|
|
112 |
raise RuntimeError('command "%s" failed: %r %r' % (cmd, stdout, stderr))
|
94 |
113 |
|
95 |
114 |
|
96 |
115 |
class Passerelle(BaseService):
|
97 |
|
-
|