3 # iscsi.py - Copyright (C) 2011 Red Hat, Inc.
4 # Written by Joey Boggs <jboggs@redhat.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA 02110-1301, USA. A copy of the GNU General Public License is
19 # also available at http://www.gnu.org/copyleft/gpl.html.
22 from ovirtnode
.ovirtfunctions
import *
25 INITIATOR_FILE
="/etc/iscsi/initiatorname.iscsi"
27 def set_iscsi_initiator(initiator_name
):
28 iscsi_config
= open(INITIATOR_FILE
, "w")
29 iscsi_config
.write("InitiatorName=" + initiator_name
+ "\n")
31 if ovirt_store_config(INITIATOR_FILE
):
32 logger
.info("Initiator name set as: " + initiator_name
)
34 logger
.warning("Setting initiator name failed")
35 os
.system("service iscsi restart &> /dev/null")
37 def get_current_iscsi_initiator_name():
38 iscsi_config
= open(INITIATOR_FILE
)
40 for line
in iscsi_config
:
41 if "InitiatorName" in line
:
42 initiator_name
= line
.replace("InitiatorName=","")
43 return initiator_name
.strip()
46 if not OVIRT_VARS
.has_key("OVIRT_ISCSI_NAME"):
47 logger
.info("Generating iSCSI IQN")
48 iscsi_iqn_cmd
= subprocess
.Popen("/sbin/iscsi-iname", stdout
=PIPE
)
49 iscsi_iqn
, err
= iscsi_iqn_cmd
.communicate()
50 set_iscsi_initiator(iscsi_iqn
.strip())
52 set_iscsi_initiator(OVIRT_VARS
["OVIRT_ISCSI_NAME"])