cinder-volume revision 2605
2605N/A#!/usr/bin/python2.6
2605N/A
2605N/A# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
2605N/A#
2605N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
2605N/A# not use this file except in compliance with the License. You may obtain
2605N/A# a copy of the License at
2605N/A#
2605N/A# http://www.apache.org/licenses/LICENSE-2.0
2605N/A#
2605N/A# Unless required by applicable law or agreed to in writing, software
2605N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
2605N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2605N/A# License for the specific language governing permissions and limitations
2605N/A# under the License.
2605N/A
2605N/Aimport ConfigParser
2605N/Aimport os
2605N/A
2605N/Aimport smf_include
2605N/A
2605N/Afrom subprocess import CalledProcessError, Popen, PIPE, check_call
2605N/A
2605N/A
2605N/Adef start():
2605N/A """ checks cinder's conf file for the ZFSISCSIDriver. If it's found, make
2605N/A sure svc:/network/iscsi/target:default is online.
2605N/A
2605N/A """
2605N/A parser = ConfigParser.ConfigParser()
2605N/A parser.read("/etc/cinder/cinder.conf")
2605N/A driver = parser.get("DEFAULT", "volume_driver")
2605N/A if driver == "cinder.volume.drivers.solaris.zfs.ZFSISCSIDriver":
2605N/A iscsi_svc = "svc:/network/iscsi/target:default"
2605N/A cmd = ["/usr/bin/svcs", "-H", "-o", "state", iscsi_svc]
2605N/A try:
2605N/A p = Popen(cmd, stdout=PIPE, stderr=PIPE)
2605N/A output, error = p.communicate()
2605N/A except CalledProcessError:
2605N/A print "%s not found. Is it installed?" % iscsi_svc
2605N/A return smf_include.SMF_EXIT_ERR_CONFIG
2605N/A
2605N/A if output.strip() != "online":
2605N/A cmd = ["/usr/sbin/svcadm", "enable", "-rs", iscsi_svc]
2605N/A try:
2605N/A check_call(cmd)
2605N/A except CalledProcessError as err:
2605N/A print "enabling %s failed: %s" % (iscsi_svc, err)
2605N/A return smf_include.SMF_EXIT_ERR_CONFIG
2605N/A
2605N/A smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/cinder/cinder-volume")
2605N/A
2605N/Aif __name__ == "__main__":
2605N/A os.putenv("LC_ALL", "C")
2605N/A smf_include.smf_main()