def fix_anomalies(self):
to_prune = []
# machine_index = MachineIndex()
for uuid, exports in six.iteritems(self.exports):
# machine = machine_index.get_by_uuid(uuid)
# machine cannot be found in the index
# if not machine:
# to_prune.append(uuid)
# continue
# one of the path does not exists anymore
if [path for path in exports if not os.path.exists(path)]:
to_prune.append(uuid)
continue
# remove all exports that have issues
for uuid in to_prune:
logger.info('pruning NFS entry for %s' % uuid)
# taken from vagrant/plugins/hosts/linux/cap/nfs.rb
extended_re_flag = '-r'
sed_expr = '\\\x01^# VAGRANT-BEGIN:( {user})? {id}\x01,' \
'\\\x01^# VAGRANT-END:( {user})? {id}\x01 d'.format(
id=uuid,
user=os.getuid()
)
if platform.system() == 'Darwin':
extended_re_flag = '-E'
sed_expr = '/^# VAGRANT-BEGIN:( {user})? {id}/,' \
'/^# VAGRANT-END:( {user})? {id}/ d'.format(
id=uuid,
user=os.getuid()
)
cmd = [
'sed',
extended_re_flag,
'-e',
sed_expr,
'-ibak',
self.export_file
]
# if we do not have write access, use sudo
if not os.access(self.export_file, os.W_OK):
cmd = [
'sudo',
'-p'
'Fixing invalid NFS exports. Administrators privileges '
'are required\n[sudo] password for %u',
'--'
] + cmd
if call(cmd) != 0:
raise RuntimeError('could not prune invalid nfs exports '
'"%s" from /etc/exports' % uuid)
评论列表
文章目录