Commit d66269ec authored by Cédric de Saint Martin's avatar Cédric de Saint Martin

Merge branch 'agent'

parents e2c6b0ab a57f9d57
...@@ -34,76 +34,45 @@ from slapos.recipe.librecipe import GenericSlapRecipe ...@@ -34,76 +34,45 @@ from slapos.recipe.librecipe import GenericSlapRecipe
import json import json
import ConfigParser import ConfigParser
# XXX: BaseSlapRecipe and GenericSlapRecipe are deprecated, use
# GenericBaseRecipe and move partition parameter fetching to software release.
class Recipe(BaseSlapRecipe, GenericSlapRecipe): class Recipe(BaseSlapRecipe, GenericSlapRecipe):
def install(self): def install(self):
self.path_list = [] self.path_list = []
self.crond = self.installCrond() crond = self.installCrond()
slap = slapos.slap.slap() slap = slapos.slap.slap()
computer_id = self.computer_id slap.initializeConnection(self.server_url, self.key_file, self.cert_file)
computer_partition_id = self.computer_partition_id parameter_dict = slap.registerComputerPartition(
server_url = self.server_url self.computer_id,
key_file = self.key_file self.computer_partition_id,
cert_file = self.cert_file ).getInstanceParameterDict()
slap.initializeConnection(server_url, key_file, cert_file)
self.computer_partition = slap.registerComputerPartition(
computer_id, computer_partition_id)
self.parameter_dict = self.computer_partition.getInstanceParameterDict()
# XXX: should probably expect one more (SR-originating) parameter instead
# of using self.work_directory .
configuration_path = os.path.join(self.work_directory, "agent.cfg") configuration_path = os.path.join(self.work_directory, "agent.cfg")
configuration = ConfigParser.SafeConfigParser() with open(configuration_path, "w") as configuration:
configuration.add_section("agent") configuration.write(parameter_dict["configuration"])
configuration.set("agent", "portal_url", self.parameter_dict["portal_url"]) agent_crond_path = os.path.join(crond, "agent")
configuration.set("agent", "master_url", self.parameter_dict["master_url"]) with open(agent_crond_path, "w") as agent_crond:
configuration.set("agent", "report_url", self.parameter_dict["report_url"]) agent_crond.write("*/5 * * * * %s -S %s --pidfile=%s --log=%s "
key_filepath = os.path.join(self.work_directory, "key") "%s 2>&1 > /dev/null\n" % (
key_file = open(key_filepath, "w") self.options["python_binary"],
key_file.write(self.parameter_dict["key"]) self.options["agent_binary"],
key_file.close() self.options["pidfile"],
configuration.set("agent", "key_file", key_filepath) self.options["log"],
cert_filepath = os.path.join(self.work_directory, "cert") configuration_path,
cert_file = open(cert_filepath, "w") ))
cert_file.write(self.parameter_dict["cert"])
cert_file.close()
configuration.set("agent", "cert_file", cert_filepath)
configuration.set("agent", "maximum_software_installation_duration",
self.parameter_dict["maximum_software_installation_duration"])
configuration.set("agent", "software_live_duration",
self.parameter_dict["software_live_duration"])
configuration.set("agent", "computer_list",
self.parameter_dict["computer_list"])
configuration.set("agent", "software_list",
self.parameter_dict["software_list"])
configuration.set("agent", "log_directory", self.options["log_directory"])
configuration.set("agent", "state_file", self.options["state_file"])
state = open(self.options["state_file"], "w")
state.write('')
state.close()
configuration.add_section("software_uri")
software_list = json.loads(self.parameter_dict["software_list"])
for software in software_list:
configuration.set("software_uri", software, self.parameter_dict[software])
configuration.write(open(configuration_path, "w")) return self.path_list + [configuration_path, agent_crond_path]
agent_crond_path = os.path.join(self.crond, "agent")
agent_crond = open(agent_crond_path, "w")
agent_crond.write("*/3 * * * * %s -S %s" % \
(self.options["python_binary"],
"%s --pidfile=%s %s" % \
(self.options["agent_binary"], self.options["pidfile"],
configuration_path)))
agent_crond.close()
return self.path_list + [configuration_path, key_filepath, cert_filepath, agent_crond_path]
def installCrond(self): def installCrond(self):
_, self.ws = self.egg.working_set() _, ws = self.egg.working_set()
timestamps = self.createDataDirectory('cronstamps') timestamps = self.createDataDirectory('cronstamps')
cron_output = os.path.join(self.log_directory, 'cron-output') cron_output = os.path.join(self.log_directory, 'cron-output')
self._createDirectory(cron_output) self._createDirectory(cron_output)
catcher = zc.buildout.easy_install.scripts([('catchcron', catcher = zc.buildout.easy_install.scripts([('catchcron',
__name__ + '.catdatefile', 'catdatefile')], self.ws, sys.executable, __name__ + '.catdatefile', 'catdatefile')], ws, sys.executable,
self.bin_directory, arguments=[cron_output])[0] self.bin_directory, arguments=[cron_output])[0]
self.path_list.append(catcher) self.path_list.append(catcher)
cron_d = os.path.join(self.etc_directory, 'cron.d') cron_d = os.path.join(self.etc_directory, 'cron.d')
...@@ -111,7 +80,7 @@ class Recipe(BaseSlapRecipe, GenericSlapRecipe): ...@@ -111,7 +80,7 @@ class Recipe(BaseSlapRecipe, GenericSlapRecipe):
self._createDirectory(cron_d) self._createDirectory(cron_d)
self._createDirectory(crontabs) self._createDirectory(crontabs)
wrapper = zc.buildout.easy_install.scripts([('crond', wrapper = zc.buildout.easy_install.scripts([('crond',
'slapos.recipe.librecipe.execute', 'execute')], self.ws, sys.executable, 'slapos.recipe.librecipe.execute', 'execute')], ws, sys.executable,
self.wrapper_directory, arguments=[ self.wrapper_directory, arguments=[
self.options['dcrond_binary'].strip(), '-s', cron_d, '-c', crontabs, self.options['dcrond_binary'].strip(), '-s', cron_d, '-c', crontabs,
'-t', timestamps, '-f', '-l', '5', '-M', catcher] '-t', timestamps, '-f', '-l', '5', '-M', catcher]
......
[buildout] [buildout]
parts = parts =
rootdirectory
instance instance
eggs-directory = ${buildout:eggs-directory} eggs-directory = ${buildout:eggs-directory}
...@@ -9,17 +8,16 @@ develop-eggs-directory = ${buildout:develop-eggs-directory} ...@@ -9,17 +8,16 @@ develop-eggs-directory = ${buildout:develop-eggs-directory}
[instance] [instance]
recipe = ${instance-recipe:egg}:${instance-recipe:module} recipe = ${instance-recipe:egg}:${instance-recipe:module}
agent_binary = ${buildout:directory}/bin/agent agent_binary = ${buildout:directory}/bin/agent
report_start = ${buildout:directory}/bin/report_start
report_stop = ${buildout:directory}/bin/report_stop
dcrond_binary = ${dcron:location}/sbin/crond dcrond_binary = ${dcron:location}/sbin/crond
python_binary = ${python2.7:location}/bin/python python_binary = ${python2.7:location}/bin/python
pidfile = $${buildout:directory}/agent.pid pidfile = $${rootdirectory:run}/agent.pid
log_directory = $${buildout:directory}/var/log log = $${rootdirectory:agentlog}/agent.log
state_file = $${buildout:directory}/state.cfg
[rootdirectory] [rootdirectory]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc/ run = $${buildout:directory}/etc/run
run = $${rootdirectory:etc}/run/ agentlog = $${buildout:directory}/var/log/agent
var = $${buildout:directory}/var/ srv = $${buildout:directory}/srv
log = $${rootdirectory:var}/log/ bin = $${buildout:directory}/bin
srv = $${buildout:directory}/srv/
bin = $${buildout:directory}/bin/
[buildout] [buildout]
# develop =
# /opt/slapdev
# /opt/slapos.toolbox
extends = extends =
../../component/dcron/buildout.cfg ../../component/dcron/buildout.cfg
../../component/python-2.7/buildout.cfg ../../component/python-2.7/buildout.cfg
...@@ -31,7 +26,7 @@ eggs = ${instance-recipe:egg} ...@@ -31,7 +26,7 @@ eggs = ${instance-recipe:egg}
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg url = ${:_profile_base_location_}/instance.cfg
output = ${buildout:directory}/template.cfg output = ${buildout:directory}/template.cfg
md5sum = 2e1a7a68b18de68b163e98a5f92cc776 md5sum = c7cb98594f394d05baedabe424643f6f
mode = 0644 mode = 0644
[eggs] [eggs]
...@@ -41,6 +36,7 @@ eggs = ...@@ -41,6 +36,7 @@ eggs =
${lxml-python:egg} ${lxml-python:egg}
slapos.cookbook slapos.cookbook
slapos.toolbox slapos.toolbox
erp5.util
[lxml-python] [lxml-python]
python = python2.7 python = python2.7
...@@ -53,7 +49,7 @@ eggs = ...@@ -53,7 +49,7 @@ eggs =
${lxml-python:egg} ${lxml-python:egg}
slapos.core slapos.core
slapos.cookbook slapos.cookbook
slapos.toolbox slapos.toolbox[agent]
[networkcache] [networkcache]
# signature certificates of the following uploaders. # signature certificates of the following uploaders.
......
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