# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Generic Solaris iSCSI utilities."""
import os
import platform
import time
"""Get the device path from the target info.
The output of cmd below is like this:
Target: iqn.2010-10.org.openstack:hostname1-tgt-grp-target
Alias: -
TPGT: 1
ISID: 4000002a0000
Connections: 1
LUN: 1
Vendor: SUN
Product: COMSTAR
OS Device Name: /dev/rdsk/c0t600144F0FDFAD05D0000563C04030003d0s2
LUN: 0
Vendor: SUN
Product: COMSTAR
OS Device Name: /dev/rdsk/c0t600144F0FDFAD05D0000563C02270002d0s2
"""
'target', '-S',
connection_properties['target_iqn'])
continue
if found:
return dev_path
if not found:
(connection_properties['target_iqn'],
connection_properties['target_lun']))
raise
"""Return the iSCSI initiator node name IQN"""
# Sample first line of command output:
# Initiator node name: iqn.1986-03.com.sun:01:e00000000000.4f757217
# TODO(Strony): handle the CHAP authentication
'--sendtargets', 'enable')
'discovery-address', '-v',
msg = _("No iSCSI target is found.")
raise
return
else:
raise
"""Attach the volume to instance_name.
connection_properties for iSCSI must include:
target_portal - ip and optional port
target_iqn - iSCSI Qualified Name
target_lun - LUN id of the volume
"""
# TODO(Strony): support the iSCSI multipath on Solaris.
# check if it is a valid device path.
break
else:
else:
# Set the label EFI to the disk on SPARC before it is accessed and
# make sure the correct device path with slice 0
# (like '/dev/rdsk/c0t600xxxd0s0').
return device_info