def create_iscsi_target(self, name, tid, lun, path, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility utils.ensure_tree(FLAGS.volumes_dir) vol_id = name.split(':')[1] volume_conf = """ <target %s> backing-store %s </target> """ % (name, path) LOG.info(_('Creating volume: %s') % vol_id) volumes_dir = FLAGS.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, 'w+') f.write(volume_conf) f.close() try: (out, err) = self._execute('tgt-admin', '--update', name, run_as_root=True) except exception.ProcessExecutionError, e: LOG.error(_("Failed to create iscsi target for volume " "id:%(vol_id)s.") % locals()) #Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id)
def create_iscsi_target(self, name, tid, lun, path, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility utils.ensure_tree(FLAGS.volumes_dir) vol_id = name.split(':')[1] volume_conf = """ <target %s> backing-store %s </target> """ % (name, path) LOG.info(_('Creating volume: %s') % vol_id) volumes_dir = FLAGS.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, 'w+') f.write(volume_conf) f.close() try: (out, err) = self._execute('tgt-admin', '--update', name, run_as_root=True) except exception.ProcessExecutionError, e: LOG.error( _("Failed to create iscsi target for volume " "id:%(vol_id)s.") % locals()) #Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id)
def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility utils.ensure_tree(FLAGS.volumes_dir) vol_id = name.split(":")[1] if chap_auth is None: volume_conf = """ <target %s> backing-store %s </target> """ % ( name, path, ) else: volume_conf = """ <target %s> backing-store %s %s </target> """ % ( name, path, chap_auth, ) LOG.info(_("Creating iscsi_target for: %s") % vol_id) volumes_dir = FLAGS.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, "w+") f.write(volume_conf) f.close() old_persist_file = None old_name = kwargs.get("old_name", None) if old_name is not None: old_persist_file = os.path.join(volumes_dir, old_name) try: (out, err) = self._execute("tgt-admin", "--update", name, run_as_root=True) except exception.ProcessExecutionError, e: LOG.error(_("Failed to create iscsi target for volume " "id:%(vol_id)s.") % locals()) # Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id)
def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility utils.ensure_tree(FLAGS.volumes_dir) vol_id = name.split(':')[1] if chap_auth is None: volume_conf = """ <target %s> backing-store %s </target> """ % (name, path) else: volume_conf = """ <target %s> backing-store %s %s </target> """ % (name, path, chap_auth) LOG.info(_('Creating iscsi_target for: %s') % vol_id) volumes_dir = FLAGS.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, 'w+') f.write(volume_conf) f.close() old_persist_file = None old_name = kwargs.get('old_name', None) if old_name is not None: old_persist_file = os.path.join(volumes_dir, old_name) try: (out, err) = self._execute('tgt-admin', '--update', name, run_as_root=True) except exception.ProcessExecutionError as e: LOG.error(_("Failed to create iscsi target for volume " "id:%(vol_id)s: %(e)s") % {'vol_id': vol_id, 'e': str(e)}) #Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) iqn = '%s%s' % (FLAGS.iscsi_target_prefix, vol_id) tid = self._get_target(iqn) if tid is None: LOG.error(_("Failed to create iscsi target for volume " "id:%(vol_id)s. Please ensure your tgtd config file " "contains 'include %(volumes_dir)s/*'") % locals()) raise exception.NotFound() if old_persist_file is not None and os.path.exists(old_persist_file): os.unlink(old_persist_file) return tid
def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility utils.ensure_tree(FLAGS.volumes_dir) vol_id = name.split(':')[1] if chap_auth is None: volume_conf = """ <target %s> backing-store %s </target> """ % (name, path) else: volume_conf = """ <target %s> backing-store %s %s </target> """ % (name, path, chap_auth) LOG.info(_('Creating iscsi_target for: %s') % vol_id) volumes_dir = FLAGS.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, 'w+') f.write(volume_conf) f.close() old_persist_file = None old_name = kwargs.get('old_name', None) if old_name is not None: old_persist_file = os.path.join(volumes_dir, old_name) try: (out, err) = self._execute('tgt-admin', '--update', name, run_as_root=True) except exception.ProcessExecutionError as e: LOG.error( _("Failed to create iscsi target for volume " "id:%(vol_id)s: %(e)s") % { 'vol_id': vol_id, 'e': str(e) }) #Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) iqn = '%s%s' % (FLAGS.iscsi_target_prefix, vol_id) tid = self._get_target(iqn) if tid is None: LOG.error( _("Failed to create iscsi target for volume " "id:%(vol_id)s. Please ensure your tgtd config file " "contains 'include %(volumes_dir)s/*'") % locals()) raise exception.NotFound() if old_persist_file is not None and os.path.exists(old_persist_file): os.unlink(old_persist_file) return tid