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
Joanne Hugé
slapos.toolbox
Commits
45a013f6
Commit
45a013f6
authored
Oct 01, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor request instance
parent
a767329b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
51 deletions
+48
-51
slapos/runner/utils.py
slapos/runner/utils.py
+48
-51
No files found.
slapos/runner/utils.py
View file @
45a013f6
...
@@ -95,7 +95,45 @@ def saveSession(config, account):
...
@@ -95,7 +95,45 @@ def saveSession(config, account):
pass
pass
return
str
(
e
)
return
str
(
e
)
def
updateProxy
(
config
,
request
=
True
):
def
getCurrentSoftwareReleaseProfile
(
config
):
"""
Returns used Software Release profile as a string.
"""
try
:
software_folder
=
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
)).
read
()
return
realpath
(
config
,
os
.
path
.
join
(
software_folder
,
config
[
'software_profile'
]))
except
:
return
False
def
requestInstance
(
config
,
software_type
=
None
):
"""
Request the main instance of our environment
"""
if
not
software_type
:
software_type
=
None
slap
=
slapos
.
slap
.
slap
()
profile
=
getCurrentSoftwareReleaseProfile
(
config
)
slap
.
initializeConnection
(
config
[
'master_url'
])
param_path
=
os
.
path
.
join
(
config
[
'etc_dir'
],
".parameter.xml"
)
xml_result
=
readParameters
(
param_path
)
partition_parameter_kw
=
None
if
type
(
xml_result
)
!=
type
(
''
)
and
xml_result
.
has_key
(
'instance'
):
partition_parameter_kw
=
xml_result
[
'instance'
]
return
slap
.
registerOpenOrder
().
request
(
profile
,
partition_reference
=
getSoftwareReleaseName
(
config
),
partition_parameter_kw
=
partition_parameter_kw
,
software_type
=
software_type
,
filter_kw
=
None
,
state
=
None
,
shared
=
False
)
def
updateProxy
(
config
):
"""
"""
Configure Slapos Node computer and partitions.
Configure Slapos Node computer and partitions.
Send current Software Release to Slapproxy for compilation and deployment.
Send current Software Release to Slapproxy for compilation and deployment.
...
@@ -103,14 +141,7 @@ def updateProxy(config, request=True):
...
@@ -103,14 +141,7 @@ def updateProxy(config, request=True):
if
not
os
.
path
.
exists
(
config
[
'instance_root'
]):
if
not
os
.
path
.
exists
(
config
[
'instance_root'
]):
os
.
mkdir
(
config
[
'instance_root'
])
os
.
mkdir
(
config
[
'instance_root'
])
slap
=
slapos
.
slap
.
slap
()
slap
=
slapos
.
slap
.
slap
()
#Get current software release profile
profile
=
getCurrentSoftwareReleaseProfile
(
config
)
try
:
software_folder
=
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
)).
read
()
profile
=
realpath
(
config
,
os
.
path
.
join
(
software_folder
,
config
[
'software_profile'
]))
except
:
return
False
slap
.
initializeConnection
(
config
[
'master_url'
])
slap
.
initializeConnection
(
config
[
'master_url'
])
slap
.
registerSupply
().
supply
(
profile
,
computer_guid
=
config
[
'computer_id'
])
slap
.
registerSupply
().
supply
(
profile
,
computer_guid
=
config
[
'computer_id'
])
...
@@ -138,22 +169,7 @@ def updateProxy(config, request=True):
...
@@ -138,22 +169,7 @@ def updateProxy(config, request=True):
'reference'
:
partition_reference
,
'reference'
:
partition_reference
,
'tap'
:
{
'name'
:
partition_reference
},
'tap'
:
{
'name'
:
partition_reference
},
})
})
#get instance parameter
param_path
=
os
.
path
.
join
(
config
[
'etc_dir'
],
".parameter.xml"
)
xml_result
=
readParameters
(
param_path
)
partition_parameter_kw
=
None
if
type
(
xml_result
)
!=
type
(
''
)
and
xml_result
.
has_key
(
'instance'
):
partition_parameter_kw
=
xml_result
[
'instance'
]
computer
.
updateConfiguration
(
xml_marshaller
.
dumps
(
slap_config
))
computer
.
updateConfiguration
(
xml_marshaller
.
dumps
(
slap_config
))
if
request
:
slap
.
registerOpenOrder
().
request
(
profile
,
partition_reference
=
getSoftwareReleaseName
(
config
),
partition_parameter_kw
=
partition_parameter_kw
,
software_type
=
None
,
filter_kw
=
None
,
state
=
None
,
shared
=
False
)
return
True
return
True
def
readPid
(
file
):
def
readPid
(
file
):
...
@@ -179,30 +195,9 @@ def updateInstanceParameter(config, software_type=None):
...
@@ -179,30 +195,9 @@ def updateInstanceParameter(config, software_type=None):
config: Slaprunner configuration.
config: Slaprunner configuration.
software_type: reconfigure Software Instance with software type.
software_type: reconfigure Software Instance with software type.
"""
"""
slap
=
slapos
.
slap
.
slap
()
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
,
software_type
)):
slap
.
initializeConnection
(
config
[
'master_url'
])
#Get current software release profile
try
:
software_folder
=
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
)).
read
()
profile
=
realpath
(
config
,
os
.
path
.
join
(
software_folder
,
config
[
'software_profile'
]))
except
:
raise
Exception
(
"Software Release profile not found"
)
if
not
updateProxy
(
config
,
request
=
False
):
return
False
return
False
#get instance parameter
param_path
=
os
.
path
.
join
(
config
[
'etc_dir'
],
".parameter.xml"
)
xml_result
=
readParameters
(
param_path
)
partition_parameter_kw
=
None
if
type
(
xml_result
)
!=
type
(
''
)
and
xml_result
.
has_key
(
'instance'
):
partition_parameter_kw
=
xml_result
[
'instance'
]
slap
.
registerOpenOrder
().
request
(
profile
,
partition_reference
=
getSoftwareReleaseName
(
config
),
partition_parameter_kw
=
partition_parameter_kw
,
software_type
=
software_type
,
filter_kw
=
None
,
state
=
None
,
shared
=
False
)
def
startProxy
(
config
):
def
startProxy
(
config
):
"""Start Slapproxy server"""
"""Start Slapproxy server"""
proxy_pid
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'proxy.pid'
)
proxy_pid
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'proxy.pid'
)
...
@@ -269,7 +264,7 @@ def runSoftwareWithLock(config):
...
@@ -269,7 +264,7 @@ def runSoftwareWithLock(config):
removeProxyDb
(
config
)
removeProxyDb
(
config
)
startProxy
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'software_log'
],
'w'
)
logfile
=
open
(
config
[
'software_log'
],
'w'
)
if
not
updateProxy
(
config
,
request
=
False
):
if
not
updateProxy
(
config
):
return
False
return
False
# Accelerate compilation by setting make -jX
# Accelerate compilation by setting make -jX
environment
=
os
.
environ
.
copy
()
environment
=
os
.
environ
.
copy
()
...
@@ -357,7 +352,7 @@ def runInstanceWithLock(config):
...
@@ -357,7 +352,7 @@ def runInstanceWithLock(config):
if
not
isInstanceRunning
(
config
):
if
not
isInstanceRunning
(
config
):
startProxy
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
if
not
updateProxy
(
config
):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)
):
return
False
return
False
svcStopAll
(
config
)
#prevent lost control of process
svcStopAll
(
config
)
#prevent lost control of process
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
...
@@ -773,15 +768,17 @@ def md5sum(file):
...
@@ -773,15 +768,17 @@ def md5sum(file):
return False
return False
def realpath(config, path, check_exist=True):
def realpath(config, path, check_exist=True):
"""Get realpath of path or return False if user is not allowed to access to
"""
this file"""
Get realpath of path or return False if user is not allowed to access to
this file.
"""
split_path = path.split('
/
')
split_path = path.split('
/
')
key = split_path[0]
key = split_path[0]
allow_list = {'
software_root
':config['
software_root
'], '
instance_root
':
allow_list = {'
software_root
':config['
software_root
'], '
instance_root
':
config['
instance_root
'], '
workspace
': config['
workspace
']}
config['
instance_root
'], '
workspace
': config['
workspace
']}
if allow_list.has_key(key):
if allow_list.has_key(key):
del split_path[0]
del split_path[0]
path = os.path.join(allow_list[key],
string.join(split_path, '
/
')
)
path = os.path.join(allow_list[key],
*split_path
)
if check_exist:
if check_exist:
if os.path.exists(path):
if os.path.exists(path):
return path
return path
...
...
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