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
Gabriel Monnerat
slapos
Commits
50d0d648
Commit
50d0d648
authored
Jul 01, 2011
by
Vivien Alger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring of the kvm recipe
parent
a9583aa9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
67 deletions
+53
-67
slapos/recipe/kvm/__init__.py
slapos/recipe/kvm/__init__.py
+53
-67
No files found.
slapos/recipe/kvm/__init__.py
View file @
50d0d648
...
@@ -40,10 +40,14 @@ class Recipe(BaseSlapRecipe):
...
@@ -40,10 +40,14 @@ class Recipe(BaseSlapRecipe):
#Get the IP list
#Get the IP list
connection_found
=
False
connection_found
=
False
ip
=
self
.
getGlobalIPv6Address
()
proxy_ip
=
self
.
getGlobalIPv6Address
()
for
tap
,
dummy
in
self
.
parameter_dict
[
'ip_list'
]:
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
# Get an ip associated to a tap interface
if
tap
:
if
tap
_interface
:
connection_found
=
True
connection_found
=
True
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"
)
...
@@ -52,11 +56,13 @@ class Recipe(BaseSlapRecipe):
...
@@ -52,11 +56,13 @@ class Recipe(BaseSlapRecipe):
disk_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'virtual.qcow2'
)
disk_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'virtual.qcow2'
)
socket_path
=
os
.
path
.
join
(
self
.
var_directory
,
'qmp_socket'
)
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
vnc_passwd
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
vnc_passwd
=
binascii
.
hexlify
(
os
.
urandom
(
4
))
#XXX pid_file path, database_path 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'
)
pid_file_path
=
os
.
path
.
join
(
self
.
run_directory
,
'pid_file'
)
database_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'slapmonitor_database'
)
database_path
=
os
.
path
.
join
(
self
.
data_root_directory
,
'slapmonitor_database'
)
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
...
@@ -67,76 +73,56 @@ class Recipe(BaseSlapRecipe):
...
@@ -67,76 +73,56 @@ class Recipe(BaseSlapRecipe):
if
retcode
!=
0
:
if
retcode
!=
0
:
raise
OSError
,
"Disk creation failed!"
raise
OSError
,
"Disk creation failed!"
# Instanciate KVM
kvm_config
=
{}
# Options nbd_ip and nbd_port are provided by slapos master
# Options nbd_ip and nbd_port are provided by slapos master
kvm_config
.
update
(
self
.
options
)
nbd_ip
=
self
.
parameter_dict
[
'nbd_ip'
]
#raise NotImplementedError("%s" % self.parameter_dict)
nbd_port
=
self
.
parameter_dict
[
'nbd_port'
]
kvm_config
[
'vnc_ip'
]
=
ip
kvm_config
[
'tap_interface'
]
=
tap
kvm_config
[
'nbd_ip'
]
=
self
.
parameter_dict
[
'nbd_ip'
]
kvm_config
[
'nbd_port'
]
=
self
.
parameter_dict
[
'nbd_port'
]
#XXX
kvm_config
[
'pid_file'
]
=
pid_file_path
kvm_config
[
'image'
]
=
disk_path
# 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
)]
kvm_config
[
'mac_address'
]
=
':'
.
join
([
'%02x'
%
x
for
x
in
octet_list
])
mac_address
=
':'
.
join
([
'%02x'
%
x
for
x
in
octet_list
])
kvm_config
[
'qmp_socket'
]
=
socket_path
kvm_config
[
'hostname'
]
=
"slaposkvm"
kvm_wrapper_template_location
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
'template'
,
'kvm_run.in'
))
kvm_runner_path
=
self
.
createRunningWrapper
(
"kvm"
,
self
.
substituteTemplate
(
kvm_wrapper_template_location
,
kvm_config
))
hostname
=
"slaposkvm"
# Instanciate KVM controller
#raise NotImplementedError("%s" % self.parameter_dict)
controller_config
=
{}
# Options nbd_ip and nbd_port are provided by slapos master
controller_config
.
update
(
self
.
options
)
controller_config
[
'qmp_socket'
]
=
socket_path
controller_config
[
'vnc_passwd'
]
=
vnc_passwd
controller_config
[
'python_path'
]
=
sys
.
executable
controller_wrapper_template_location
=
pkg_resources
.
resource_filename
(
self
.
computer_partition
.
setConnectionDict
(
dict
(
__name__
,
os
.
path
.
join
(
vnc_connection_string
=
"vnc://[%s]:1"
%
vnc_ip
,
'template'
,
'kvm_controller_run.in'
))
vnc_password
=
vnc_passwd
,
controller_runner_path
=
self
.
createRunningWrapper
(
"kvm_controller"
,
))
self
.
substituteTemplate
(
controller_wrapper_template_location
,
controller_config
))
# 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
])
# Instanciate KVM controller
kvm_controller_runner_path
=
self
.
instanciate
(
"kvm_controller"
,
[
socket_path
,
vnc_passwd
,
python_path
])
#XXX Instanciate Slapmonitor
#XXX Instanciate Slapmonitor
slapmonitor_config
=
{}
##slapmonitor_runner_path = self.instanciate("slapmonitor", [database_path, pid_file_path, python_path])
slapmonitor_config
.
update
(
self
.
options
)
#XXX Instanciate Slapreport
slapmonitor_config
[
'database_path'
]
=
database_path
##slapreport_runner_path = self.instanciate("slapreport", [database_path, python_path])
slapmonitor_config
[
'pid_file'
]
=
pid_file_path
#XXX Instanciate Websockify
slapmonitor_config
[
'python_path'
]
=
sys
.
executable
websockify_runner_path
=
self
.
instanciate
(
"websockify"
,
[
python_path
,
vnc_ip
,
proxy_ip
,
vnc_port
,
proxy_port
])
slapmonitor_wrapper_template_location
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
'template'
,
'slapmonitor_run.in'
))
slapmonitor_runner_path
=
self
.
createRunningWrapper
(
"slapmonitor"
,
self
.
substituteTemplate
(
slapmonitor_wrapper_template_location
,
slapmonitor_config
))
#XXX Instanciate Slapreport
return
[
kvm_runner_path
,
kvm_controller_runner_path
,
websockify_runner_path
]
slapreport_config
=
{}
slapreport_config
.
update
(
self
.
options
)
slapreport_config
[
'database_path'
]
=
database_path
slapreport_config
[
'python_path'
]
=
sys
.
executable
slapreport_wrapper_template_location
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
'template'
,
'slapreport_run.in'
))
slapreport_runner_path
=
self
.
createReportRunningWrapper
(
self
.
substituteTemplate
(
slapreport_wrapper_template_location
,
slapreport_config
))
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
Returns : path to the running wrapper
"""
name_config
=
{}
name_config
.
update
(
self
.
options
)
self
.
computer_partition
.
setConnectionDict
(
dict
(
for
e
in
list
:
vnc_connection_string
=
"vnc://[%s]:1"
%
ip
,
name_config
[
'i'
]
=
i
vnc_password
=
vnc_passwd
,
))
name_wrapper_template_location
=
pkg_resources
.
resource_filename
(
__name__
,
os
.
path
.
join
(
'template'
,
'name_run.in'
))
return
[
kvm_runner_path
,
controller_runner_path
]
name_runner_path
=
self
.
createRunningWrapper
(
name
,
self
.
substituteTemplate
(
name_wrapper_template_location
,
name_config
))
return
name_runner_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