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 |
17 import os |
18 import os |
|
19 from subprocess import CalledProcessError, Popen, PIPE, check_call |
18 |
20 |
19 import smf_include |
21 import smf_include |
20 |
22 |
21 |
23 |
22 def start(): |
24 def start(): |
|
25 # retrieve dataset path for suspend images |
|
26 nova_conf = "/etc/nova/nova.conf" |
|
27 if not os.path.exists(nova_conf): |
|
28 print "%s doesn't exist" % nova_conf |
|
29 return smf_include.SMF_EXIT_ERR_CONFIG |
|
30 |
|
31 parser = ConfigParser.ConfigParser() |
|
32 parser.read(nova_conf) |
|
33 |
|
34 # retrieve the suspend path or just get the default |
|
35 default_path = '/var/share/suspend' |
|
36 try: |
|
37 suspend_path = parser.get('DEFAULT', 'zones_suspend_path') |
|
38 except ConfigParser.NoOptionError: |
|
39 suspend_path = default_path |
|
40 |
|
41 if not os.path.exists(suspend_path): |
|
42 if suspend_path == default_path: |
|
43 # get the root pool name |
|
44 cmd = ['/usr/sbin/zfs', 'list', '-Ho', 'name', '/'] |
|
45 p = Popen(cmd, stdout=PIPE, stderr=PIPE) |
|
46 output, error = p.communicate() |
|
47 if p.returncode != 0: |
|
48 print "unable to determine root pool name: %s" % (error) |
|
49 return smf_include.SMF_EXIT_ERR_CONFIG |
|
50 rpool = output.split('/')[0] |
|
51 |
|
52 # the default directory doesn't exist, create a new dataset for it |
|
53 suspend_ds = os.path.join(rpool, 'VARSHARE/suspend') |
|
54 try: |
|
55 check_call(['/usr/bin/pfexec', '/usr/sbin/zfs', 'create', '-p', |
|
56 '-o', 'mountpoint=' + suspend_path, suspend_ds]) |
|
57 except CalledProcessError as err: |
|
58 print "unable to create %s: %s" % (suspend_ds, err) |
|
59 return smf_include.SMF_EXIT_ERR_CONFIG |
|
60 else: |
|
61 # the user specified a path, but it doesn't exist |
|
62 print "Zones suspend path %s does not exist" % (suspend_path) |
|
63 return smf_include.SMF_EXIT_ERR_CONFIG |
|
64 |
23 smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/nova/nova-compute") |
65 smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/nova/nova-compute") |
24 |
66 |
25 if __name__ == "__main__": |
67 if __name__ == "__main__": |
26 os.putenv("LC_ALL", "C") |
68 os.putenv("LC_ALL", "C") |
27 smf_include.smf_main() |
69 smf_include.smf_main() |