nova-compute revision 5403
199767f8919635c4928607450d9e0abb932109ceToomas Soome#!/usr/bin/python2.7
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Licensed under the Apache License, Version 2.0 (the "License"); you may
199767f8919635c4928607450d9e0abb932109ceToomas Soome# not use this file except in compliance with the License. You may obtain
199767f8919635c4928607450d9e0abb932109ceToomas Soome# a copy of the License at
199767f8919635c4928607450d9e0abb932109ceToomas Soome#
199767f8919635c4928607450d9e0abb932109ceToomas Soome# http://www.apache.org/licenses/LICENSE-2.0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Unless required by applicable law or agreed to in writing, software
199767f8919635c4928607450d9e0abb932109ceToomas Soome# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
199767f8919635c4928607450d9e0abb932109ceToomas Soome# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
199767f8919635c4928607450d9e0abb932109ceToomas Soome# License for the specific language governing permissions and limitations
199767f8919635c4928607450d9e0abb932109ceToomas Soome# under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeimport ConfigParser
199767f8919635c4928607450d9e0abb932109ceToomas Soomeimport os
199767f8919635c4928607450d9e0abb932109ceToomas Soomefrom subprocess import CalledProcessError, Popen, PIPE, check_call
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeimport smf_include
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomedef start():
199767f8919635c4928607450d9e0abb932109ceToomas Soome # retrieve dataset path for suspend images
199767f8919635c4928607450d9e0abb932109ceToomas Soome nova_conf = "/etc/nova/nova.conf"
199767f8919635c4928607450d9e0abb932109ceToomas Soome if not os.path.exists(nova_conf):
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "%s doesn't exist" % nova_conf
199767f8919635c4928607450d9e0abb932109ceToomas Soome return smf_include.SMF_EXIT_ERR_CONFIG
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome parser = ConfigParser.ConfigParser()
199767f8919635c4928607450d9e0abb932109ceToomas Soome parser.read(nova_conf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome # retrieve the suspend path or just get the default
199767f8919635c4928607450d9e0abb932109ceToomas Soome default_path = '/var/share/zones/SYSsuspend'
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/zones/SYSsuspend')
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()