################################################## devel-oriented
tags:
- (find . '(' -name '*.py' -o -name '*.c' -o -name '*.spec' ')' ; ls initscripts/*) | xargs etags
+ git ls-files | xargs etags
.PHONY: tags
root_ssh = "/home/{}/.ssh".format(slicename)
sliver_ssh = "/vservers/{}/home/{}/.ssh".format(slicename, slicename)
def is_mounted (root_ssh):
- for mount_line in file('/proc/mounts').readlines():
- if mount_line.find (root_ssh) >= 0:
- return True
+ with open('/proc/mounts') as mountsfile:
+ for mount_line in mountsfile.readlines():
+ if mount_line.find (root_ssh) >= 0:
+ return True
return False
if do_mount:
# any of both might not exist yet
config = Config(optval)
elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id":
if os.path.exists(optval):
- node_id = file(optval).read().strip()
+ with open(optval) as optfile:
+ node_id = optfile.read().strip()
else:
node_id = int(optval)
elif opt == "-k" or opt == "--key":
if os.path.exists(optval):
- key = file(optval).read().strip()
+ with open(optval) as optfile:
+ key = optfile.read().strip()
else:
key = optval
else:
# Load /etc/planetlab/session
if os.path.exists(options.session):
- session = file(options.session).read().strip()
+ with open(options.session) as f:
+ session = f.read().strip()
else:
session = options.session
if glo_coresched_simulate:
print "F", cgroup
else:
- file(cgroup, "w").write(freeze)
+ with open(cgroup, "w") as f:
+ f.write(freeze)
except Exception as e:
# the cgroup probably didn't exit...
logger.log("CoreSched: exception while setting freeze for {} ({})".format(slicename, e))
if glo_coresched_simulate:
print "R", "/dev/cgroup/" + cgroup + "/" + var_name, self.listToRange(cpus)
else:
- file("/dev/cgroup/" + cgroup + "/" + var_name, "w").write( self.listToRange(cpus) + "\n" )
+ with opwn("/dev/cgroup/{}/{}".format(cgroup, var_name), "w") as f:
+ f.write( self.listToRange(cpus) + "\n" )
def reserveDefault (self, var_name, cpus):
if not os.path.exists("/etc/vservers/.defaults/cgroup"):
if glo_coresched_simulate:
print "RDEF", "/etc/vservers/.defaults/cgroup/" + var_name, self.listToRange(cpus)
else:
- file("/etc/vservers/.defaults/cgroup/" + var_name, "w").write( self.listToRange(cpus) + "\n" )
+ with open("/etc/vservers/.defaults/cgroup/{}".format(var_name), "w") as f:
+ f.write( self.listToRange(cpus) + "\n" )
def listToRange (self, list):
""" take a list of items [1,2,3,5,...] and return it as a range: "1-3,5"
enable_link = "/vservers/%s/etc/rc.d/rc3.d/S99vinit" % self.name
enable_target = "../init.d/vinit"
# install in sliver
- code = file(vinit_source).read()
+ with open(vinit_source) as f:
+ code = f.read()
if tools.replace_file_with_string(vinit_script, code, chmod=0755):
logger.log("Initscript: %s: installed generic vinit rc script" % self.name)
# create symlink for runlevel 3
enable_link = "/vservers/%s/etc/systemd/system/multi-user.target.wants/vinit.service" % self.name
enable_target = "/usr/lib/systemd/system/vinit.service"
# install in sliver
- code = file(vinit_source).read()
+ with open(vinit_source) as f:
+ code = f.read()
if tools.replace_file_with_string(vinit_unit_file, code, chmod=0755):
logger.log("Initscript: %s: installed vinit.service unit file" % self.name)
# create symlink for enabling this unit
# Load /etc/planetlab/session
if os.path.exists(self.options.session):
- session = file(self.options.session).read().strip()
+ with open(self.options.session) as f:
+ session = f.read().strip()
else:
session = None
if not os.path.exists(fn):
continue
- contents = file(fn,"r").read()
+ with open(fn) as f:
+ contents = f.read()
hostmap = []
for index, entry in enumerate(tag["value"].split("\n")):
contents = contents + hostmap
try:
- file(fn, "w").write(contents)
+ with open(fn, "w") as f:
+ f.write(contents)
except:
logger.log_exc("hostmap (%s): failed to write %s" % (slicename, fn))
in_vg.extend(map(lambda x: x.replace("!", "/"),
os.listdir("/sys/block/%s/slaves" % i)))
# Read the list of partitions
- partitions = file("/proc/partitions", "r")
- pat = re.compile("\s+")
- while True:
- buf = partitions.readline()
- if buf == "":
- break
- buf = buf.strip()
- fields = re.split(pat, buf)
- dev = fields[-1]
- if (not dev.startswith("dm-") and dev not in in_vg and
- os.path.exists("/dev/%s" % dev) and
- (os.minor(os.stat("/dev/%s" % dev).st_rdev) % 2) != 0):
- devices.append("/dev/%s" % dev)
+ with open("/proc/partitions") as partitions:
+ pat = re.compile("\s+")
+ while True:
+ buf = partitions.readline()
+ if buf == "":
+ break
+ buf = buf.strip()
+ fields = re.split(pat, buf)
+ dev = fields[-1]
+ if (not dev.startswith("dm-") and dev not in in_vg and
+ os.path.exists("/dev/%s" % dev) and
+ (os.minor(os.stat("/dev/%s" % dev).st_rdev) % 2) != 0):
+ devices.append("/dev/%s" % dev)
partitions.close()
return devices
if not os.path.isdir (dotssh):
os.mkdir (dotssh, 0700)
logger.log_call ( [ 'chown', "%s:slices"%(sliver['name']), dotssh ] )
- if not os.path.isfile (pubfile):
+ if not os.path.isfile(pubfile):
comment="%s@%s"%(sliver['name'],socket.gethostname())
logger.log_call( [ 'ssh-keygen', '-t', 'rsa', '-N', '', '-f', keyfile , '-C', comment] )
os.chmod (keyfile, 0400)
logger.log_call ( [ 'chown', "%s:slices"%(sliver['name']), keyfile, pubfile ] )
- return file(pubfile).read().strip()
+ with open(pubfile) as f:
+ return f.read().strip()
# a sliver can get created, deleted and re-created
# the slice having the tag is not sufficient to skip key geneneration
pass
for tagname in tagnames:
- tagfile = os.path.join(slicedir,tagname)
- values_n = file(tagfile).readlines()
- values = map(lambda s:s.rstrip(),values_n)
- slice = os.path.basename(slicedir)
- cur_privs[slice][tagname]=values
+ tagfilename = os.path.join(slicedir,tagname)
+ with open(tagfilename) as tagfile:
+ values_n = tagfile.readlines()
+ values = [ v.rstrip() for v in values_n ]
+ slice = os.path.basename(slicedir)
+ cur_privs[slice][tagname] = values
return cur_privs
# slice. This lets us know that we've done the sysctl.
try:
logger.log("vsys_sysctl: create file %s value %s" % (fn, value))
- file(fn,"w").write(value+"\n")
+ with open(fn,"w") as f:
+ f.write(value+"\n")
except:
logger.log("vsys_sysctl: failed to create file %s" % fn)
logger.log("creating /etc/slicename file in {}".format(os.path.join(containerDir, 'etc/slicename')))
try:
- file(os.path.join(containerDir, 'etc/slicename'), 'w').write(name)
+ with open(os.path.join(containerDir, 'etc/slicename'), 'w') as f:
+ f.write(name)
except:
logger.log_exc("exception while creating /etc/slicename")
try:
- file(os.path.join(containerDir, 'etc/slicefamily'), 'w').write(vref)
+ with open(os.path.join(containerDir, 'etc/slicefamily'), 'w') as f:
+ f.write(vref)
except:
logger.log_exc("exception while creating /etc/slicefamily")
sudoers = os.path.join(containerDir, 'etc/sudoers')
if os.path.exists(sudoers):
try:
- file(sudoers, 'a').write("{} ALL=(ALL) NOPASSWD: ALL\n".format(name))
+ with open(sudoers, 'a') as f:
+ f.write("{} ALL=(ALL) NOPASSWD: ALL\n".format(name))
except:
logger.log_exc("exception while updating /etc/sudoers")
if not os.path.isdir(os.path.dirname(from_root)): continue
found = False
try:
- contents = file(from_root).readlines()
- for content in contents:
- if content == enforced_line:
- found = True
+ with open(from_root) as f:
+ contents = f.readlines()
+ for content in contents:
+ if content == enforced_line:
+ found = True
except IOError:
pass
if not found:
# Template for libvirt sliver configuration
template_filename_sliceimage = os.path.join(Sliver_LXC.REF_IMG_BASE_DIR, 'lxc_template.xml')
- if os.path.isfile (template_filename_sliceimage):
+ if os.path.isfile(template_filename_sliceimage):
logger.verbose("Using XML template {}".format(template_filename_sliceimage))
template_filename = template_filename_sliceimage
else:
returns True if a change occurred, or the file is deleted
"""
try:
- current = file(target).read()
+ with open(target) as f:
+ current = f.read()
except:
current = ""
if current == new_contents:
global _node_id
if _node_id is None:
try:
- _node_id = int(file("/etc/planetlab/node_id").read())
+ with open("/etc/planetlab/node_id") as f:
+ _node_id = int(f.read())
except:
_node_id = ""
return _node_id
virt_stamp = "/etc/planetlab/virt"
def get_node_virt ():
try:
- return file(virt_stamp).read().strip()
+ with open(virt_stamp) as f:
+ return f.read().strip()
except:
pass
logger.log("Computing virt..")