var/opt/nydus/ops/customer_local_ops/control_panel/ispconfig.py000064400000006172147205660400021201 0ustar00# -*- coding: utf-8 -*- from typing import Dict, Any, Tuple import logging from customer_local_ops import Ops, OpType LOG = logging.getLogger(__name__) class OSISPConfig: """Mixin class representing common functionality and constants for ISPConfig between all OSes""" class ISPConfig(Ops): op_type = OpType.CONTROL_PANEL os_op_instance = None def change_hostname(self, payload: Dict[str, Any], *args: Any) -> Any: """Changes the server hostname via an op for the local operating system and an op for ispconfig :param payload: A dict containing input data """ LOG.info("ISPConfig.change_hostname start") os_op = payload["os_op"] op_name = 'change_hostname' if self.os_op_instance is None: self.os_op_instance = self.get_os_op(os_op) LOG.info("ISPConfig.change_hostname deferring to OS operation: %s.%s", str( os_op), op_name) success, os_result = self._change_os_hostname(payload) if not success: return self.build_result_from_other_result((success, os_result), op_name) LOG.info("Change the hostname in ISPConfig.") self.os_op_instance.change_ispconfig_hostname(payload) return True, self.build_result_dict('hostname changed successfully', '', op_name) def _change_os_hostname(self, payload: Dict[str, Any]) -> Tuple[bool, Any]: """Changes the server hostname via an op for the local operating system :param payload: A dict containing input data """ os_result = self.os_op_instance.change_hostname(payload) data = self.get_result_data(os_result) LOG.info("ISPConfig.change_hostname os_op_result - %s - %s - %s", data.success, data.outs, data.errs) return data.as_tuple() def change_password(self, payload: Dict[str, Any], *args: Any) -> Any: """Changes the user password via an op for the local operating system and an op for ispconfig :param payload: A dict containing input data """ LOG.info("ISPConfig.change_password start") os_op = payload["os_op"] op_name = 'change_password' LOG.info("ISPConfig.change_password deferring to OS operation: %s.%s", str( os_op), op_name) if self.os_op_instance is None: self.os_op_instance = self.get_os_op(os_op) success, os_result = self._change_os_password(payload) if not success: return self.build_result_from_other_result((success, os_result), op_name) self.os_op_instance.change_ispconfig_password(payload, op_name) return True, self.build_result_dict('password changed successfully', '', op_name) def _change_os_password(self, payload: Dict[str, Any]) -> Tuple[bool, Any]: """Changes the user password via an op for the local operating system :param payload: A dict containing input data """ os_result = self.os_op_instance.change_password(payload) data = self.get_result_data(os_result) LOG.info("ISPConfig.change_password os_op_result - %s - %s - %s", data.success, data.outs, data.errs) return data.as_tuple()