Revision cb66225d lib/tools/ensure_dirs.py
b/lib/tools/ensure_dirs.py | ||
---|---|---|
1 |
# |
|
2 |
# |
|
3 |
|
|
1 | 4 |
# Copyright (C) 2011 Google Inc. |
2 | 5 |
# |
3 | 6 |
# This program is free software; you can redistribute it and/or modify |
... | ... | |
30 | 33 |
from ganeti import errors |
31 | 34 |
from ganeti import runtime |
32 | 35 |
from ganeti import ssconf |
36 |
from ganeti import utils |
|
33 | 37 |
|
34 | 38 |
|
35 |
(DIR, FILE) = range(2) |
|
36 |
ALL_TYPES = frozenset([DIR, FILE]) |
|
39 |
(DIR, |
|
40 |
FILE, |
|
41 |
QUEUE_DIR) = range(1, 4) |
|
42 |
|
|
43 |
ALL_TYPES = frozenset([ |
|
44 |
DIR, |
|
45 |
FILE, |
|
46 |
QUEUE_DIR, |
|
47 |
]) |
|
37 | 48 |
|
38 | 49 |
|
39 | 50 |
class EnsureError(errors.GenericError): |
... | ... | |
122 | 133 |
gid=gid) |
123 | 134 |
|
124 | 135 |
|
136 |
def EnsureQueueDir(path, mode, uid, gid): |
|
137 |
"""Sets the correct permissions on all job files in the queue. |
|
138 |
|
|
139 |
@param path: Directory path |
|
140 |
@param mode: Wanted file mode |
|
141 |
@param uid: Wanted user ID |
|
142 |
@param gid: Wanted group ID |
|
143 |
|
|
144 |
""" |
|
145 |
for filename in utils.ListVisibleFiles(path): |
|
146 |
if constants.JOB_FILE_RE.match(filename): |
|
147 |
EnsurePermission(utils.PathJoin(path, filename), mode, uid=uid, gid=gid) |
|
148 |
|
|
149 |
|
|
125 | 150 |
def ProcessPath(path): |
126 | 151 |
"""Processes a path component. |
127 | 152 |
|
... | ... | |
132 | 157 |
|
133 | 158 |
assert pathtype in ALL_TYPES |
134 | 159 |
|
135 |
if pathtype == DIR:
|
|
160 |
if pathtype in (DIR, QUEUE_DIR):
|
|
136 | 161 |
# No additional parameters |
137 | 162 |
assert len(path[5:]) == 0 |
138 |
EnsureDir(pathname, mode, uid, gid) |
|
163 |
if pathtype == DIR: |
|
164 |
EnsureDir(pathname, mode, uid, gid) |
|
165 |
elif pathtype == QUEUE_DIR: |
|
166 |
EnsureQueueDir(pathname, mode, uid, gid) |
|
139 | 167 |
elif pathtype == FILE: |
140 | 168 |
(must_exist, ) = path[5:] |
141 | 169 |
EnsurePermission(pathname, mode, uid=uid, gid=gid, must_exist=must_exist) |
... | ... | |
178 | 206 |
paths.extend([ |
179 | 207 |
(constants.QUEUE_DIR, DIR, 0700, getent.masterd_uid, |
180 | 208 |
getent.masterd_gid), |
209 |
(constants.QUEUE_DIR, QUEUE_DIR, 0600, getent.masterd_uid, |
|
210 |
getent.masterd_gid), |
|
181 | 211 |
(constants.JOB_QUEUE_LOCK_FILE, FILE, 0600, |
182 | 212 |
getent.masterd_uid, getent.masterd_gid, False), |
183 | 213 |
(constants.JOB_QUEUE_SERIAL_FILE, FILE, 0600, |
Also available in: Unified diff