nova-compute revision 5190
4049N/A#!/usr/bin/python2.7
2521N/A
4049N/A# Copyright (c) 2013, 2015, 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
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
5190N/A default_path = '/var/share/zones/SYSsuspend'
4779N/A try:
4779N/A suspend_path = parser.get('DEFAULT', 'zones_suspend_path')
4779N/A except ConfigParser.NoOptionError:
4779N/A suspend_path = default_path
4779N/A
4779N/A if not os.path.exists(suspend_path):
4779N/A if suspend_path == default_path:
4779N/A # get the root pool name
4779N/A cmd = ['/usr/sbin/zfs', 'list', '-Ho', 'name', '/']
4779N/A p = Popen(cmd, stdout=PIPE, stderr=PIPE)
4779N/A output, error = p.communicate()
4779N/A if p.returncode != 0:
4779N/A print "unable to determine root pool name: %s" % (error)
4779N/A return smf_include.SMF_EXIT_ERR_CONFIG
4779N/A rpool = output.split('/')[0]
4779N/A
4779N/A # the default directory doesn't exist, create a new dataset for it
5190N/A suspend_ds = os.path.join(rpool, 'VARSHARE/zones/SYSsuspend')
4779N/A try:
4779N/A check_call(['/usr/bin/pfexec', '/usr/sbin/zfs', 'create', '-p',
4779N/A '-o', 'mountpoint=' + suspend_path, suspend_ds])
4779N/A except CalledProcessError as err:
4779N/A print "unable to create %s: %s" % (suspend_ds, err)
4779N/A return smf_include.SMF_EXIT_ERR_CONFIG
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
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()