]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add the persistency to the volume created by iscsi IET.
authorVincent Hou <sbhou@cn.ibm.com>
Tue, 13 Nov 2012 09:15:41 +0000 (17:15 +0800)
committerVincent Hou <sbhou@cn.ibm.com>
Thu, 22 Nov 2012 08:04:47 +0000 (16:04 +0800)
Bug 1070649.

Change-Id: Ia2e095a8a60a5d5ca028272ed2a35c20b4ad45a7

cinder/volume/iscsi.py

index 925921c4864045d5345ed5dba0d89a12580f0084..670b0e7edb3e6a7b3a1d1a917b9ffbf76d3a917e 100644 (file)
@@ -20,6 +20,7 @@ Helper code for the iSCSI volume driver.
 
 """
 import os
+import re
 
 from cinder import exception
 from cinder import flags
@@ -36,6 +37,9 @@ iscsi_helper_opt = [
         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
@@ -211,12 +215,55 @@ class IetAdm(TargetAdmin):
         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',