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
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
Titouan Soulard
slapos
Commits
2f370675
Commit
2f370675
authored
Oct 10, 2011
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing trailing spaces
parent
b086cbd5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
36 deletions
+36
-36
slapos/recipe/kvm/__init__.py
slapos/recipe/kvm/__init__.py
+36
-36
No files found.
slapos/recipe/kvm/__init__.py
View file @
2f370675
...
@@ -49,42 +49,42 @@ class Recipe(BaseSlapRecipe):
...
@@ -49,42 +49,42 @@ class Recipe(BaseSlapRecipe):
self
.
path_list
=
[]
self
.
path_list
=
[]
self
.
requirements
,
self
.
ws
=
self
.
egg
.
working_set
()
self
.
requirements
,
self
.
ws
=
self
.
egg
.
working_set
()
self
.
cron_d
=
self
.
installCrond
()
self
.
cron_d
=
self
.
installCrond
()
self
.
ca_conf
=
self
.
installCertificateAuthority
()
self
.
ca_conf
=
self
.
installCertificateAuthority
()
self
.
key_path
,
self
.
certificate_path
=
self
.
requestCertificate
(
'noVNC'
)
self
.
key_path
,
self
.
certificate_path
=
self
.
requestCertificate
(
'noVNC'
)
kvm_conf
=
self
.
installKvm
(
vnc_ip
=
self
.
getLocalIPv4Address
())
kvm_conf
=
self
.
installKvm
(
vnc_ip
=
self
.
getLocalIPv4Address
())
vnc_port
=
5900
+
kvm_conf
[
'vnc_display'
]
vnc_port
=
5900
+
kvm_conf
[
'vnc_display'
]
noVNC_conf
=
self
.
installNoVnc
(
source_ip
=
self
.
getGlobalIPv6Address
(),
noVNC_conf
=
self
.
installNoVnc
(
source_ip
=
self
.
getGlobalIPv6Address
(),
source_port
=
6080
,
source_port
=
6080
,
target_ip
=
kvm_conf
[
'vnc_ip'
],
target_ip
=
kvm_conf
[
'vnc_ip'
],
target_port
=
vnc_port
)
target_port
=
vnc_port
)
self
.
linkBinary
()
self
.
linkBinary
()
self
.
computer_partition
.
setConnectionDict
(
dict
(
self
.
computer_partition
.
setConnectionDict
(
dict
(
url
=
"https://[%s]:%s/vnc.html?host=[%s]&port=%s&encrypt=1"
%
(
noVNC_conf
[
'source_ip'
],
url
=
"https://[%s]:%s/vnc.html?host=[%s]&port=%s&encrypt=1"
%
(
noVNC_conf
[
'source_ip'
],
noVNC_conf
[
'source_port'
],
noVNC_conf
[
'source_port'
],
noVNC_conf
[
'source_ip'
],
noVNC_conf
[
'source_ip'
],
noVNC_conf
[
'source_port'
]
noVNC_conf
[
'source_port'
]
),
),
password
=
kvm_conf
[
'vnc_passwd'
]))
password
=
kvm_conf
[
'vnc_passwd'
]))
return
self
.
path_list
return
self
.
path_list
def
installKvm
(
self
,
vnc_ip
):
def
installKvm
(
self
,
vnc_ip
):
"""
"""
Create kvm configuration dictionnary and instanciate a wrapper for kvm and
Create kvm configuration dictionnary and instanciate a wrapper for kvm and
kvm controller
kvm controller
Parameters : IP the vnc server is listening on
Parameters : IP the vnc server is listening on
Returns : Dictionnary kvm_conf
Returns : Dictionnary kvm_conf
"""
"""
kvm_conf
=
dict
(
vnc_ip
=
vnc_ip
)
kvm_conf
=
dict
(
vnc_ip
=
vnc_ip
)
connection_found
=
False
connection_found
=
False
for
tap_interface
,
dummy
in
self
.
parameter_dict
[
'ip_list'
]:
for
tap_interface
,
dummy
in
self
.
parameter_dict
[
'ip_list'
]:
# Get an ip associated to a tap interface
# Get an ip associated to a tap interface
...
@@ -94,13 +94,13 @@ class Recipe(BaseSlapRecipe):
...
@@ -94,13 +94,13 @@ class Recipe(BaseSlapRecipe):
raise
NotImplementedError
(
"Do not support ip without tap interface"
)
raise
NotImplementedError
(
"Do not support ip without tap interface"
)
kvm_conf
[
'tap_interface'
]
=
tap_interface
kvm_conf
[
'tap_interface'
]
=
tap_interface
# Disk path
# Disk path
kvm_conf
[
'disk_path'
]
=
os
.
path
.
join
(
self
.
data_root_directory
,
kvm_conf
[
'disk_path'
]
=
os
.
path
.
join
(
self
.
data_root_directory
,
'virtual.qcow2'
)
'virtual.qcow2'
)
kvm_conf
[
'socket_path'
]
=
os
.
path
.
join
(
self
.
var_directory
,
'qmp_socket'
)
kvm_conf
[
'socket_path'
]
=
os
.
path
.
join
(
self
.
var_directory
,
'qmp_socket'
)
# XXX Weak password
# XXX Weak password
##XXX -Vivien: add an option to generate one password for all instances
##XXX -Vivien: add an option to generate one password for all instances
# and/or to input it yourself
# and/or to input it yourself
kvm_conf
[
'vnc_passwd'
]
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
kvm_conf
[
'vnc_passwd'
]
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
...
@@ -119,7 +119,7 @@ class Recipe(BaseSlapRecipe):
...
@@ -119,7 +119,7 @@ class Recipe(BaseSlapRecipe):
int
(
self
.
options
[
'disk_size'
]))],
shell
=
True
)
int
(
self
.
options
[
'disk_size'
]))],
shell
=
True
)
if
retcode
!=
0
:
if
retcode
!=
0
:
raise
OSError
,
"Disk creation failed!"
raise
OSError
,
"Disk creation failed!"
# Options nbd_ip and nbd_port are provided by slapos master
# Options nbd_ip and nbd_port are provided by slapos master
kvm_conf
[
'nbd_ip'
]
=
self
.
parameter_dict
[
'nbd_ip'
]
kvm_conf
[
'nbd_ip'
]
=
self
.
parameter_dict
[
'nbd_ip'
]
kvm_conf
[
'nbd_port'
]
=
self
.
parameter_dict
[
'nbd_port'
]
kvm_conf
[
'nbd_port'
]
=
self
.
parameter_dict
[
'nbd_port'
]
...
@@ -133,37 +133,37 @@ class Recipe(BaseSlapRecipe):
...
@@ -133,37 +133,37 @@ class Recipe(BaseSlapRecipe):
kvm_conf
[
'ram_size'
]
=
self
.
options
[
'ram_size'
]
kvm_conf
[
'ram_size'
]
=
self
.
options
[
'ram_size'
]
kvm_conf
[
'vnc_display'
]
=
1
kvm_conf
[
'vnc_display'
]
=
1
# Instanciate KVM
# Instanciate KVM
kvm_template_location
=
pkg_resources
.
resource_filename
(
kvm_template_location
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
__name__
,
os
.
path
.
join
(
'template'
,
'kvm_run.in'
))
'template'
,
'kvm_run.in'
))
kvm_runner_path
=
self
.
createRunningWrapper
(
"kvm"
,
kvm_runner_path
=
self
.
createRunningWrapper
(
"kvm"
,
self
.
substituteTemplate
(
kvm_template_location
,
self
.
substituteTemplate
(
kvm_template_location
,
kvm_conf
))
kvm_conf
))
self
.
path_list
.
append
(
kvm_runner_path
)
self
.
path_list
.
append
(
kvm_runner_path
)
# Instanciate KVM controller
# Instanciate KVM controller
kvm_controller_template_location
=
pkg_resources
.
resource_filename
(
kvm_controller_template_location
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
__name__
,
os
.
path
.
join
(
'template'
,
'template'
,
'kvm_controller_run.in'
))
'kvm_controller_run.in'
))
kvm_controller_runner_path
=
self
.
createRunningWrapper
(
"kvm_controller"
,
kvm_controller_runner_path
=
self
.
createRunningWrapper
(
"kvm_controller"
,
self
.
substituteTemplate
(
kvm_controller_template_location
,
self
.
substituteTemplate
(
kvm_controller_template_location
,
kvm_conf
))
kvm_conf
))
self
.
path_list
.
append
(
kvm_controller_runner_path
)
self
.
path_list
.
append
(
kvm_controller_runner_path
)
# Instanciate Slapmonitor
# Instanciate Slapmonitor
##slapmonitor_runner_path = self.instanciate_wrapper("slapmonitor",
##slapmonitor_runner_path = self.instanciate_wrapper("slapmonitor",
# [database_path, pid_file_path, python_path])
# [database_path, pid_file_path, python_path])
# Instanciate Slapreport
# Instanciate Slapreport
##slapreport_runner_path = self.instanciate_wrapper("slapreport",
##slapreport_runner_path = self.instanciate_wrapper("slapreport",
# [database_path, python_path])
# [database_path, python_path])
return
kvm_conf
return
kvm_conf
def
installNoVnc
(
self
,
source_ip
,
source_port
,
target_ip
,
target_port
):
def
installNoVnc
(
self
,
source_ip
,
source_port
,
target_ip
,
target_port
):
...
@@ -178,16 +178,16 @@ class Recipe(BaseSlapRecipe):
...
@@ -178,16 +178,16 @@ class Recipe(BaseSlapRecipe):
"""
"""
noVNC_conf
=
{}
noVNC_conf
=
{}
noVNC_conf
[
'source_ip'
]
=
source_ip
noVNC_conf
[
'source_ip'
]
=
source_ip
noVNC_conf
[
'source_port'
]
=
source_port
noVNC_conf
[
'source_port'
]
=
source_port
# Install numpy.
# Install numpy.
# XXX-Cedric : this looks like a hack. Do we have better solution, knowing
# XXX-Cedric : this looks like a hack. Do we have better solution, knowing
# That websockify is not an egg?
# That websockify is not an egg?
numpy
=
zc
.
buildout
.
easy_install
.
install
([
'numpy'
],
self
.
options
[
'eggs-directory'
])
numpy
=
zc
.
buildout
.
easy_install
.
install
([
'numpy'
],
self
.
options
[
'eggs-directory'
])
environment
=
dict
(
PYTHONPATH
=
'%s'
%
numpy
.
entries
[
0
])
environment
=
dict
(
PYTHONPATH
=
'%s'
%
numpy
.
entries
[
0
])
# Instanciate Websockify
# Instanciate Websockify
websockify_runner_path
=
zc
.
buildout
.
easy_install
.
scripts
([(
'websockify'
,
websockify_runner_path
=
zc
.
buildout
.
easy_install
.
scripts
([(
'websockify'
,
'slapos.recipe.librecipe.execute'
,
'executee_wait'
)],
self
.
ws
,
'slapos.recipe.librecipe.execute'
,
'executee_wait'
)],
self
.
ws
,
...
@@ -204,9 +204,9 @@ class Recipe(BaseSlapRecipe):
...
@@ -204,9 +204,9 @@ class Recipe(BaseSlapRecipe):
[
self
.
certificate_path
,
self
.
key_path
],
[
self
.
certificate_path
,
self
.
key_path
],
environment
]
environment
]
)[
0
]
)[
0
]
self
.
path_list
.
append
(
websockify_runner_path
)
self
.
path_list
.
append
(
websockify_runner_path
)
return
noVNC_conf
return
noVNC_conf
def
linkBinary
(
self
):
def
linkBinary
(
self
):
...
@@ -230,7 +230,7 @@ class Recipe(BaseSlapRecipe):
...
@@ -230,7 +230,7 @@ class Recipe(BaseSlapRecipe):
os
.
symlink
(
target
,
link
)
os
.
symlink
(
target
,
link
)
self
.
logger
.
debug
(
'Created link %r -> %r'
%
(
link
,
target
))
self
.
logger
.
debug
(
'Created link %r -> %r'
%
(
link
,
target
))
self
.
path_list
.
append
(
link
)
self
.
path_list
.
append
(
link
)
def
installCertificateAuthority
(
self
,
ca_country_code
=
'XX'
,
def
installCertificateAuthority
(
self
,
ca_country_code
=
'XX'
,
ca_email
=
'xx@example.com'
,
ca_state
=
'State'
,
ca_city
=
'City'
,
ca_email
=
'xx@example.com'
,
ca_state
=
'State'
,
ca_city
=
'City'
,
ca_company
=
'Company'
):
ca_company
=
'Company'
):
...
@@ -289,7 +289,7 @@ class Recipe(BaseSlapRecipe):
...
@@ -289,7 +289,7 @@ class Recipe(BaseSlapRecipe):
ca_crl
=
os
.
path
.
join
(
config
[
'ca_dir'
],
'crl'
),
ca_crl
=
os
.
path
.
join
(
config
[
'ca_dir'
],
'crl'
),
certificate_authority_path
=
config
[
'ca_dir'
]
certificate_authority_path
=
config
[
'ca_dir'
]
)
)
def
requestCertificate
(
self
,
name
):
def
requestCertificate
(
self
,
name
):
hash
=
hashlib
.
sha512
(
name
).
hexdigest
()
hash
=
hashlib
.
sha512
(
name
).
hexdigest
()
key
=
os
.
path
.
join
(
self
.
ca_private
,
hash
+
self
.
ca_key_ext
)
key
=
os
.
path
.
join
(
self
.
ca_private
,
hash
+
self
.
ca_key_ext
)
...
@@ -301,7 +301,7 @@ class Recipe(BaseSlapRecipe):
...
@@ -301,7 +301,7 @@ class Recipe(BaseSlapRecipe):
parser
.
set
(
'certificate'
,
'certificate_file'
,
certificate
)
parser
.
set
(
'certificate'
,
'certificate_file'
,
certificate
)
parser
.
write
(
open
(
os
.
path
.
join
(
self
.
ca_request_dir
,
hash
),
'w'
))
parser
.
write
(
open
(
os
.
path
.
join
(
self
.
ca_request_dir
,
hash
),
'w'
))
return
key
,
certificate
return
key
,
certificate
def
installCrond
(
self
):
def
installCrond
(
self
):
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'
)
...
...
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