Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Arnaud Véron
slapos.core
Commits
b4de4ad1
Commit
b4de4ad1
authored
Jun 09, 2017
by
Tomáš Peterka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace plurals
parent
69e53d9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
22 deletions
+22
-22
slapos/format.py
slapos/format.py
+20
-20
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+2
-2
No files found.
slapos/format.py
View file @
b4de4ad1
...
@@ -66,7 +66,7 @@ logger = logging.getLogger("slapos.format")
...
@@ -66,7 +66,7 @@ logger = logging.getLogger("slapos.format")
# dict[str: ManagerClass] used in configuration and XML dump of computer
# dict[str: ManagerClass] used in configuration and XML dump of computer
# this dictionary is intended to be filled after each definition of a Manager
# this dictionary is intended to be filled after each definition of a Manager
available_manager
s
=
{}
available_manager
_list
=
{}
def
prettify_xml
(
xml
):
def
prettify_xml
(
xml
):
...
@@ -427,7 +427,7 @@ class CGroupManager(Manager):
...
@@ -427,7 +427,7 @@ class CGroupManager(Manager):
return
folder
return
folder
# mark manager available
# mark manager available
available_manager
s
[
CGroupManager
.
short_name
]
=
CGroupManager
available_manager
_list
[
CGroupManager
.
short_name
]
=
CGroupManager
class
Computer
(
object
):
class
Computer
(
object
):
...
@@ -437,7 +437,7 @@ class Computer(object):
...
@@ -437,7 +437,7 @@ class Computer(object):
ipv6_interface
=
None
,
software_user
=
'slapsoft'
,
ipv6_interface
=
None
,
software_user
=
'slapsoft'
,
tap_gateway_interface
=
None
,
tap_gateway_interface
=
None
,
instance_root
=
None
,
software_root
=
None
,
instance_storage_home
=
None
,
instance_root
=
None
,
software_root
=
None
,
instance_storage_home
=
None
,
partition_list
=
None
,
manager
s
=
None
):
partition_list
=
None
,
manager
_list
=
None
):
"""
"""
Attributes:
Attributes:
reference: str, the reference of the computer.
reference: str, the reference of the computer.
...
@@ -466,11 +466,11 @@ class Computer(object):
...
@@ -466,11 +466,11 @@ class Computer(object):
self
.
slapos_version
=
None
self
.
slapos_version
=
None
# HASA relation to managers (could turn into plugins with `format` and `update` methods)
# HASA relation to managers (could turn into plugins with `format` and `update` methods)
self
.
manager
s
=
managers
# for serialization
self
.
manager
_list
=
manager_list
# for serialization
# hide list[Manager] from serializer by prepending "_"
# hide list[Manager] from serializer by prepending "_"
self
.
_manager_list
=
tuple
(
filter
(
lambda
manager
:
manager
.
is_allowed
(),
self
.
_manager_list
=
tuple
(
filter
(
lambda
manager
:
manager
.
is_allowed
(),
(
available_manager
s
[
manager_str
](
self
)
for
manager_str
in
managers
)))
\
(
available_manager
_list
[
manager_str
](
self
)
for
manager_str
in
manager_list
)))
\
if
manager
s
else
tuple
()
if
manager
_list
else
tuple
()
def
__getinitargs__
(
self
):
def
__getinitargs__
(
self
):
return
(
self
.
reference
,
self
.
interface
)
return
(
self
.
reference
,
self
.
interface
)
...
@@ -600,7 +600,7 @@ class Computer(object):
...
@@ -600,7 +600,7 @@ class Computer(object):
@
classmethod
@
classmethod
def
load
(
cls
,
path_to_xml
,
reference
,
ipv6_interface
,
tap_gateway_interface
,
def
load
(
cls
,
path_to_xml
,
reference
,
ipv6_interface
,
tap_gateway_interface
,
instance_root
=
None
,
software_root
=
None
,
manager
s
=
None
):
instance_root
=
None
,
software_root
=
None
,
manager
_list
=
None
):
"""
"""
Create a computer object from a valid xml file.
Create a computer object from a valid xml file.
...
@@ -624,10 +624,10 @@ class Computer(object):
...
@@ -624,10 +624,10 @@ class Computer(object):
tap_gateway_interface
=
tap_gateway_interface
,
tap_gateway_interface
=
tap_gateway_interface
,
software_root
=
dumped_dict
.
get
(
'software_root'
,
software_root
),
software_root
=
dumped_dict
.
get
(
'software_root'
,
software_root
),
instance_root
=
dumped_dict
.
get
(
'instance_root'
,
instance_root
),
instance_root
=
dumped_dict
.
get
(
'instance_root'
,
instance_root
),
manager
s
=
dumped_dict
.
get
(
'managers'
,
managers
),
manager
_list
=
dumped_dict
.
get
(
'manager_list'
,
manager_list
),
)
)
for
i
,
partition_dict
in
enumerate
(
dumped_dict
[
'partition_list'
]):
for
partition_index
,
partition_dict
in
enumerate
(
dumped_dict
[
'partition_list'
]):
if
partition_dict
[
'user'
]:
if
partition_dict
[
'user'
]:
user
=
User
(
partition_dict
[
'user'
][
'name'
])
user
=
User
(
partition_dict
[
'user'
][
'name'
])
...
@@ -645,10 +645,10 @@ class Computer(object):
...
@@ -645,10 +645,10 @@ class Computer(object):
tap
=
Tap
(
partition_dict
[
'reference'
])
tap
=
Tap
(
partition_dict
[
'reference'
])
if
partition_dict
.
get
(
'tun'
)
is
not
None
and
partition_dict
[
'tun'
].
get
(
'ipv4_addr'
)
is
not
None
:
if
partition_dict
.
get
(
'tun'
)
is
not
None
and
partition_dict
[
'tun'
].
get
(
'ipv4_addr'
)
is
not
None
:
tun
=
Tun
(
partition_dict
[
'tun'
][
'name'
],
i
,
len
(
dumped_dict
[
'partition_list'
]))
tun
=
Tun
(
partition_dict
[
'tun'
][
'name'
],
partition_index
,
len
(
dumped_dict
[
'partition_list'
]))
tun
.
ipv4_addr
=
partition_dict
[
'tun'
][
'ipv4_addr'
]
tun
.
ipv4_addr
=
partition_dict
[
'tun'
][
'ipv4_addr'
]
else
:
else
:
tun
=
Tun
(
"slaptun"
+
str
(
i
),
i
,
len
(
dumped_dict
[
'partition_list'
]))
tun
=
Tun
(
"slaptun"
+
str
(
partition_index
),
partition_index
,
len
(
dumped_dict
[
'partition_list'
]))
address_list
=
partition_dict
[
'address_list'
]
address_list
=
partition_dict
[
'address_list'
]
external_storage_list
=
partition_dict
.
get
(
'external_storage_list'
,
[])
external_storage_list
=
partition_dict
.
get
(
'external_storage_list'
,
[])
...
@@ -1509,7 +1509,7 @@ def parse_computer_xml(conf, xml_path):
...
@@ -1509,7 +1509,7 @@ def parse_computer_xml(conf, xml_path):
tap_gateway_interface
=
conf
.
tap_gateway_interface
,
tap_gateway_interface
=
conf
.
tap_gateway_interface
,
software_root
=
conf
.
software_root
,
software_root
=
conf
.
software_root
,
instance_root
=
conf
.
instance_root
,
instance_root
=
conf
.
instance_root
,
manager
s
=
conf
.
managers
)
manager
_list
=
conf
.
manager_list
)
# Connect to the interface defined by the configuration
# Connect to the interface defined by the configuration
computer
.
interface
=
interface
computer
.
interface
=
interface
else
:
else
:
...
@@ -1525,7 +1525,7 @@ def parse_computer_xml(conf, xml_path):
...
@@ -1525,7 +1525,7 @@ def parse_computer_xml(conf, xml_path):
ipv6_interface
=
conf
.
ipv6_interface
,
ipv6_interface
=
conf
.
ipv6_interface
,
software_user
=
conf
.
software_user
,
software_user
=
conf
.
software_user
,
tap_gateway_interface
=
conf
.
tap_gateway_interface
,
tap_gateway_interface
=
conf
.
tap_gateway_interface
,
manager
s
=
conf
.
managers
,
manager
_list
=
conf
.
manager_list
,
)
)
partition_amount
=
int
(
conf
.
partition_amount
)
partition_amount
=
int
(
conf
.
partition_amount
)
...
@@ -1640,7 +1640,7 @@ class FormatConfig(object):
...
@@ -1640,7 +1640,7 @@ class FormatConfig(object):
tap_gateway_interface
=
None
tap_gateway_interface
=
None
use_unique_local_address_block
=
None
use_unique_local_address_block
=
None
instance_storage_home
=
None
instance_storage_home
=
None
manager
s
=
None
manager
_list
=
None
def
__init__
(
self
,
logger
):
def
__init__
(
self
,
logger
):
self
.
logger
=
logger
self
.
logger
=
logger
...
@@ -1730,13 +1730,13 @@ class FormatConfig(object):
...
@@ -1730,13 +1730,13 @@ class FormatConfig(object):
# Split str into list[str] and check availability of every manager
# Split str into list[str] and check availability of every manager
# Config value is expected to be strings separated by spaces or commas
# Config value is expected to be strings separated by spaces or commas
manager
s
=
[]
manager
_list
=
[]
for
manager
in
self
.
manager
s
.
replace
(
","
,
" "
).
split
():
for
manager
in
self
.
manager
_list
.
replace
(
","
,
" "
).
split
():
if
manager
not
in
available_manager
s
:
if
manager
not
in
available_manager
_list
:
raise
ValueError
(
"Unknown manager
\
"
{}
\
"
! Known are: {!s}"
.
format
(
raise
ValueError
(
"Unknown manager
\
"
{}
\
"
! Known are: {!s}"
.
format
(
manager
,
list
(
available_manager
s
.
keys
())))
manager
,
list
(
available_manager
_list
.
keys
())))
manager
s
.
append
(
manager
)
manager
_list
.
append
(
manager
)
self
.
manager
s
=
managers
# replace original str with list[str] of known managers
self
.
manager
_list
=
manager_list
# replace original str with list[str] of known managers
if
not
self
.
dry_run
:
if
not
self
.
dry_run
:
if
self
.
alter_user
:
if
self
.
alter_user
:
...
...
slapos/tests/slapformat.py
View file @
b4de4ad1
...
@@ -195,7 +195,7 @@ class CGroupManagerMock(slapos.format.CGroupManager):
...
@@ -195,7 +195,7 @@ class CGroupManagerMock(slapos.format.CGroupManager):
return
True
return
True
# update available managers with our partially-mocked version
# update available managers with our partially-mocked version
slapos
.
format
.
available_manager
s
[
CGroupManagerMock
.
short_name
]
=
CGroupManagerMock
slapos
.
format
.
available_manager
_list
[
CGroupManagerMock
.
short_name
]
=
CGroupManagerMock
class
SlapformatMixin
(
unittest
.
TestCase
):
class
SlapformatMixin
(
unittest
.
TestCase
):
...
@@ -705,7 +705,7 @@ class TestComputerWithCGroup(SlapformatMixin):
...
@@ -705,7 +705,7 @@ class TestComputerWithCGroup(SlapformatMixin):
slapos
.
format
.
Partition
(
slapos
.
format
.
Partition
(
'partition'
,
'/tmp/slapgrid/instance_root/part1'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
None
),
'partition'
,
'/tmp/slapgrid/instance_root/part1'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
None
),
],
],
manager
s
=
(
CGroupManagerMock
.
short_name
,
)
manager
_list
=
(
CGroupManagerMock
.
short_name
,
)
)
)
# self.patchOs(self.logger)
# self.patchOs(self.logger)
...
...
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