|
1 #!/usr/bin/python2.6 |
|
2 |
|
3 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may |
|
6 # not use this file except in compliance with the License. You may obtain |
|
7 # a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
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 |
|
14 # License for the specific language governing permissions and limitations |
|
15 # under the License. |
|
16 |
|
17 import ConfigParser |
|
18 import os |
|
19 |
|
20 import smf_include |
|
21 |
|
22 from subprocess import CalledProcessError, Popen, PIPE, check_call |
|
23 |
|
24 |
|
25 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") |
|
52 |
|
53 if __name__ == "__main__": |
|
54 os.putenv("LC_ALL", "C") |
|
55 smf_include.smf_main() |