Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.toolbox
Commits
5852de46
Commit
5852de46
authored
Apr 19, 2012
by
Yingjie Xu
Committed by
Alain Takoudjou
Jun 14, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SlapOS Test Agent, modified to adapt with buildout and vifib.
parent
d3614b3f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
20 deletions
+42
-20
setup.py
setup.py
+1
-0
slapos/agent/__init__.py
slapos/agent/__init__.py
+0
-0
slapos/agent/agent.py
slapos/agent/agent.py
+41
-20
No files found.
setup.py
View file @
5852de46
...
@@ -50,6 +50,7 @@ setup(name=name,
...
@@ -50,6 +50,7 @@ setup(name=name,
# accessing templates
# accessing templates
entry_points
=
{
entry_points
=
{
'console_scripts'
:
[
'console_scripts'
:
[
'agent = slapos.agent.agent:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
...
...
slapos/agent/__init__.py
0 → 100644
View file @
5852de46
slapos/agent/agent.py
100755 → 100644
View file @
5852de46
import
ConfigParser
import
ConfigParser
import
argparse
import
json
import
json
from
random
import
random
,
choice
from
random
import
random
,
choice
import
os
import
os
...
@@ -12,11 +13,12 @@ from slapos.slap import slap, Supply
...
@@ -12,11 +13,12 @@ from slapos.slap import slap, Supply
from
slapos.grid.utils
import
setRunning
,
setFinished
from
slapos.grid.utils
import
setRunning
,
setFinished
def
safeRpcCall
(
proxy
,
function_id
,
*
args
):
def
safeRpcCall
(
proxy
,
function_id
,
*
args
):
try
:
while
True
:
function
=
getattr
(
proxy
,
function_id
)
try
:
return
function
(
*
args
)
function
=
getattr
(
proxy
,
function_id
)
except
(
socket
.
error
,
xmlrpclib
.
ProtocolError
,
xmlrpclib
.
Fault
),
e
:
return
function
(
*
args
)
pass
except
(
socket
.
error
,
xmlrpclib
.
ProtocolError
,
xmlrpclib
.
Fault
),
e
:
time
.
sleep
(
64
)
def
_encode_software_dict
(
software_dict
):
def
_encode_software_dict
(
software_dict
):
result
=
dict
()
result
=
dict
()
...
@@ -31,10 +33,9 @@ def _decode_software_dict(software_dict):
...
@@ -31,10 +33,9 @@ def _decode_software_dict(software_dict):
return
result
return
result
class
Agent
:
class
Agent
:
def
__init__
(
self
):
def
__init__
(
self
,
configuration_file
):
dirname
=
os
.
path
.
dirname
(
__file__
)
configuration
=
ConfigParser
.
SafeConfigParser
()
configuration
=
ConfigParser
.
SafeConfigParser
()
configuration
.
readfp
(
open
(
os
.
path
.
join
(
dirname
,
"agent.cfg"
))
)
configuration
.
readfp
(
configuration_file
)
self
.
portal_url
=
configuration
.
get
(
"agent"
,
"portal_url"
)
self
.
portal_url
=
configuration
.
get
(
"agent"
,
"portal_url"
)
self
.
master_url
=
configuration
.
get
(
"agent"
,
"master_url"
)
self
.
master_url
=
configuration
.
get
(
"agent"
,
"master_url"
)
self
.
key_file
=
configuration
.
get
(
"agent"
,
"key_file"
)
self
.
key_file
=
configuration
.
get
(
"agent"
,
"key_file"
)
...
@@ -48,9 +49,11 @@ class Agent:
...
@@ -48,9 +49,11 @@ class Agent:
self
.
software_uri
=
dict
()
self
.
software_uri
=
dict
()
for
(
software
,
uri
)
in
configuration
.
items
(
"software_uri"
):
for
(
software
,
uri
)
in
configuration
.
items
(
"software_uri"
):
self
.
software_uri
[
software
]
=
uri
self
.
software_uri
[
software
]
=
uri
self
.
log_directory
=
configuration
.
get
(
"agent"
,
"log_directory"
)
self
.
state_file
=
configuration
.
get
(
"agent"
,
"state_file"
)
filename
=
"agent-%s.log"
%
datetime
.
strftime
(
datetime
.
now
(),
"%Y-%m-%d"
)
filename
=
os
.
path
.
join
(
self
.
log_directory
,
"agent-%s.log"
%
datetime
.
strftime
(
datetime
.
now
(),
"%Y-%m-%d"
)
)
basicConfig
(
filename
=
os
.
path
.
join
(
dirname
,
filename
)
,
format
=
"%(asctime)-15s %(message)s"
,
level
=
"INFO"
)
basicConfig
(
filename
=
filename
,
format
=
"%(asctime)-15s %(message)s"
,
level
=
"INFO"
)
self
.
logger
=
getLogger
()
self
.
logger
=
getLogger
()
self
.
slap
=
slap
()
self
.
slap
=
slap
()
...
@@ -58,7 +61,7 @@ class Agent:
...
@@ -58,7 +61,7 @@ class Agent:
self
.
supply
=
Supply
()
self
.
supply
=
Supply
()
state
=
ConfigParser
.
SafeConfigParser
()
state
=
ConfigParser
.
SafeConfigParser
()
state
.
readfp
(
open
(
os
.
path
.
join
(
dirname
,
"state.cfg"
)
))
state
.
readfp
(
open
(
self
.
state_file
))
self
.
installing_software_dict
=
dict
()
self
.
installing_software_dict
=
dict
()
self
.
installed_software_dict
=
dict
()
self
.
installed_software_dict
=
dict
()
for
computer
in
self
.
computer_list
:
for
computer
in
self
.
computer_list
:
...
@@ -114,14 +117,28 @@ class Agent:
...
@@ -114,14 +117,28 @@ class Agent:
state
.
set
(
computer
,
"installed_software"
,
\
state
.
set
(
computer
,
"installed_software"
,
\
json
.
dumps
(
_encode_software_dict
(
self
.
installed_software_dict
[
computer
])))
json
.
dumps
(
_encode_software_dict
(
self
.
installed_software_dict
[
computer
])))
dirname
=
os
.
path
.
dirname
(
__file__
)
dirname
=
os
.
path
.
dirname
(
__file__
)
state
.
write
(
open
(
os
.
path
.
join
(
dirname
,
"state.cfg"
),
"w"
))
state
.
write
(
open
(
self
.
state_file
,
"w"
))
if
__name__
==
"__main__"
:
def
main
(
*
args
):
dirname
=
os
.
path
.
dirname
(
__file__
)
parser
=
argparse
.
ArgumentParser
()
pidfile
=
os
.
path
.
join
(
dirname
,
"agent.pid"
)
parser
.
add_argument
(
"--pidfile"
,
help
=
"The location where pidfile will be created."
)
setRunning
(
pidfile
)
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
help
=
"Slap Test Agent configuration file."
)
agent
=
Agent
()
if
args
==
():
argument_option_instance
=
parser
.
parse_args
()
else
:
argument_option_instance
=
\
parser
.
parse_args
(
list
(
args
))
option_dict
=
{}
configuration_file
=
argument_option_instance
.
configuration_file
[
0
]
for
argument_key
,
argument_value
in
vars
(
argument_option_instance
).
iteritems
():
option_dict
.
update
({
argument_key
:
argument_value
})
pidfile
=
option_dict
.
get
(
"pidfile"
,
None
)
if
pidfile
:
setRunning
(
pidfile
)
agent
=
Agent
(
configuration_file
)
now
=
datetime
.
now
()
now
=
datetime
.
now
()
for
computer
in
agent
.
computer_list
:
for
computer
in
agent
.
computer_list
:
installing_software_list
=
agent
.
getInstallingSoftwareReleaseListOnComputer
(
computer
)
installing_software_list
=
agent
.
getInstallingSoftwareReleaseListOnComputer
(
computer
)
...
@@ -155,4 +172,8 @@ if __name__ == "__main__":
...
@@ -155,4 +172,8 @@ if __name__ == "__main__":
del
agent
.
installed_software_dict
[
computer
][
installed_software
]
del
agent
.
installed_software_dict
[
computer
][
installed_software
]
agent
.
writeState
()
agent
.
writeState
()
setFinished
(
pidfile
)
if
pidfile
:
setFinished
(
pidfile
)
if
__name__
==
"__main__"
:
main
()
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