Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos
Commits
8cd32a72
Commit
8cd32a72
authored
Apr 19, 2012
by
Yingjie Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SlapOS Test Agent Packaging.
parent
6b7b7774
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
143 additions
and
48 deletions
+143
-48
slapos/recipe/agent/__init__.py
slapos/recipe/agent/__init__.py
+86
-3
slapos/recipe/agent/catdatefile.py
slapos/recipe/agent/catdatefile.py
+14
-0
software/agent/instance-agent.cfg
software/agent/instance-agent.cfg
+0
-23
software/agent/instance.cfg
software/agent/instance.cfg
+20
-13
software/agent/software.cfg
software/agent/software.cfg
+23
-9
No files found.
slapos/recipe/agent/__init__.py
View file @
8cd32a72
...
...
@@ -28,9 +28,92 @@
import
os
import
sys
import
zc.buildout
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
slapos.slap
from
slapos.recipe.librecipe
import
BaseSlapRecipe
from
slapos.recipe.librecipe
import
GenericSlapRecipe
import
json
import
ConfigParser
class
Recipe
(
GenericBase
Recipe
):
class
Recipe
(
BaseSlapRecipe
,
GenericSlap
Recipe
):
def
install
(
self
):
self
.
path_list
=
[]
self
.
crond
=
self
.
installCrond
()
return
[]
slap
=
slapos
.
slap
.
slap
()
computer_id
=
self
.
computer_id
computer_partition_id
=
self
.
computer_partition_id
server_url
=
self
.
server_url
key_file
=
self
.
key_file
cert_file
=
self
.
cert_file
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
()
configuration_path
=
os
.
path
.
join
(
self
.
work_directory
,
"agent.cfg"
)
configuration
=
ConfigParser
.
SafeConfigParser
()
configuration
.
add_section
(
"agent"
)
configuration
.
set
(
"agent"
,
"portal_url"
,
self
.
parameter_dict
[
"portal_url"
])
configuration
.
set
(
"agent"
,
"master_url"
,
self
.
parameter_dict
[
"master_url"
])
key_filepath
=
os
.
path
.
join
(
self
.
work_directory
,
"key"
)
key_file
=
open
(
key_filepath
,
"w"
)
key_file
.
write
(
self
.
parameter_dict
[
"key"
])
key_file
.
close
()
configuration
.
set
(
"agent"
,
"key_file"
,
key_filepath
)
cert_filepath
=
os
.
path
.
join
(
self
.
work_directory
,
"cert"
)
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"
))
agent_crond_path
=
os
.
path
.
join
(
self
.
crond
,
"agent"
)
agent_crond
=
open
(
agent_crond_path
,
"w"
)
agent_crond
.
write
(
"*/1 * * * * %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
):
_
,
self
.
ws
=
self
.
egg
.
working_set
()
timestamps
=
self
.
createDataDirectory
(
'cronstamps'
)
cron_output
=
os
.
path
.
join
(
self
.
log_directory
,
'cron-output'
)
self
.
_createDirectory
(
cron_output
)
catcher
=
zc
.
buildout
.
easy_install
.
scripts
([(
'catchcron'
,
__name__
+
'.catdatefile'
,
'catdatefile'
)],
self
.
ws
,
sys
.
executable
,
self
.
bin_directory
,
arguments
=
[
cron_output
])[
0
]
self
.
path_list
.
append
(
catcher
)
cron_d
=
os
.
path
.
join
(
self
.
etc_directory
,
'cron.d'
)
crontabs
=
os
.
path
.
join
(
self
.
etc_directory
,
'crontabs'
)
self
.
_createDirectory
(
cron_d
)
self
.
_createDirectory
(
crontabs
)
wrapper
=
zc
.
buildout
.
easy_install
.
scripts
([(
'crond'
,
'slapos.recipe.librecipe.execute'
,
'execute'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
self
.
options
[
'dcrond_binary'
].
strip
(),
'-s'
,
cron_d
,
'-c'
,
crontabs
,
'-t'
,
timestamps
,
'-f'
,
'-l'
,
'5'
,
'-M'
,
catcher
]
)[
0
]
self
.
path_list
.
append
(
wrapper
)
return
cron_d
slapos/recipe/agent/catdatefile.py
0 → 100644
View file @
8cd32a72
import
os
import
sys
import
time
def
catdatefile
(
args
):
directory
=
args
[
0
]
try
:
suffix
=
args
[
1
]
except
IndexError
:
suffix
=
'.log'
f
=
open
(
os
.
path
.
join
(
directory
,
time
.
strftime
(
'%Y-%m-%d.%H:%M.%s'
)
+
suffix
),
'aw'
)
for
line
in
sys
.
stdin
.
read
():
f
.
write
(
line
)
f
.
close
()
software/agent/instance-agent.cfg
deleted
100644 → 0
View file @
6b7b7774
[buildout]
parts =
agent-instance
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[agent-instance]
recipe = slapos.cookbook:agent
[rootdirectory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
var = $${buildout:directory}/var
srv = $${buildout:directory}/srv
bin = $${buildout:directory}/bin
[basedirectory]
recipe = slapos.cookbook:mkdirectory
services = $${rootdirectory:etc}/run
run = $${rootdirectory:var}/run
framebuffer = $${rootdirectory:srv}/framebuffer
software/agent/instance.cfg
View file @
8cd32a72
[buildout]
parts =
switch-softwaretype
rootdirectory
instance
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[switch-softwaretype]
recipe = slapos.cookbook:softwaretype
default = ${template-agent:output}
[slap-connection]
computer-id = $${slap_connection:computer_id}
partition-id = $${slap_connection:partition_id}
server-url = $${slap_connection:server_url}
software-release-url = $${slap_connection:software_release_url}
key-file = $${slap_connection:key_file}
cert-file = $${slap_connection:cert_file}
[instance]
recipe = ${instance-recipe:egg}:${instance-recipe:module}
agent_binary = ${buildout:directory}/bin/agent
dcrond_binary = ${dcron:location}/sbin/crond
python_binary = ${python2.7:location}/bin/python
pidfile = $${buildout:directory}/agent.pid
log_directory = $${buildout:directory}/var/log
state_file = $${buildout:directory}/state.cfg
[rootdirectory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc/
run = $${rootdirectory:etc}/run/
var = $${buildout:directory}/var/
log = $${rootdirectory:var}/log/
srv = $${buildout:directory}/srv/
bin = $${buildout:directory}/bin/
software/agent/software.cfg
View file @
8cd32a72
[buildout]
develop =
/
srv/slapgrid/slappart2/srv/runner/project/SlapOS
/
opt/slapdev
/opt/slapos.toolbox
extends =
...
...
@@ -13,21 +13,25 @@ extends =
parts =
template
eggs
instance-recipe-egg
dcron
python2.7
script
[instance-recipe]
egg = slapos.cookbook
module = agent
[instance-recipe-egg]
recipe = zc.recipe.egg
python = python2.7
eggs = ${instance-recipe:egg}
[template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg
md5sum = 3cd7b47f979bb880eb9f61f8424e2814
output = ${buildout:directory}/template.cfg
mode = 0644
[template-agent]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-agent.cfg
md5sum = 400945519a33bbdd6a807dbc6b828169
output = ${buildout:directory}/template-agent.cfg
md5sum = 2e1a7a68b18de68b163e98a5f92cc776
mode = 0644
[eggs]
...
...
@@ -41,6 +45,16 @@ eggs =
[lxml-python]
python = python2.7
[script]
recipe = z3c.recipe.scripts
python = python2.7
eggs =
zc.buildout
${lxml-python:egg}
slapos.core
slapos.cookbook
slapos.toolbox
[networkcache]
# signature certificates of the following uploaders.
# Romain Courteaud
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment