2012-01-11 12:47:33 -08:00
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
from devstack import component as comp
|
|
|
|
from devstack import log as logging
|
2012-01-22 16:09:47 -08:00
|
|
|
from devstack import settings
|
2012-01-23 14:45:09 -08:00
|
|
|
from devstack import utils
|
2012-01-20 14:12:20 -08:00
|
|
|
from devstack import shell as sh
|
2012-01-23 14:45:09 -08:00
|
|
|
from devstack.components import db
|
2012-01-20 14:12:20 -08:00
|
|
|
from devstack.components import nova_conf as nc
|
|
|
|
|
|
|
|
LOG = logging.getLogger("devstack.components.nova")
|
2012-01-20 17:00:23 -08:00
|
|
|
|
2012-01-19 14:04:37 -08:00
|
|
|
API_CONF = "nova.conf"
|
2012-01-20 17:00:23 -08:00
|
|
|
PASTE_CONF = 'nova-api-paste.ini'
|
2012-01-19 14:04:37 -08:00
|
|
|
CONFIGS = [API_CONF]
|
2012-01-20 17:00:23 -08:00
|
|
|
|
2012-01-19 14:04:37 -08:00
|
|
|
DB_NAME = "nova"
|
2012-01-20 17:00:23 -08:00
|
|
|
BIN_DIR = 'bin'
|
2012-01-22 16:09:47 -08:00
|
|
|
TYPE = settings.NOVA
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-23 14:45:09 -08:00
|
|
|
#what to start
|
|
|
|
APP_OPTIONS = {
|
|
|
|
'nova-api': [],
|
|
|
|
settings.NCPU: [],
|
|
|
|
settings.NVOL: [],
|
|
|
|
'nova-network': [],
|
|
|
|
'nova-scheduler': []
|
|
|
|
}
|
|
|
|
|
2012-01-24 10:16:51 -08:00
|
|
|
POST_INSTALL_CMDS = [
|
|
|
|
{'cmd' : ['%APPDIR%/bin/nova-manage', '--flagfile',
|
|
|
|
'%APPDIR%/config/nova.conf', 'db', 'sync']},
|
|
|
|
{'cmd' : ['%APPDIR%/bin/nova-manage', '--flagfile',
|
|
|
|
'%APPDIR%/config/nova.conf', 'floating', 'create',
|
|
|
|
'%FLOATING_RANGE%']},
|
|
|
|
{'cmd' : ['%APPDIR%/bin/nova-manage', '--flagfile',
|
|
|
|
'%APPDIR%/config/nova.conf', 'floating', 'create',
|
|
|
|
'--ip_range=%TEST_FLOATING_RANGE%',
|
|
|
|
'-pool=%TEST_FLOATING_POOL%']}
|
|
|
|
]
|
|
|
|
|
2012-01-23 14:45:09 -08:00
|
|
|
# In case we need to map names to the image to run
|
|
|
|
APP_NAME_MAP = {
|
|
|
|
settings.NCPU: 'nova-compute',
|
|
|
|
settings.NVOL: 'nova-volume',
|
|
|
|
}
|
|
|
|
CONFIG_ACTUAL_DIR = 'etc'
|
|
|
|
BIN_DIR = 'bin'
|
|
|
|
# FIXME, need base bin dir
|
2012-01-24 10:16:51 -08:00
|
|
|
# Look at keystone to see how it do what it do
|
2012-01-23 14:45:09 -08:00
|
|
|
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
class NovaUninstaller(comp.PythonUninstallComponent):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-20 14:12:20 -08:00
|
|
|
comp.PythonUninstallComponent.__init__(self, TYPE, *args, **kargs)
|
2012-01-19 14:04:37 -08:00
|
|
|
#self.cfgdir = joinpths(self.appdir, CONFIG_ACTUAL_DIR)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-20 17:11:50 -08:00
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
class NovaInstaller(comp.PythonInstallComponent):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-20 14:12:20 -08:00
|
|
|
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
|
2012-01-20 17:00:23 -08:00
|
|
|
self.git_repo = self.cfg.get("git", "nova_repo")
|
|
|
|
self.git_branch = self.cfg.get("git", "nova_branch")
|
2012-01-20 19:05:13 -08:00
|
|
|
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
2012-01-19 14:04:37 -08:00
|
|
|
|
2012-01-23 14:45:09 -08:00
|
|
|
def get_pkglist(self):
|
|
|
|
pkgs = comp.PkgInstallComponent.get_pkglist(self)
|
|
|
|
LOG.debug("pkg list from parent: %s" % (pkgs))
|
|
|
|
# Walk through the subcomponents (like 'vol' and 'cpu') and add those
|
2012-01-24 10:16:51 -08:00
|
|
|
# those packages as well. (Let utils.get_pkglist handle any missing
|
2012-01-23 14:45:09 -08:00
|
|
|
# entries
|
|
|
|
LOG.debug("get_pkglist looking for extras: %s" % (self.component_opts))
|
|
|
|
for cname in self.component_opts:
|
|
|
|
pkgs.update(utils.get_pkg_list(self.distro, cname))
|
|
|
|
return pkgs
|
|
|
|
|
2012-01-20 19:05:13 -08:00
|
|
|
def _get_download_locations(self):
|
2012-01-20 14:12:20 -08:00
|
|
|
places = comp.PythonInstallComponent._get_download_locations(self)
|
2012-01-19 17:47:16 -08:00
|
|
|
places.append({
|
2012-01-20 17:00:23 -08:00
|
|
|
'uri': self.git_repo,
|
|
|
|
'branch': self.git_branch,
|
2012-01-19 17:47:16 -08:00
|
|
|
})
|
|
|
|
return places
|
2012-01-20 17:11:50 -08:00
|
|
|
|
2012-01-23 14:45:09 -08:00
|
|
|
def post_install(self):
|
|
|
|
parent_result = comp.PkgInstallComponent.post_install(self)
|
2012-01-24 10:16:51 -08:00
|
|
|
LOG.debug("Parent post_install results:%s" % (parent_result))
|
2012-01-23 14:45:09 -08:00
|
|
|
#extra actions to do nova setup
|
|
|
|
self._setup_db()
|
2012-01-24 10:16:51 -08:00
|
|
|
# Need to do db sync and other post install commands
|
|
|
|
# set up replacement map for APPDIR, FLOATING_RANGE,
|
|
|
|
# TEST_FLOATING_RANGE, TEST_FLOATING_POOL
|
|
|
|
mp = dict()
|
|
|
|
mp['APPDIR'] = self.appdir
|
|
|
|
mp['FLOATING_RANGE'] = self.cfg.get('nova', 'floating_range')
|
|
|
|
mp['TEST_FLOATING_RANGE'] = self.cfg.get('nova', 'test_floating_range')
|
|
|
|
mp['TEST_FLOATING_POOL'] = self.cfg.get('nova', 'test_floating_pool')
|
|
|
|
results = utils.execute_template(*POST_INSTALL_CMDS, params=mp)
|
|
|
|
LOG.debug("Post install command results:%s" % (results))
|
|
|
|
return results
|
2012-01-23 14:45:09 -08:00
|
|
|
|
|
|
|
def _setup_db(self):
|
|
|
|
LOG.debug("setting up nova DB")
|
|
|
|
db.drop_db(self.cfg, DB_NAME)
|
|
|
|
db.create_db(self.cfg, DB_NAME)
|
|
|
|
|
2012-01-20 17:00:23 -08:00
|
|
|
def _generate_nova_conf(self):
|
2012-01-20 19:05:13 -08:00
|
|
|
LOG.debug("Generating dynamic content for nova configuration")
|
2012-01-20 17:00:23 -08:00
|
|
|
dirs = dict()
|
|
|
|
dirs['app'] = self.appdir
|
|
|
|
dirs['cfg'] = self.cfgdir
|
|
|
|
dirs['bin'] = self.bindir
|
2012-01-23 22:05:53 -08:00
|
|
|
conf_gen = nc.NovaConfigurator(self.cfg, self.instances)
|
2012-01-20 17:00:23 -08:00
|
|
|
nova_conf = conf_gen.configure(dirs)
|
2012-01-23 22:05:53 -08:00
|
|
|
tgtfn = self.get_target_config_name(API_CONF)
|
2012-01-20 19:05:13 -08:00
|
|
|
LOG.info("Created nova configuration:")
|
|
|
|
LOG.info(nova_conf)
|
|
|
|
LOG.debug("Placing it in %s" % (tgtfn))
|
2012-01-20 17:00:23 -08:00
|
|
|
sh.write_file(tgtfn, nova_conf)
|
2012-01-20 17:11:50 -08:00
|
|
|
#we configured one file, return that we did that
|
2012-01-19 17:47:16 -08:00
|
|
|
return 1
|
|
|
|
|
2012-01-20 17:00:23 -08:00
|
|
|
def _configure_files(self):
|
|
|
|
return self._generate_nova_conf()
|
|
|
|
|
2012-01-19 17:47:16 -08:00
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
class NovaRuntime(comp.PythonRuntime):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-20 14:12:20 -08:00
|
|
|
comp.PythonRuntime.__init__(self, TYPE, *args, **kargs)
|
2012-01-23 14:45:09 -08:00
|
|
|
|
|
|
|
def _get_aps_to_start(self):
|
|
|
|
# Check if component_opts was set to a subset of apps to be started
|
|
|
|
apps = list()
|
|
|
|
if (not self.component_opts and len(self.component_opts) > 0):
|
|
|
|
LOG.debug("Attempt to use subset of components:%s" % (self.component_opts))
|
|
|
|
# check if the specified sub components exist
|
|
|
|
delta = set(self.component_opts) - set(APP_OPTIONS.keys())
|
|
|
|
if (delta):
|
|
|
|
# FIXME, error, something was specified that we don't have
|
|
|
|
LOG.error("sub items that we don't know about:%s" % delta)
|
|
|
|
else:
|
|
|
|
apps = self.component_opts
|
|
|
|
else:
|
|
|
|
apps = APP_OPTIONS.keys()
|
|
|
|
|
|
|
|
result = list()
|
|
|
|
for app_name in apps:
|
|
|
|
if (app_name in APP_NAME_MAP):
|
|
|
|
app_name = APP_NAME_MAP.get(app_name)
|
|
|
|
list.append({
|
|
|
|
'name': app_name,
|
|
|
|
'path': sh.joinpths(self.appdir, BIN_DIR, app_name),
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _get_app_options(self, app):
|
|
|
|
return APP_OPTIONS.get(app)
|