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