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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
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
Show 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
...
@@ -37,14 +37,29 @@ import pkg_resources
class
Recipe
(
BaseSlapRecipe
):
class
Recipe
(
BaseSlapRecipe
):
def
_install
(
self
):
def
_install
(
self
):
self
.
path_list
=
[]
#Get the IP list
kvm_conf
=
self
.
installKvm
(
vnc_ip
=
self
.
getLocalIPv4Address
())
connection_found
=
False
proxy_ip
=
self
.
getGlobalIPv6Address
()
vnc_port
=
5900
+
kvm_conf
[
'vnc_display'
]
proxy_port
=
6080
vnc_ip
=
self
.
getLocalIPv4Address
()
novnc_conf
=
self
.
installNovnc
(
source_ip
=
self
.
getGlobalIPv6Address
(),
vnc_port
=
5901
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
def
installKvm
(
self
,
vnc_ip
):
kvm_conf
=
dict
(
vnc_ip
=
vnc_ip
)
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
if
tap_interface
:
if
tap_interface
:
...
@@ -52,21 +67,26 @@ class Recipe(BaseSlapRecipe):
...
@@ -52,21 +67,26 @@ class Recipe(BaseSlapRecipe):
if
not
connection_found
:
if
not
connection_found
:
raise
NotImplementedError
(
"Do not support ip without tap interface"
)
raise
NotImplementedError
(
"Do not support ip without tap interface"
)
kvm_conf
[
'tap_interface'
]
=
tap_interface
# Disk path
# Disk path
disk_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'virtual.qcow2'
)
kvm_conf
[
'disk_path'
]
=
os
.
path
.
join
(
self
.
data_root_directory
,
socket_path
=
os
.
path
.
join
(
self
.
var_directory
,
'qmp_socket'
)
'virtual.qcow2'
)
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 and/or to input it yourself
##XXX -Vivien: add an option to generate one password for all instances
vnc_passwd
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
# 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
#XXX pid_file path, database_path, path to python binary and xml path
pid_file_path
=
os
.
path
.
join
(
self
.
run_directory
,
'pid_file'
)
kvm_conf
[
'pid_file_path'
]
=
os
.
path
.
join
(
self
.
run_directory
,
'pid_file'
)
database_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'slapmonitor_database'
)
kvm_conf
[
'database_path'
]
=
os
.
path
.
join
(
self
.
data_root_directory
,
python_path
=
sys
.
executable
'slapmonitor_database'
)
kvm_conf
[
'python_path'
]
=
sys
.
executable
#xml_path = os.path.join(self.var_directory, 'slapreport.xml' )
#xml_path = os.path.join(self.var_directory, 'slapreport.xml' )
# Create disk if needed
# 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"
%
(
retcode
=
subprocess
.
call
([
"%s create -f qcow2 %s %iG"
%
(
self
.
options
[
'qemu_img_path'
],
disk_path
,
self
.
options
[
'qemu_img_path'
],
disk_path
,
int
(
self
.
options
[
'disk_size'
]))],
shell
=
True
)
int
(
self
.
options
[
'disk_size'
]))],
shell
=
True
)
...
@@ -74,41 +94,44 @@ class Recipe(BaseSlapRecipe):
...
@@ -74,41 +94,44 @@ class Recipe(BaseSlapRecipe):
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
nbd_ip
=
self
.
parameter_dict
[
'nbd_ip'
]
kvm_conf
[
'nbd_ip'
]
=
self
.
parameter_dict
[
'nbd_ip'
]
nbd_port
=
self
.
parameter_dict
[
'nbd_port'
]
kvm_conf
[
'nbd_port'
]
=
self
.
parameter_dict
[
'nbd_port'
]
# First octet has to represent a locally administered address
# First octet has to represent a locally administered address
octet_list
=
[
254
]
+
[
random
.
randint
(
0x00
,
0xff
)
for
x
in
range
(
5
)]
octet_list
=
[
254
]
+
[
random
.
randint
(
0x00
,
0xff
)
for
x
in
range
(
5
)]
mac_address
=
':'
.
join
([
'%02x'
%
x
for
x
in
octet_list
])
kvm_conf
[
'mac_address'
]
=
':'
.
join
([
'%02x'
%
x
for
x
in
octet_list
])
hostname
=
"slaposkvm"
#raise NotImplementedError("%s" % self.parameter_dict)
kvm_conf
[
'hostname'
]
=
"slaposkvm"
self
.
computer_partition
.
setConnectionDict
(
dict
(
vnc_connection_string
=
"vnc://[%s]:1"
%
vnc_ip
,
vnc_password
=
vnc_passwd
,
))
# Instanciate KVM
# 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
# Instanciate KVM controller
kvm_controller_runner_path
=
self
.
instanciate
(
"kvm_controller"
,
[
socket_path
,
vnc_passwd
,
python_path
])
kvm_controller_runner_path
=
self
.
instanciate
(
"kvm_controller"
,
kvm_conf
)
#XXX Instanciate Slapmonitor
self
.
path_list
.
append
(
kvm_controller_runner_path
)
##slapmonitor_runner_path = self.instanciate("slapmonitor", [database_path, pid_file_path, python_path])
# Instanciate Slapmonitor
#XXX Instanciate Slapreport
##slapmonitor_runner_path = self.instanciate("slapmonitor",
##slapreport_runner_path = self.instanciate("slapreport", [database_path, python_path])
# [database_path, pid_file_path, python_path])
#XXX Instanciate Websockify
# Instanciate Slapreport
websockify_runner_path
=
self
.
instanciate
(
"websockify"
,
[
python_path
,
vnc_ip
,
proxy_ip
,
vnc_port
,
proxy_port
])
##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
):
def
instanciate
(
self
,
name
,
list
):
"""
"""
Define the path to the wrapper of the thing you are instanciating
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
Returns : path to the running wrapper
"""
"""
...
@@ -126,3 +149,25 @@ class Recipe(BaseSlapRecipe):
...
@@ -126,3 +149,25 @@ class Recipe(BaseSlapRecipe):
self
.
substituteTemplate
(
name_wrapper_template_location
,
name_config
))
self
.
substituteTemplate
(
name_wrapper_template_location
,
name_config
))
return
name_runner_path
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