[node-patches] Change in ovirt-node[master]: move iscsi initiator operations into storage module
jboggs at redhat.com
jboggs at redhat.com
Mon Jan 27 15:33:46 UTC 2014
Joey Boggs has uploaded a new change for review.
Change subject: move iscsi initiator operations into storage module
......................................................................
move iscsi initiator operations into storage module
Signed-off-by: Joey Boggs <jboggs at redhat.com>
Change-Id: I08db8696b44b228feccb797d6ee323f734318462
---
M scripts/ovirt-auto-install.py
M src/Makefile.am
M src/ovirt/node/config/defaults.py
M src/ovirt/node/setup/core/remote_storage_page.py
M src/ovirt/node/utils/storage.py
M src/ovirtnode/install.py
D src/ovirtnode/iscsi.py
M src/ovirtnode/storage.py
8 files changed, 59 insertions(+), 73 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/63/23763/1
diff --git a/scripts/ovirt-auto-install.py b/scripts/ovirt-auto-install.py
index 1369625..0ff7f58 100755
--- a/scripts/ovirt-auto-install.py
+++ b/scripts/ovirt-auto-install.py
@@ -129,6 +129,18 @@
logger.warning("Unknown NFSv4 domain: %s" % \
OVIRT_VARS["OVIRT_NFSV4_DOMAIN"])
+class ConfigureiSCSI(Transaction.Element):
+ title = "Setting iSCSI Initiator Name"
+
+ def commit(self):
+ try:
+ model = defaults.iSCSI()
+ model.update(name=OVIRT_VARS["OVIRT_ISCSI_NAME"])
+ tx = model.transaction()
+ tx()
+ except:
+ logger.warning("Unable to set initiator name: %s" % \
+ OVIRT_VARS["OVIRT_ISCSI_NAME"])
class ConfigureLogging(Transaction.Element):
title = "Configuring Logging"
@@ -227,6 +239,8 @@
tx.append(ConfigureKdump())
+ tx.append(ConfigureiSCSI())
+
if not is_stateless():
tx.append(InstallBootloader())
diff --git a/src/Makefile.am b/src/Makefile.am
index 01919ff..9cbf767 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,7 +40,6 @@
pyovirtnode_PYTHON = \
ovirtnode/__init__.py \
ovirtnode/install.py \
- ovirtnode/iscsi.py \
ovirtnode/kdump.py \
ovirtnode/log.py \
ovirtnode/network.py \
diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index befacfd..bc5f126 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -1189,7 +1189,7 @@
>>> data[2:]
[('target_name', 'iqn.1992-01.com.example:target'), ('target_port', '42')]
"""
- keys = ("OVIRT_ISCSI_NODE_NAME",
+ keys = ("OVIRT_ISCSI_NAME",
"OVIRT_ISCSI_TARGET_NAME",
"OVIRT_ISCSI_TARGET_IP",
"OVIRT_ISCSI_TARGET_PORT")
@@ -1205,13 +1205,14 @@
def transaction(self):
cfg = dict(self.retrieve())
initiator_name = cfg["name"]
-
class ConfigureIscsiInitiator(utils.Transaction.Element):
title = "Setting the iSCSI initiator name"
def commit(self):
iscsi = utils.storage.iSCSI()
- iscsi.initiator_name(initiator_name)
+ iscsi.set_iscsi_initiator(initiator_name)
+ fs.Config().persist(iscsi.configfilename)
+ system.service("iscsid", "restart")
tx = utils.Transaction("Configuring the iSCSI Initiator")
tx.append(ConfigureIscsiInitiator())
diff --git a/src/ovirt/node/setup/core/remote_storage_page.py b/src/ovirt/node/setup/core/remote_storage_page.py
index d68618c..02b3f74 100644
--- a/src/ovirt/node/setup/core/remote_storage_page.py
+++ b/src/ovirt/node/setup/core/remote_storage_page.py
@@ -42,7 +42,7 @@
ncfg = defaults.NFSv4().retrieve()
model = {}
model["iscsi.initiator_name"] = icfg["name"] or \
- self.dry_or(lambda: storage.iSCSI().initiator_name())
+ self.dry_or(lambda: storage.iSCSI().set_iscsi_initiator())
model["nfsv4.domain"] = ncfg["domain"]
return model
diff --git a/src/ovirt/node/utils/storage.py b/src/ovirt/node/utils/storage.py
index 8958b70..0f272dc 100644
--- a/src/ovirt/node/utils/storage.py
+++ b/src/ovirt/node/utils/storage.py
@@ -23,19 +23,30 @@
from ovirt.node.utils import process
from ovirt.node.utils.fs import File
import os
+from ovirt.node.utils.system import service
class iSCSI(base.Base):
"""A class to deal with some external iSCSI related functionality
"""
- def initiator_name(self, initiator_name=None):
- try:
- import ovirtnode.iscsi as oiscsi
- if initiator_name:
- oiscsi.set_iscsi_initiator(initiator_name)
- return oiscsi.get_current_iscsi_initiator_name()
- except ImportError as e:
- self.logger.warning("Failed on import: %s" % e)
+ configfilename = "/etc/iscsi/initiatorname.iscsi"
+
+ def set_iscsi_initiator(self, initiator_name=None):
+ if not initiator_name:
+ initiator_name = process.check_output(["/sbin/iscsi-iname"])
+ iscsi_config = open(self.configfilename, "w")
+ iscsi_config.write("InitiatorName=" + initiator_name + "\n")
+ iscsi_config.close()
+ self.logger.info("Initiator name set as: " + initiator_name)
+ service("iscsid", "restart")
+
+ def get_current_iscsi_initiator_name(self):
+ iscsi_config = open(self.configfilename)
+ initiator_name = ""
+ for line in iscsi_config:
+ if "InitiatorName" in line:
+ initiator_name = line.replace("InitiatorName=", "")
+ return initiator_name.strip()
class NFSv4(base.Base):
diff --git a/src/ovirtnode/install.py b/src/ovirtnode/install.py
index 3b51723..d206bef 100755
--- a/src/ovirtnode/install.py
+++ b/src/ovirtnode/install.py
@@ -19,7 +19,8 @@
import ovirtnode.ovirtfunctions as _functions
import ovirt.node.utils.system as _system
-import ovirtnode.iscsi as _iscsi
+import ovirt.node.utils.process as _process
+from ovirt.node.config import defaults
import shutil
import traceback
import os
@@ -614,8 +615,20 @@
return False
_functions.disable_firstboot()
if _functions.finish_install():
- if _functions.is_firstboot():
- _iscsi.iscsi_auto()
+ iscsi_name = None
+ if "OVIRT_ISCSI_NAME" in _functions.OVIRT_VARS:
+ iscsi_name = _functions.OVIRT_VARS["OVIRT_ISCSI_NAME"]
+ logger.info("Found! Using iscsi_name %s" % iscsi_name)
+ try:
+ if not iscsi_name:
+ iscsi_name = _process.check_output(["/sbin/iscsi-iname"])
+ model = defaults.iSCSI()
+ model.update(name=iscsi_name)
+ tx = model.transaction()
+ tx()
+ except:
+ logger.warning("Unable to set initiator name: %s" % \
+ iscsi_name)
logger.info("Installation of %s Completed" % \
_functions.PRODUCT_SHORT)
if reboot is not None and reboot == "Y":
diff --git a/src/ovirtnode/iscsi.py b/src/ovirtnode/iscsi.py
deleted file mode 100755
index 9dbbaf0..0000000
--- a/src/ovirtnode/iscsi.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env python
-#
-# iscsi.py - Copyright (C) 2011 Red Hat, Inc.
-# Written by Joey Boggs <jboggs at redhat.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA. A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-import ovirtnode.ovirtfunctions as _functions
-import subprocess
-
-INITIATOR_FILE = "/etc/iscsi/initiatorname.iscsi"
-
-
-def set_iscsi_initiator(initiator_name):
- iscsi_config = open(INITIATOR_FILE, "w")
- iscsi_config.write("InitiatorName=" + initiator_name + "\n")
- iscsi_config.close()
- if _functions.ovirt_store_config(INITIATOR_FILE):
- _functions.logger.info("Initiator name set as: " + initiator_name)
- else:
- _functions.logger.warning("Setting initiator name failed")
- _functions.system_closefds("service iscsid restart &> /dev/null")
-
-
-def get_current_iscsi_initiator_name():
- iscsi_config = open(INITIATOR_FILE)
- initiator_name = ""
- for line in iscsi_config:
- if "InitiatorName" in line:
- initiator_name = line.replace("InitiatorName=", "")
- return initiator_name.strip()
-
-
-def iscsi_auto():
- if "OVIRT_ISCSI_NAME" not in _functions.OVIRT_VARS:
- _functions.logger.info("Generating iSCSI IQN")
- iscsi_iqn_cmd = _functions.subprocess_closefds("/sbin/iscsi-iname", \
- stdout=subprocess.PIPE)
- iscsi_iqn, err = iscsi_iqn_cmd.communicate()
- set_iscsi_initiator(iscsi_iqn.strip())
- else:
- set_iscsi_initiator(_functions.OVIRT_VARS["OVIRT_ISCSI_NAME"])
diff --git a/src/ovirtnode/storage.py b/src/ovirtnode/storage.py
index 2e11997..9ec002e 100644
--- a/src/ovirtnode/storage.py
+++ b/src/ovirtnode/storage.py
@@ -26,7 +26,7 @@
import logging
import subprocess
import shlex
-from ovirtnode.iscsi import set_iscsi_initiator
+from ovirt.node.config import defaults
logger = logging.getLogger(__name__)
@@ -771,7 +771,10 @@
if _functions.is_iscsi_install():
if "OVIRT_ISCSI_NAME" in _functions.OVIRT_VARS:
iscsi_name = _functions.OVIRT_VARS["OVIRT_ISCSI_NAME"]
- set_iscsi_initiator(iscsi_name)
+ model = defaults.iSCSI()
+ model.update(name=iscsi_name)
+ tx = model.transaction()
+ tx()
# login to target and setup disk
get_targets = ("iscsiadm -m discovery -p %s:%s -t sendtargets" %
(_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
--
To view, visit http://gerrit.ovirt.org/23763
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I08db8696b44b228feccb797d6ee323f734318462
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>
More information about the node-patches
mailing list