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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
4e5c2e86
Commit
4e5c2e86
authored
Sep 05, 2018
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.core: Include new plugin for adjust /dev/* permission for kvm
parent
5098540e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
0 deletions
+107
-0
slapos/manager/devperm.py
slapos/manager/devperm.py
+107
-0
No files found.
slapos/manager/devperm.py
0 → 100644
View file @
4e5c2e86
# coding: utf-8
import
json
import
logging
import
os
import
pwd
import
grp
from
.interface
import
IManager
from
itertools
import
ifilter
from
zope
import
interface
logger
=
logging
.
getLogger
(
__name__
)
def
which
(
exename
):
for
path
in
os
.
environ
[
"PATH"
].
split
(
os
.
pathsep
):
full_path
=
os
.
path
.
join
(
path
,
exename
)
if
os
.
path
.
exists
(
full_path
):
return
full_path
return
None
class
Manager
(
object
):
interface
.
implements
(
IManager
)
disk_device_filename
=
'.slapos-disk-permission'
def
__init__
(
self
,
config
):
"""Manager needs to know config for its functioning.
"""
self
.
config
=
config
def
format
(
self
,
computer
):
"""Method called at `slapos node format` phase.
:param computer: slapos.format.Computer, currently formatted computer
"""
def
formatTearDown
(
self
,
computer
):
"""Method called after `slapos node format` phase.
:param computer: slapos.format.Computer, formatted computer
"""
def
software
(
self
,
software
):
"""Method called at `slapos node software` phase.
:param software: slapos.grid.SlapObject.Software, currently processed software
"""
def
softwareTearDown
(
self
,
software
):
"""Method called after `slapos node software` phase.
:param computer: slapos.grid.SlapObject.Software, processed software
"""
def
instance
(
self
,
partition
):
"""Method called at `slapos node instance` phase.
:param partition: slapos.grid.SlapObject.Partition, currently processed partition
"""
self
.
instanceTearDown
(
partition
)
def
instanceTearDown
(
self
,
partition
):
"""Method called after `slapos node instance` phase.
:param partition: slapos.grid.SlapObject.Partition, processed partition
"""
disk_dev_path
=
os
.
path
.
join
(
partition
.
instance_path
,
self
.
disk_device_filename
)
if
not
os
.
path
.
exists
(
disk_dev_path
):
return
# Read it
with
open
(
disk_dev_path
)
as
f
:
try
:
disk_list
=
json
.
load
(
f
)
except
:
logger
.
warning
(
'Bad disk configuration file'
,
exc_info
=
True
)
return
for
entry
in
disk_list
:
disk
=
entry
.
get
(
"disk"
,
None
)
if
disk
is
None
:
logger
.
warning
(
"Disk is None: %s "
%
disk_list
,
exc_info
=
True
)
continue
if
not
str
(
disk
).
startswith
(
"/dev/"
):
logger
.
warning
(
"Bad disk definition: %s "
%
disk_list
,
exc_info
=
True
)
continue
if
len
(
disk
[
len
(
"/dev/"
):])
>
6
:
logger
.
warning
(
"Bad disk definition: %s "
%
disk_list
,
exc_info
=
True
)
continue
if
not
os
.
path
.
exists
(
disk
):
logger
.
warning
(
"Disk don't exist: %s "
%
disk_list
,
exc_info
=
True
)
continue
uid
=
os
.
stat
(
partition
.
instance_path
).
st_uid
if
os
.
stat
(
disk
).
st_uid
==
uid
:
continue
logger
.
warning
(
"Transfer ownership of %s to %s"
%
(
disk
,
pwd
.
getpwuid
(
uid
).
pw_name
))
os
.
chown
(
disk
,
uid
,
grp
.
getgrnam
(
"disk"
).
gr_gid
)
def
report
(
self
,
partition
):
"""Method called at `slapos node report` phase.
:param partition: slapos.grid.SlapObject.Partition, currently processed partition
"""
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