"""Module implementing the job queue handling."""
-import os
import errno
from ganeti import constants
from ganeti import errors
+from ganeti import runtime
from ganeti import utils
"""
try:
- fd = open(file_name, "r")
- except IOError, err:
+ return int(utils.ReadFile(file_name))
+ except EnvironmentError, err:
if err.errno in (errno.ENOENT, ):
return None
raise
- try:
- return int(fd.read(128))
- finally:
- fd.close()
-
def ReadSerial():
"""Read the serial file.
locking mode.
"""
- # Make sure our directories exists
- for path in (constants.QUEUE_DIR, constants.JOB_QUEUE_ARCHIVE_DIR):
- try:
- os.mkdir(path, 0700)
- except OSError, err:
- if err.errno not in (errno.EEXIST, ):
- raise
+ getents = runtime.GetEnts()
# Lock queue
queue_lock = utils.FileLock.Open(constants.JOB_QUEUE_LOCK_FILE)
if version is None:
# Write new version file
utils.WriteFile(constants.JOB_QUEUE_VERSION_FILE,
+ uid=getents.masterd_uid, gid=getents.masterd_gid,
data="%s\n" % constants.JOB_QUEUE_VERSION)
# Read again
if serial is None:
# Write new serial file
utils.WriteFile(constants.JOB_QUEUE_SERIAL_FILE,
+ uid=getents.masterd_uid, gid=getents.masterd_gid,
data="%s\n" % 0)
# Read again