compass-core/compass/deployment/deploy_manager.py
Weidong Shao 37411ed68e Update deployment code to improve debugging
Add some logging for deploy celery task and chef_installer
environment update.

- Fix a bug in chef databag updating logic (missing .tmpl file
  extension in the file path)
- Temporarily comment out databag update due to template mis-config.
- Rename the OpenStack Icehouse flavor config values
  (to fix the mismatch of template names)

Change-Id: I856f7896156158f1c4f5a4cd654c8c93213a2879
2014-09-02 15:43:41 +00:00

192 lines
7.0 KiB
Python

# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.
__author__ = "Grace Yu (grace.yu@huawei.com)"
"""Module to get configs from provider and isntallers and update
them to provider and installers.
"""
from compass.deployment.installers.installer import OSInstaller
from compass.deployment.installers.installer import PKInstaller
from compass.deployment.utils import constants as const
from compass.utils import util
import logging
class DeployManager(object):
"""Deploy manager module."""
def __init__(self, adapter_info, cluster_info, hosts_info):
"""Init deploy manager."""
self.os_installer = None
self.pk_installer = None
# Get OS installer
os_installer_name = adapter_info[const.OS_INSTALLER][const.NAME]
os_hosts_info = self._get_hosts_for_os_installation(hosts_info)
self.os_installer = DeployManager._get_installer(OSInstaller,
os_installer_name,
adapter_info,
cluster_info,
os_hosts_info)
# Get package installer
pk_info = adapter_info.setdefault(const.PK_INSTALLER, {})
if pk_info:
pk_installer_name = pk_info[const.NAME]
self.pk_installer = DeployManager._get_installer(PKInstaller,
pk_installer_name,
adapter_info,
cluster_info,
hosts_info)
@staticmethod
def _get_installer(installer_type, name, adapter_info, cluster_info,
hosts_info):
"""Get installer instance."""
callback = getattr(installer_type, 'get_installer')
installer = callback(name, adapter_info, cluster_info, hosts_info)
return installer
def deploy(self):
"""Deploy the cluster."""
deployed_config = self.deploy_os()
package_deployed_config = self.deploy_target_system()
util.merge_dict(deployed_config, package_deployed_config)
return deployed_config
def clean_progress(self):
"""Clean previous installation log and progress."""
self.clean_os_installtion_progress()
self.clean_package_installation_progress()
def clean_os_installtion_progress(self):
# OS installer cleans previous installing progress.
if self.os_installer:
self.os_installer.clean_progress()
def clean_package_installation_progress(self):
# Package installer cleans previous installing progress.
if self.pk_installer:
self.pk_installer.clean_progress()
def prepare_for_deploy(self):
self.clean_progress()
def deploy_os(self):
"""Deploy OS to hosts which need to in the cluster. Return OS deployed
config.
"""
if not self.os_installer:
return {}
pk_installer_config = {}
if self.pk_installer:
# generate target system config which will be installed by OS
# installer right after OS installation is completed.
pk_installer_config = self.pk_installer.generate_installer_config()
logging.debug('[DeployManager]package installer config is %s',
pk_installer_config)
# Send package installer config info to OS installer.
self.os_installer.set_package_installer_config(pk_installer_config)
# start to deploy OS
return self.os_installer.deploy()
def deploy_target_system(self):
"""Deploy target system to all hosts in the cluster. Return package
deployed config.
"""
if not self.pk_installer:
return {}
return self.pk_installer.deploy()
def redeploy_os(self):
"""Redeploy OS for this cluster without changing configurations."""
if not self.os_installer:
logging.info("Redeploy_os: No OS installer found!")
return
self.os_installer.redeploy()
logging.info("Start to redeploy OS for cluster.")
def redeploy_target_system(self):
"""Redeploy target system for the cluster without changing config."""
if not self.pk_installer:
logging.info("Redeploy_target_system: No installer found!")
self.os_installer.redeploy()
logging.info("Start to redeploy target system.")
def redeploy(self):
"""Redeploy the cluster without changing configurations."""
self.redeploy_os()
self.redeploy_target_system()
def remove_hosts(self, package_only=False):
"""Remove hosts from both OS and/or package installlers server side."""
if self.os_installer and not package_only:
self.os_installer.delete_hosts()
if self.pk_installer:
self.pk_installer.delete_hosts()
def _get_hosts_for_os_installation(self, hosts_info):
"""Get info of hosts which need to install/reinstall OS."""
hosts_list = {}
for host_id in hosts_info:
reinstall_os_flag = hosts_info[host_id][const.REINSTALL_OS_FLAG]
if not reinstall_os_flag:
continue
hosts_list[host_id] = hosts_info[host_id]
return hosts_list
class PowerManager(object):
"""Manage host to power on, power off, and reset."""
def __init__(self, adapter_info, cluster_info, hosts_info):
os_installer_name = adapter_info[const.OS_INSTALLER][const.NAME]
self.os_installer = DeployManager._get_installer(OSInstaller,
os_installer_name,
adapter_info,
cluster_info,
hosts_info)
def poweron(self):
if not self.os_installer:
logging.info("No OS installer found, cannot power on machine!")
return
self.os_installer.poweron()
def poweroff(self):
if not self.os_installer:
logging.info("No OS installer found, cannot power on machine!")
return
self.os_installer.poweroff()
def reset(self):
if not self.os_installer:
logging.info("No OS installer found, cannot power on machine!")
return
self.os_installer.reset()