Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos
Commits
c0b1b311
Commit
c0b1b311
authored
Jul 01, 2011
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kvm recipe : begin refactor
parent
36e23d39
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
37 deletions
+82
-37
slapos/recipe/kvm/__init__.py
slapos/recipe/kvm/__init__.py
+82
-37
No files found.
slapos/recipe/kvm/__init__.py
View file @
c0b1b311
...
...
@@ -37,14 +37,29 @@ import pkg_resources
class
Recipe
(
BaseSlapRecipe
):
def
_install
(
self
):
self
.
path_list
=
[]
kvm_conf
=
self
.
installKvm
(
vnc_ip
=
self
.
getLocalIPv4Address
())
vnc_port
=
5900
+
kvm_conf
[
'vnc_display'
]
novnc_conf
=
self
.
installNovnc
(
source_ip
=
self
.
getGlobalIPv6Address
(),
source_port
=
6080
,
target_ip
=
kvm_conf
[
'vnc_ip'
],
target_port
=
vnc_port
)
self
.
linkBinary
()
self
.
computer_partition
.
setConnectionDict
(
dict
(
vnc_connection_string
=
"vnc://[%s]:%s"
%
(
vnc_port
[
'vnc_ip'
],
vnc_port
),
vnc_password
=
vnc_passwd
,
))
return
self
.
path_list
#Get the IP list
def
installKvm
(
self
,
vnc_ip
):
kvm_conf
=
dict
(
vnc_ip
=
vnc_ip
)
connection_found
=
False
proxy_ip
=
self
.
getGlobalIPv6Address
()
proxy_port
=
6080
vnc_ip
=
self
.
getLocalIPv4Address
()
vnc_port
=
5901
for
tap_interface
,
dummy
in
self
.
parameter_dict
[
'ip_list'
]:
# Get an ip associated to a tap interface
if
tap_interface
:
...
...
@@ -52,21 +67,26 @@ class Recipe(BaseSlapRecipe):
if
not
connection_found
:
raise
NotImplementedError
(
"Do not support ip without tap interface"
)
kvm_conf
[
'tap_interface'
]
=
tap_interface
# Disk path
disk_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'virtual.qcow2'
)
socket_path
=
os
.
path
.
join
(
self
.
var_directory
,
'qmp_socket'
)
kvm_conf
[
'disk_path'
]
=
os
.
path
.
join
(
self
.
data_root_directory
,
'virtual.qcow2'
)
kvm_conf
[
'socket_path'
]
=
os
.
path
.
join
(
self
.
var_directory
,
'qmp_socket'
)
# XXX Weak password
##XXX -Vivien: add an option to generate one password for all instances and/or to input it yourself
vnc_passwd
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
##XXX -Vivien: add an option to generate one password for all instances
# and/or to input it yourself
kvm_conf
[
'vnc_passwd'
]
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
#XXX pid_file path, database_path, path to python binary and xml path
pid_file_path
=
os
.
path
.
join
(
self
.
run_directory
,
'pid_file'
)
database_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'slapmonitor_database'
)
python_path
=
sys
.
executable
kvm_conf
[
'pid_file_path'
]
=
os
.
path
.
join
(
self
.
run_directory
,
'pid_file'
)
kvm_conf
[
'database_path'
]
=
os
.
path
.
join
(
self
.
data_root_directory
,
'slapmonitor_database'
)
kvm_conf
[
'python_path'
]
=
sys
.
executable
#xml_path = os.path.join(self.var_directory, 'slapreport.xml' )
# Create disk if needed
if
not
os
.
path
.
exists
(
disk_path
):
if
not
os
.
path
.
exists
(
kvm_conf
[
'disk_path'
]
):
retcode
=
subprocess
.
call
([
"%s create -f qcow2 %s %iG"
%
(
self
.
options
[
'qemu_img_path'
],
disk_path
,
int
(
self
.
options
[
'disk_size'
]))],
shell
=
True
)
...
...
@@ -74,41 +94,44 @@ class Recipe(BaseSlapRecipe):
raise
OSError
,
"Disk creation failed!"
# Options nbd_ip and nbd_port are provided by slapos master
nbd_ip
=
self
.
parameter_dict
[
'nbd_ip'
]
nbd_port
=
self
.
parameter_dict
[
'nbd_port'
]
kvm_conf
[
'nbd_ip'
]
=
self
.
parameter_dict
[
'nbd_ip'
]
kvm_conf
[
'nbd_port'
]
=
self
.
parameter_dict
[
'nbd_port'
]
# First octet has to represent a locally administered address
octet_list
=
[
254
]
+
[
random
.
randint
(
0x00
,
0xff
)
for
x
in
range
(
5
)]
mac_address
=
':'
.
join
([
'%02x'
%
x
for
x
in
octet_list
])
hostname
=
"slaposkvm"
octet_list
=
[
254
]
+
[
random
.
randint
(
0x00
,
0xff
)
for
x
in
range
(
5
)]
kvm_conf
[
'mac_address'
]
=
':'
.
join
([
'%02x'
%
x
for
x
in
octet_list
])
#raise NotImplementedError("%s" % self.parameter_dict)
self
.
computer_partition
.
setConnectionDict
(
dict
(
vnc_connection_string
=
"vnc://[%s]:1"
%
vnc_ip
,
vnc_password
=
vnc_passwd
,
))
kvm_conf
[
'hostname'
]
=
"slaposkvm"
# Instanciate KVM
kvm_runner_path
=
self
.
instanciate
(
"kvm"
,
[
vnc_ip
,
tap_interface
,
nbd_ip
,
nbd_port
,
pid_file_path
,
disk_path
,
mac_address
,
socket_path
,
hostname
])
kvm_runner_path
=
self
.
instanciate
(
"kvm"
,
kvm_conf
)
self
.
path_list
.
append
(
kvm_runner_path
)
# Instanciate KVM controller
kvm_controller_runner_path
=
self
.
instanciate
(
"kvm_controller"
,
[
socket_path
,
vnc_passwd
,
python_path
])
#XXX Instanciate Slapmonitor
##slapmonitor_runner_path = self.instanciate("slapmonitor", [database_path, pid_file_path, python_path])
#XXX Instanciate Slapreport
##slapreport_runner_path = self.instanciate("slapreport", [database_path, python_path])
#XXX Instanciate Websockify
websockify_runner_path
=
self
.
instanciate
(
"websockify"
,
[
python_path
,
vnc_ip
,
proxy_ip
,
vnc_port
,
proxy_port
])
kvm_controller_runner_path
=
self
.
instanciate
(
"kvm_controller"
,
kvm_conf
)
self
.
path_list
.
append
(
kvm_controller_runner_path
)
# Instanciate Slapmonitor
##slapmonitor_runner_path = self.instanciate("slapmonitor",
# [database_path, pid_file_path, python_path])
# Instanciate Slapreport
##slapreport_runner_path = self.instanciate("slapreport",
# [database_path, python_path])
kvm_conf
[
'vnc_display'
]
=
1
return
kvm_conf
def
installNoVnc
(
self
,
source_ip
,
source_port
,
target_ip
,
target_port
):
# Instanciate Websockify
websockify_runner_path
=
self
.
instanciate
(
"websockify"
,
[
python_path
,
vnc_ip
,
proxy_ip
,
vnc_port
,
proxy_port
])
self
.
path_list
.
append
(
websockify_runner_path
)
return
[
kvm_runner_path
,
kvm_controller_runner_path
,
websockify_runner_path
]
def
instanciate
(
self
,
name
,
list
):
"""
Define the path to the wrapper of the thing you are instanciating
Parameters : name of what you are instanciating, list of arguments for the configuration dictionnary of the wrapper
Parameters : name of what you are instanciating, list of arguments for the
configuration dictionnary of the wrapper
Returns : path to the running wrapper
"""
...
...
@@ -126,3 +149,25 @@ class Recipe(BaseSlapRecipe):
self
.
substituteTemplate
(
name_wrapper_template_location
,
name_config
))
return
name_runner_path
def
linkBinary
(
self
):
"""Links binaries to instance's bin directory for easier exposal"""
for
linkline
in
self
.
options
.
get
(
'link_binary_list'
,
''
).
splitlines
():
if
not
linkline
:
continue
target
=
linkline
.
split
()
if
len
(
target
)
==
1
:
target
=
target
[
0
]
path
,
linkname
=
os
.
path
.
split
(
target
)
else
:
linkname
=
target
[
1
]
target
=
target
[
0
]
link
=
os
.
path
.
join
(
self
.
bin_directory
,
linkname
)
if
os
.
path
.
lexists
(
link
):
if
not
os
.
path
.
islink
(
link
):
raise
zc
.
buildout
.
UserError
(
'Target link already %r exists but it is not link'
%
link
)
os
.
unlink
(
link
)
os
.
symlink
(
target
,
link
)
self
.
logger
.
debug
(
'Created link %r -> %r'
%
(
link
,
target
))
self
.
path_list
.
append
(
link
)
\ No newline at end of file
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