diff --git a/sysinv/sysinv/sysinv/sysinv/common/constants.py b/sysinv/sysinv/sysinv/sysinv/common/constants.py index 7263974325..40e2aa2e2a 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/constants.py +++ b/sysinv/sysinv/sysinv/sysinv/common/constants.py @@ -1468,3 +1468,9 @@ CLOCK_SYNCHRONIZATION = [ NTP, PTP ] + +# ceph-mon IP placeholders (keys) +CEPH_MON_0 = 'ceph-mon-0-ip' +CEPH_MON_1 = 'ceph-mon-1-ip' +CEPH_MON_2 = 'ceph-mon-2-ip' +CEPH_FLOATING_MON = 'ceph-floating-mon-ip' diff --git a/sysinv/sysinv/sysinv/sysinv/common/storage_backend_conf.py b/sysinv/sysinv/sysinv/sysinv/common/storage_backend_conf.py index d5bf45e212..b30f184d1d 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/storage_backend_conf.py +++ b/sysinv/sysinv/sysinv/sysinv/common/storage_backend_conf.py @@ -197,38 +197,29 @@ class StorageBackendConfig(object): @staticmethod def get_ceph_mon_ip_addresses(dbapi): - network_type = constants.NETWORK_TYPE_MGMT - floating_network_name = constants.CONTROLLER_HOSTNAME - - targets = { - '%s-%s' % (floating_network_name, - network_type): 'ceph-floating-mon-ip', - '%s-%s' % (constants.CONTROLLER_0_HOSTNAME, - network_type): 'ceph-mon-0-ip', - '%s-%s' % (constants.CONTROLLER_1_HOSTNAME, - network_type): 'ceph-mon-1-ip', + # map hostname to ceph-mon ip placeholder + host2ph = { + constants.CONTROLLER_HOSTNAME: constants.CEPH_FLOATING_MON, + constants.CONTROLLER_0_HOSTNAME: constants.CEPH_MON_0, + constants.CONTROLLER_1_HOSTNAME: constants.CEPH_MON_1, } - - ceph_mons = dbapi.ceph_mon_get_list() - ceph_mon = None - for ceph_mon in ceph_mons: - if ceph_mon['hostname'] == constants.CONTROLLER_0_HOSTNAME: - targets.update({'%s-%s' % (constants.CONTROLLER_0_HOSTNAME, - network_type): 'ceph-mon-0-ip'}) - elif ceph_mon['hostname'] == constants.CONTROLLER_1_HOSTNAME: - targets.update({'%s-%s' % (constants.CONTROLLER_1_HOSTNAME, - network_type): 'ceph-mon-1-ip'}) - else: - targets.update({'%s-%s' % (ceph_mon['hostname'], - network_type): 'ceph-mon-2-ip'}) - - results = {} - addrs = dbapi.addresses_get_all() - for addr in addrs: - if addr.name in targets: - results[targets[addr.name]] = addr.address - - return results + # find 3rd ceph-mon host name (if any) + for mon in dbapi.ceph_mon_get_list(): + host = mon['hostname'] + if host not in host2ph: + host2ph[host] = constants.CEPH_MON_2 + # map host interface to ceph-mon ip placeholder + hostif2ph = {} + for host, ph in host2ph.items(): + hostif = '%s-%s' % (host, constants.NETWORK_TYPE_MGMT) + hostif2ph[hostif] = ph + # map placeholder to ceph-mon ip address + ph2ipaddr = {} + for addr in dbapi.addresses_get_all(): + if addr.name in hostif2ph: + ph = hostif2ph[addr.name] + ph2ipaddr[ph] = addr.address + return ph2ipaddr @staticmethod def is_ceph_backend_ready(api): diff --git a/sysinv/sysinv/sysinv/sysinv/helm/base.py b/sysinv/sysinv/sysinv/sysinv/helm/base.py index c220982829..87fc52d1e2 100644 --- a/sysinv/sysinv/sysinv/sysinv/helm/base.py +++ b/sysinv/sysinv/sysinv/sysinv/helm/base.py @@ -157,17 +157,23 @@ class BaseHelm(object): def _system_mode(self): return self.dbapi.isystem_get_one().system_mode - def _get_ceph_monitor_ips(self): + def _get_ceph_monitor_ips(self, name_filter=None): if self._system_mode() == constants.SYSTEM_MODE_SIMPLEX: monitors = [self._get_controller_0_management_address()] + elif name_filter: + monitors = [] + for name, addr in StorageBackendConfig.get_ceph_mon_ip_addresses( + self.dbapi).items(): + if name_filter(name): + monitors.append(addr) else: monitors = StorageBackendConfig.get_ceph_mon_ip_addresses( self.dbapi).values() return monitors - def _get_formatted_ceph_monitor_ips(self): + def _get_formatted_ceph_monitor_ips(self, name_filter=None): port = self.CEPH_MON_SERVICE_PORT - monitor_ips = self._get_ceph_monitor_ips() + monitor_ips = self._get_ceph_monitor_ips(name_filter) formatted_monitor_ips = [ utils.format_ceph_mon_address(mon, port) for mon in monitor_ips ] diff --git a/sysinv/sysinv/sysinv/sysinv/helm/rbd_provisioner.py b/sysinv/sysinv/sysinv/sysinv/helm/rbd_provisioner.py index c0905e8a4b..9d4bd9b956 100644 --- a/sysinv/sysinv/sysinv/sysinv/helm/rbd_provisioner.py +++ b/sysinv/sysinv/sysinv/sysinv/helm/rbd_provisioner.py @@ -46,8 +46,12 @@ class RbdProvisionerHelm(base.BaseHelm): if not ceph_bks: return {} # ceph is not configured + def _skip_ceph_mon_2(name): + return name != constants.CEPH_MON_2 + classdefaults = { - "monitors": self._get_formatted_ceph_monitor_ips(), + "monitors": self._get_formatted_ceph_monitor_ips( + name_filter=_skip_ceph_mon_2), "adminId": constants.K8S_RBD_PROV_USER_NAME, "adminSecretName": constants.K8S_RBD_PROV_ADMIN_SECRET_NAME } diff --git a/sysinv/sysinv/sysinv/sysinv/puppet/ceph.py b/sysinv/sysinv/sysinv/sysinv/puppet/ceph.py index 77aca591cd..fbb065f003 100644 --- a/sysinv/sysinv/sysinv/sysinv/puppet/ceph.py +++ b/sysinv/sysinv/sysinv/sysinv/puppet/ceph.py @@ -67,10 +67,10 @@ class CephPuppet(openstack.OpenstackBasePuppet): else: mon_2_host = None - mon_0_ip = ceph_mon_ips['ceph-mon-0-ip'] - mon_1_ip = ceph_mon_ips['ceph-mon-1-ip'] - mon_2_ip = ceph_mon_ips.get('ceph-mon-2-ip', None) - floating_mon_ip = ceph_mon_ips['ceph-floating-mon-ip'] + mon_0_ip = ceph_mon_ips[constants.CEPH_MON_0] + mon_1_ip = ceph_mon_ips[constants.CEPH_MON_1] + mon_2_ip = ceph_mon_ips.get(constants.CEPH_MON_2, None) + floating_mon_ip = ceph_mon_ips[constants.CEPH_FLOATING_MON] mon_0_addr = self._format_ceph_mon_address(mon_0_ip) mon_1_addr = self._format_ceph_mon_address(mon_1_ip)