"""
import os
+import re
from cinder import exception
from cinder import flags
cfg.StrOpt('volumes_dir',
default='$state_path/volumes',
help='Volume configuration file storage directory'),
+ cfg.StrOpt('iet_conf',
+ default='/etc/iet/ietd.conf',
+ help='IET configuration file'),
]
FLAGS = flags.FLAGS
if chap_auth is not None:
(type, username, password) = chap_auth.split()
self._new_auth(tid, type, username, password, **kwargs)
+
+ conf_file = FLAGS.iet_conf
+ if os.path.exists(conf_file):
+ try:
+ volume_conf = """
+ Target %s
+ %s
+ Lun 0 Path=%s,Type=fileio
+ """ % (name, chap_auth, path)
+
+ with utils.temporary_chown(conf_file):
+ f = open(conf_file, 'a+')
+ f.write(volume_conf)
+ f.close()
+ except exception.ProcessExecutionError, e:
+ vol_id = name.split(':')[1]
+ LOG.error(_("Failed to create iscsi target for volume "
+ "id:%(vol_id)s.") % locals())
+ raise exception.ISCSITargetCreateFailed(volume_id=vol_id)
return tid
def remove_iscsi_target(self, tid, lun, vol_id, **kwargs):
LOG.info(_('Removing volume: %s') % vol_id)
self._delete_logicalunit(tid, lun, **kwargs)
self._delete_target(tid, **kwargs)
+ vol_uuid = 'volume-%s' % vol_id
+ conf_file = FLAGS.iet_conf
+ if os.path.exists(conf_file):
+ with utils.temporary_chown(conf_file):
+ try:
+ iet_conf_text = open(conf_file, 'r+')
+ full_txt = iet_conf_text.readlines()
+ new_iet_conf_txt = []
+ count = 0
+ for line in full_txt:
+ if count > 0:
+ count -= 1
+ continue
+ elif re.search(vol_uuid, line):
+ count = 2
+ continue
+ else:
+ new_iet_conf_txt.append(line)
+
+ iet_conf_text.seek(0)
+ iet_conf_text.truncate(0)
+ iet_conf_text.writelines(new_iet_conf_txt)
+ finally:
+ iet_conf_text.close()
def _new_target(self, name, tid, **kwargs):
self._run('--op', 'new',