nova-compute revision 4779
#!/usr/bin/python2.7
# Copyright (c) 2013, 2015, 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 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
default_path = '/var/share/suspend'
try:
suspend_path = parser.get('DEFAULT', 'zones_suspend_path')
except ConfigParser.NoOptionError:
suspend_path = default_path
if not os.path.exists(suspend_path):
if suspend_path == default_path:
# 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
suspend_ds = os.path.join(rpool, 'VARSHARE/suspend')
try:
check_call(['/usr/bin/pfexec', '/usr/sbin/zfs', 'create', '-p',
'-o', 'mountpoint=' + suspend_path, suspend_ds])
except CalledProcessError as err:
print "unable to create %s: %s" % (suspend_ds, err)
return smf_include.SMF_EXIT_ERR_CONFIG
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
smf_include.smf_subprocess("/usr/bin/pfexec /usr/lib/nova/nova-compute")
if __name__ == "__main__":
os.putenv("LC_ALL", "C")
smf_include.smf_main()