171 lines
6.1 KiB
Python
Raw Normal View History

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.
from devstack import component as comp
from devstack import log as logging
from devstack import settings
from devstack import utils
from devstack import shell as sh
from devstack.components import db
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'
TYPE = settings.NOVA
2012-01-11 12:47:33 -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%']}
]
# 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-11 12:47:33 -08:00
class NovaUninstaller(comp.PythonUninstallComponent):
2012-01-11 12:47:33 -08:00
def __init__(self, *args, **kargs):
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
class NovaInstaller(comp.PythonInstallComponent):
2012-01-11 12:47:33 -08:00
def __init__(self, *args, **kargs):
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")
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
2012-01-19 14:04:37 -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
# 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
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places.append({
2012-01-20 17:00:23 -08:00
'uri': self.git_repo,
'branch': self.git_branch,
})
return places
2012-01-20 17:11:50 -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))
#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
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):
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
conf_gen = nc.NovaConfigurator(self.cfg, self.instances)
2012-01-20 17:00:23 -08:00
nova_conf = conf_gen.configure(dirs)
tgtfn = self.get_target_config_name(API_CONF)
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
return 1
2012-01-20 17:00:23 -08:00
def _configure_files(self):
return self._generate_nova_conf()
class NovaRuntime(comp.PythonRuntime):
2012-01-11 12:47:33 -08:00
def __init__(self, *args, **kargs):
comp.PythonRuntime.__init__(self, TYPE, *args, **kargs)
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)