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
Ophélie Gagnard
slapos.core
Commits
5818daed
Commit
5818daed
authored
Jun 09, 2017
by
Tomáš Peterka
Committed by
Rafael Monnerat
Jun 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[format] Dump allocated per-partition resources into the partition
parent
081e745e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
slapos/format.py
slapos/format.py
+24
-4
No files found.
slapos/format.py
View file @
5818daed
...
@@ -378,6 +378,9 @@ class Computer(object):
...
@@ -378,6 +378,9 @@ class Computer(object):
with
open
(
path_to_xml
,
'wb'
)
as
fout
:
with
open
(
path_to_xml
,
'wb'
)
as
fout
:
fout
.
write
(
new_pretty_xml
)
fout
.
write
(
new_pretty_xml
)
for
partition
in
self
.
partition_list
:
partition
.
dump
()
def
backup_xml
(
self
,
path_to_archive
,
path_to_xml
):
def
backup_xml
(
self
,
path_to_archive
,
path_to_xml
):
"""
"""
Stores a copy of the current xml file to an historical archive.
Stores a copy of the current xml file to an historical archive.
...
@@ -413,7 +416,7 @@ class Computer(object):
...
@@ -413,7 +416,7 @@ class Computer(object):
tap_gateway_interface
=
tap_gateway_interface
,
tap_gateway_interface
=
tap_gateway_interface
,
)
)
for
partition_
dict
in
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'
])
...
@@ -629,16 +632,20 @@ class Computer(object):
...
@@ -629,16 +632,20 @@ class Computer(object):
class
Partition
(
object
):
class
Partition
(
object
):
"Represent a computer partition"
"""Represent a computer partition."""
resource_file
=
".slapos-resource"
def
__init__
(
self
,
reference
,
path
,
user
,
address_list
,
tap
,
external_storage_list
=
[]):
def
__init__
(
self
,
reference
,
path
,
user
,
address_list
,
tap
,
external_storage_list
=
[],
tun
=
None
):
"""
"""
Attributes:
Attributes:
reference: String, the name of the partition.
reference: String, the name of the partition.
path: String, the path to the partition folder.
path: String, the path to the partition folder.
user: User, the user linked to this partition.
user: User, the user linked to this partition.
address_list: List of associated IP addresses.
address_list: List of associated IP addresses.
tap: Tap, the tap interface linked to this partition.
tap: Tap, the tap interface linked to this partition e.g. used as a bridge for kvm
tun: Tun interface used for special apps simulating ethernet connections
external_storage_list: Base path list of folder to format for data storage
external_storage_list: Base path list of folder to format for data storage
"""
"""
...
@@ -684,6 +691,19 @@ class Partition(object):
...
@@ -684,6 +691,19 @@ class Partition(object):
os
.
chown
(
storage_path
,
owner_pw
.
pw_uid
,
owner_pw
.
pw_gid
)
os
.
chown
(
storage_path
,
owner_pw
.
pw_uid
,
owner_pw
.
pw_gid
)
os
.
chmod
(
storage_path
,
0o750
)
os
.
chmod
(
storage_path
,
0o750
)
def
dump
(
self
):
"""Dump available resources into ~partition_home/.slapos-resource."""
file_path
=
os
.
path
.
join
(
self
.
path
,
self
.
resource_file
)
logger
.
info
(
"Partition resources saved to {}"
.
format
(
self
.
reference
,
file_path
))
data
=
_getDict
(
self
)
with
open
(
file_path
,
"wb"
)
as
fo
:
json
.
dump
(
data
,
fo
,
sort_keys
=
True
,
indent
=
4
)
owner_pw
=
pwd
.
getpwnam
(
self
.
user
.
name
)
os
.
chmod
(
file_path
,
0o640
)
os
.
chown
(
file_path
,
owner_pw
.
pw_uid
,
owner_pw
.
pw_gid
)
class
User
(
object
):
class
User
(
object
):
"""User: represent and manipulate a user on the system."""
"""User: represent and manipulate a user on the system."""
...
...
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