4049N/A#!/usr/bin/python2.7
2521N/A
5403N/A# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2521N/A#
2521N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
2521N/A# not use this file except in compliance with the License. You may obtain
2521N/A# a copy of the License at
2521N/A#
2521N/A# http://www.apache.org/licenses/LICENSE-2.0
2521N/A#
2521N/A# Unless required by applicable law or agreed to in writing, software
2521N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
2521N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2521N/A# License for the specific language governing permissions and limitations
2521N/A# under the License.
2521N/A
4779N/Aimport ConfigParser
2521N/Aimport os
4779N/Afrom subprocess import CalledProcessError, Popen, PIPE, check_call
2521N/A
2521N/Aimport smf_include
2521N/A
2521N/A
5607N/Adef _create_dataset(path, poolname):
5607N/A # get the root pool name
5607N/A cmd = ['/usr/sbin/zfs', 'list', '-Ho', 'name', '/']
5607N/A p = Popen(cmd, stdout=PIPE, stderr=PIPE)
5607N/A output, error = p.communicate()
5607N/A if p.returncode != 0:
5607N/A print "unable to determine root pool name: %s" % (error)
5607N/A return smf_include.SMF_EXIT_ERR_CONFIG
5607N/A rpool = output.split('/')[0]
5607N/A
5607N/A # the default directory doesn't exist, create a new dataset for it
5607N/A ds = os.path.join(rpool, poolname)
5607N/A try:
5607N/A check_call(['/usr/bin/pfexec', '/usr/sbin/zfs', 'create', '-p',
5607N/A '-o', 'mountpoint=' + path, ds])
5607N/A except CalledProcessError as err:
5607N/A print "unable to create %s: %s" % (ds, err)
5607N/A return smf_include.SMF_EXIT_ERR_CONFIG
5607N/A
5607N/A return smf_include.SMF_EXIT_OK
5607N/A
5607N/A
2521N/Adef start():
4779N/A # retrieve dataset path for suspend images
4779N/A nova_conf = "/etc/nova/nova.conf"
4779N/A if not os.path.exists(nova_conf):
4779N/A print "%s doesn't exist" % nova_conf
4779N/A return smf_include.SMF_EXIT_ERR_CONFIG
4779N/A
4779N/A parser = ConfigParser.ConfigParser()
4779N/A parser.read(nova_conf)
4779N/A
4779N/A # retrieve the suspend path or just get the default
5607N/A suspend_default_path = '/var/share/zones/SYSsuspend'
4779N/A try:
6852N/A suspend_path = parser.get('solariszones', 'zones_suspend_path')
4779N/A except ConfigParser.NoOptionError:
5607N/A suspend_path = suspend_default_path
4779N/A
4779N/A if not os.path.exists(suspend_path):
5607N/A if suspend_path == suspend_default_path:
5607N/A ret = _create_dataset(suspend_path, 'VARSHARE/zones/SYSsuspend')
5607N/A if ret != smf_include.SMF_EXIT_OK:
5607N/A return ret
4779N/A else:
4779N/A # the user specified a path, but it doesn't exist
4779N/A print "Zones suspend path %s does not exist" % (suspend_path)
4779N/A return smf_include.SMF_EXIT_ERR_CONFIG
4779N/A
5607N/A # retrieve the image cache path or just get the default
5607N/A imagecache_default_path = '/var/share/nova/images'
5607N/A try:
6852N/A imagecache_path = parser.get('solariszones', 'glancecache_dirname')
5607N/A except ConfigParser.NoOptionError:
5607N/A imagecache_path = imagecache_default_path
5607N/A
5607N/A if not os.path.exists(imagecache_path):
5607N/A if imagecache_path == imagecache_default_path:
5607N/A ret = _create_dataset(imagecache_path, 'VARSHARE/nova/images')
5607N/A if ret != smf_include.SMF_EXIT_OK:
5607N/A return ret
5607N/A
5607N/A check_call(['/usr/bin/pfexec', '/usr/bin/chown', 'nova:nova',
5607N/A imagecache_path])
5607N/A
2521N/A smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/nova/nova-compute")
2521N/A
2521N/Aif __name__ == "__main__":
2521N/A os.putenv("LC_ALL", "C")
2521N/A smf_include.smf_main()