Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build
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
Thomas Leymonerie
slapos.recipe.build
Commits
1ecf5954
Commit
1ecf5954
authored
Oct 14, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New vm.* recipes to build VM images and execute commands inside them
parent
0f601ebf
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
405 additions
and
40 deletions
+405
-40
setup.py
setup.py
+2
-0
slapos/recipe/__init__.py
slapos/recipe/__init__.py
+57
-0
slapos/recipe/build/__init__.py
slapos/recipe/build/__init__.py
+5
-40
slapos/recipe/vm.py
slapos/recipe/vm.py
+341
-0
No files found.
setup.py
View file @
1ecf5954
...
...
@@ -40,6 +40,8 @@ setup(name=name,
'download-unpacked = slapos.recipe.downloadunpacked:Recipe'
,
'gitclone = slapos.recipe.gitclone:Recipe'
,
'npm = slapos.recipe.npm:Npm'
,
'vm.install-debian = slapos.recipe.vm:InstallDebianRecipe'
,
'vm.run = slapos.recipe.vm:RunRecipe'
,
],
'zc.buildout.uninstall'
:
[
'gitclone = slapos.recipe.gitclone:uninstall'
,
...
...
slapos/recipe/__init__.py
View file @
1ecf5954
...
...
@@ -4,3 +4,60 @@ try:
except
ImportError
:
from
pkgutil
import
extend_path
__path__
=
extend_path
(
__path__
,
__name__
)
import
errno
,
logging
,
os
,
shutil
import
zc.buildout
logger
=
logging
.
getLogger
(
__name__
)
def
generatePassword
(
length
=
8
):
from
random
import
SystemRandom
from
string
import
ascii_lowercase
return
''
.
join
(
SystemRandom
().
sample
(
ascii_lowercase
,
length
))
def
rmtree
(
path
):
try
:
os
.
remove
(
path
)
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
EISDIR
:
raise
shutil
.
rmtree
(
path
)
class
EnvironMixin
:
def
__init__
(
self
,
allow_none
=
True
):
environment
=
self
.
options
.
get
(
'environment'
,
''
).
strip
()
if
environment
:
from
os
import
environ
if
'='
in
environment
:
self
.
_environ
=
env
=
{}
for
line
in
environment
.
splitlines
():
line
=
line
.
strip
()
if
line
:
try
:
k
,
v
=
line
.
split
(
'='
,
1
)
except
ValueError
:
raise
zc
.
buildout
.
UserError
(
'Line %r in environment is incorrect'
%
line
)
k
=
k
.
strip
()
if
k
in
env
:
raise
zc
.
buildout
.
UserError
(
'Key %r is repeated'
%
k
)
env
[
k
]
=
v
.
strip
()
%
environ
else
:
self
.
_environ
=
{
k
:
v
.
strip
()
%
environ
for
k
,
v
in
self
.
buildout
[
environment
].
iteritems
()}
else
:
self
.
_environ
=
None
if
allow_none
else
{}
@
property
def
environ
(
self
):
if
self
.
_environ
is
not
None
:
from
os
import
environ
env
=
self
.
_environ
.
copy
()
for
k
,
v
in
env
.
iteritems
():
logger
.
info
(
'Environment %r set to %r'
if
k
in
environ
else
'Environment %r added with %r'
,
k
,
v
)
for
kw
in
environ
.
iteritems
():
env
.
setdefault
(
*
kw
)
return
env
slapos/recipe/build/__init__.py
View file @
1ecf5954
...
...
@@ -35,6 +35,7 @@ import subprocess
import
sys
import
tempfile
import
zc.buildout
from
slapos.recipe
import
rmtree
,
EnvironMixin
ARCH_MAP
=
{
'i386'
:
'x86'
,
...
...
@@ -122,17 +123,9 @@ def guessOperatingSystem():
assert
target
,
'Unknown architecture'
return
target
def
rmtree
(
path
):
try
:
os
.
remove
(
path
)
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
EISDIR
:
raise
shutil
.
rmtree
(
path
)
TRUE_LIST
=
(
'y'
,
'on'
,
'yes'
,
'true'
,
'1'
)
class
Script
:
class
Script
(
EnvironMixin
)
:
"""Free script building system"""
def
_checkPromise
(
self
,
promise_key
,
location
):
promise_text
=
self
.
options
.
get
(
promise_key
)
...
...
@@ -285,43 +278,15 @@ class Script:
self
.
keep_on_error
=
True
else
:
self
.
keep_on_error
=
False
def
getEnvironment
(
self
):
# prepare cool dictionary
wanted_env
=
{}
for
line
in
self
.
options
.
get
(
'environment'
,
''
).
splitlines
():
line
=
line
.
strip
()
if
not
line
:
continue
if
not
'='
in
line
:
raise
zc
.
buildout
.
UserError
(
'Line %r in environment is incorrect'
%
line
)
key
,
value
=
line
.
split
(
'='
,
1
)
key
=
key
.
strip
()
value
=
value
.
strip
()
if
key
in
wanted_env
:
raise
zc
.
buildout
.
UserError
(
'Key %r is repeated'
%
key
)
wanted_env
[
key
]
=
value
env
=
{}
for
k
,
v
in
os
.
environ
.
iteritems
():
change
=
wanted_env
.
pop
(
k
,
None
)
if
change
is
not
None
:
env
[
k
]
=
change
%
os
.
environ
self
.
logger
.
info
(
'Environment %r setup to %r'
%
(
k
,
env
[
k
]))
else
:
env
[
k
]
=
v
for
k
,
v
in
wanted_env
.
iteritems
():
self
.
logger
.
info
(
'Environment %r added with %r'
%
(
k
,
v
))
env
[
k
]
=
v
return
env
EnvironMixin
.
__init__
(
self
,
False
)
def
install
(
self
):
location
=
self
.
options
[
'location'
]
if
os
.
path
.
lexists
(
location
):
self
.
logger
.
warning
(
'Removing already existing path %r'
,
location
)
rmtree
(
location
)
env
=
self
.
getEnvironment
()
# env is used in script exec'ed below
# env is used in script exec'ed below
env
=
self
.
environ
try
:
exec
self
.
script
self
.
_checkPromise
(
'slapos_promise'
,
location
)
...
...
slapos/recipe/vm.py
0 → 100644
View file @
1ecf5954
This diff is collapsed.
Click to expand it.
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