From f89ef9a9ee968c778af3444c7f9d2a39489fcf2b Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Thu, 11 Oct 2018 11:05:02 +0800 Subject: Manage host power from cobbler JIRA: COMPASS-616 1. Use fence_ipmilan to control power of baremetal servers. Add fence_libvirt to control power of virtual servers. 2. Use power_manage field instead of ipmi field 3. Add power_type to specify machine's power manage tool 4. Store power manage information in db and update to cobbler 5. Manage power from cobbler for both virtual and baremetal machines Change-Id: Ic36ae640dc0aa1703566b5b0b549880a71be36e4 Signed-off-by: Harry Huang --- compass-tasks-base/deployment/deploy_manager.py | 29 +++++++++++++++++++++- .../deployment/installers/config_manager.py | 22 ++++++++-------- .../installers/os_installers/cobbler/cobbler.py | 28 ++++++++++----------- compass-tasks-base/deployment/utils/constants.py | 4 +-- 4 files changed, 56 insertions(+), 27 deletions(-) (limited to 'compass-tasks-base/deployment') diff --git a/compass-tasks-base/deployment/deploy_manager.py b/compass-tasks-base/deployment/deploy_manager.py index baf7cd6..225c31e 100644 --- a/compass-tasks-base/deployment/deploy_manager.py +++ b/compass-tasks-base/deployment/deploy_manager.py @@ -111,7 +111,34 @@ class DeployManager(object): self.os_installer.set_package_installer_config(pk_installer_config) # start to deploy OS - return self.os_installer.deploy() + result = self.os_installer.deploy() + self.reset_server() + + return result + + def poweron_server(self): + if not self.os_installer: + return + + host_id_list = self.os_installer.config_manager.get_host_id_list() + for host_id in host_id_list: + self.os_installer.poweron(host_id) + + def poweroff_server(self): + if not self.os_installer: + return + + host_id_list = self.os_installer.config_manager.get_host_id_list() + for host_id in host_id_list: + self.os_installer.poweroff(host_id) + + def reset_server(self): + if not self.os_installer: + return + + host_id_list = self.os_installer.config_manager.get_host_id_list() + for host_id in host_id_list: + self.os_installer.reset(host_id) def deploy_target_system(self): """Deploy target system to all hosts in the cluster. diff --git a/compass-tasks-base/deployment/installers/config_manager.py b/compass-tasks-base/deployment/installers/config_manager.py index d3b28e0..ebee727 100644 --- a/compass-tasks-base/deployment/installers/config_manager.py +++ b/compass-tasks-base/deployment/installers/config_manager.py @@ -169,8 +169,8 @@ class HostInfo(object): self.package_config = self.host_info.setdefault(const.PK_CONFIG, {}) self.roles = self.host_info.setdefault(const.ROLES, []) self.patched_roles = self.host_info.setdefault(const.PATCHED_ROLES, []) - self.ipmi = deepcopy(self.host_info.setdefault(const.IPMI, {})) - self.ipmi_credentials = deepcopy(self.host_info.setdefault(const.IPMI_CREDS, {})) + self.power_type = deepcopy(self.host_info.setdefault(const.POWER_TYPE, {})) + self.power_manage = deepcopy(self.host_info.setdefault(const.POWER_MANAGE, {})) self.reinstall_os_flag = self.host_info.get(const.REINSTALL_OS_FLAG) self.deployed_os_config = self.host_info.setdefault( const.DEPLOYED_OS_CONFIG, {} @@ -276,7 +276,8 @@ class HostInfo(object): def baseinfo(self): return { const.REINSTALL_OS_FLAG: self.reinstall_os_flag, - const.IPMI_CREDS: self.ipmi_credentials, + const.POWER_TYPE: self.power_type, + const.POWER_MANAGE: self.power_manage, const.MAC_ADDR: self.mac, const.NAME: self.name, const.HOSTNAME: self.hostname, @@ -516,14 +517,15 @@ class BaseConfigManager(object): self.validate_host(host_id) return self.hosts_info[host_id].roles_mapping - def get_host_ipmi_info(self, host_id): + def get_host_power_info(self, host_id): self.validate_host(host_id) - if self.hosts_info[host_id].ipmi: + if self.hosts_info[host_id].power_manage: return ( - self.hosts_info[host_id].ipmi[const.IP_ADDR], - self.hosts_info[host_id].ipmi - [const.IPMI_CREDS][const.USERNAME], - self.hosts_info[host_id].ipmi - [const.IPMI_CREDS][const.USERNAME]) + self.hosts_info[host_id].power_manage + [const.IP_ADDR], + self.hosts_info[host_id].power_manage + [const.USERNAME], + self.hosts_info[host_id].power_manage + [const.PASSWORD]) else: return (None, None, None) diff --git a/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py b/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py index 9c2a935..aa74f68 100644 --- a/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py +++ b/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py @@ -397,25 +397,25 @@ class CobblerInstaller(OSInstaller): return cluster_vas_dict - def _check_and_set_system_impi(self, host_id, sys_id): + def _check_and_set_system_power(self, host_id, sys_id): if not sys_id: logging.info("System is None!") return False system = self.dump_system_info(host_id) - if system[self.POWER_TYPE] != 'ipmilan' or not system[self.POWER_USER]: + if not system.get(self.POWER_TYPE): # Set sytem power type to ipmilan if needs and set IPMI info - ipmi_info = self.config_manager.get_host_ipmi_info(host_id) - if not ipmi_info: + power_info = self.config_manager.get_host_power_info(host_id) + if not power_info: logging.info('No IPMI information found! Failed power on.') return False - ipmi_ip, ipmi_user, ipmi_pass = ipmi_info + ip, username, password = power_info power_opts = {} power_opts[self.POWER_TYPE] = 'ipmilan' - power_opts[self.POWER_ADDR] = ipmi_ip - power_opts[self.POWER_USER] = ipmi_user - power_opts[self.POWER_PASS] = ipmi_pass + power_opts[self.POWER_ADDR] = ip + power_opts[self.POWER_USER] = username + power_opts[self.POWER_PASS] = password self._update_system_config(sys_id, power_opts) @@ -424,26 +424,26 @@ class CobblerInstaller(OSInstaller): def poweron(self, host_id): hostname = self.config_manager.get_hostname(host_id) sys_id = self._get_create_system(hostname) - if not self._check_and_set_system_impi(sys_id): + if not self._check_and_set_system_power(host_id, sys_id): return - self.remote.power_system(sys_id, self.token, power='on') + self.remote.power_system(sys_id, 'on', self.token) logging.info("Host with ID=%d starts to power on!" % host_id) def poweroff(self, host_id): hostname = self.config_manager.get_hostname(host_id) sys_id = self._get_create_system(hostname) - if not self._check_and_set_system_impi(sys_id): + if not self._check_and_set_system_power(host_id, sys_id): return - self.remote.power_system(sys_id, self.token, power='off') + self.remote.power_system(sys_id, 'off', self.token) logging.info("Host with ID=%d starts to power off!" % host_id) def reset(self, host_id): hostname = self.config_manager.get_hostname(host_id) sys_id = self._get_create_system(hostname) - if not self._check_and_set_system_impi(sys_id): + if not self._check_and_set_system_power(host_id, sys_id): return - self.remote.power_system(sys_id, self.token, power='reboot') + self.remote.power_system(sys_id, 'reboot', self.token) logging.info("Host with ID=%d starts to reboot!" % host_id) diff --git a/compass-tasks-base/deployment/utils/constants.py b/compass-tasks-base/deployment/utils/constants.py index e90b1b2..18ee56a 100644 --- a/compass-tasks-base/deployment/utils/constants.py +++ b/compass-tasks-base/deployment/utils/constants.py @@ -54,8 +54,8 @@ DOMAIN = 'domain' HOST_ID = 'host_id' HOSTNAME = 'hostname' IP_ADDR = 'ip' -IPMI = 'ipmi' -IPMI_CREDS = 'ipmi_credentials' +POWER_TYPE = 'power_type' +POWER_MANAGE = 'power_manage' MAC_ADDR = 'mac' MGMT_NIC_FLAG = 'is_mgmt' NETMASK = 'netmask' -- cgit 1.2.3-korg