12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
14 # License for the specific language governing permissions and limitations |
14 # License for the specific language governing permissions and limitations |
15 # under the License. |
15 # under the License. |
16 |
16 |
17 import ConfigParser |
|
18 import os |
17 import os |
19 |
18 |
20 import smf_include |
19 import smf_include |
21 |
20 |
22 from subprocess import CalledProcessError, Popen, PIPE, check_call |
|
23 |
|
24 |
21 |
25 def start(): |
22 def start(): |
26 """ checks cinder's conf file for the ZFSISCSIDriver. If it's found, make |
|
27 sure svc:/network/iscsi/target:default is online. |
|
28 |
|
29 """ |
|
30 parser = ConfigParser.ConfigParser() |
|
31 parser.read("/etc/cinder/cinder.conf") |
|
32 driver = parser.get("DEFAULT", "volume_driver") |
|
33 if driver == "cinder.volume.drivers.solaris.zfs.ZFSISCSIDriver": |
|
34 iscsi_svc = "svc:/network/iscsi/target:default" |
|
35 cmd = ["/usr/bin/svcs", "-H", "-o", "state", iscsi_svc] |
|
36 try: |
|
37 p = Popen(cmd, stdout=PIPE, stderr=PIPE) |
|
38 output, error = p.communicate() |
|
39 except CalledProcessError: |
|
40 print "%s not found. Is it installed?" % iscsi_svc |
|
41 return smf_include.SMF_EXIT_ERR_CONFIG |
|
42 |
|
43 if output.strip() != "online": |
|
44 cmd = ["/usr/sbin/svcadm", "enable", "-rs", iscsi_svc] |
|
45 try: |
|
46 check_call(cmd) |
|
47 except CalledProcessError as err: |
|
48 print "enabling %s failed: %s" % (iscsi_svc, err) |
|
49 return smf_include.SMF_EXIT_ERR_CONFIG |
|
50 |
|
51 smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/cinder/cinder-volume") |
23 smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/cinder/cinder-volume") |
52 |
24 |
53 if __name__ == "__main__": |
25 if __name__ == "__main__": |
54 os.putenv("LC_ALL", "C") |
26 os.putenv("LC_ALL", "C") |
55 smf_include.smf_main() |
27 smf_include.smf_main() |