Skip to content
Snippets Groups Projects
Commit 86bdfecc authored by Luis Fernandez Alvarez's avatar Luis Fernandez Alvarez Committed by Luis Fernandez Alvarez
Browse files

Add cluster_by_service_host

parent b452a1c1
Branches
Tags
1 merge request!97[OS-18672] Add cluster_by_service_host
Pipeline #10563466 passed
......@@ -219,22 +219,7 @@ class LanDB(object):
# vm_cluster = None
if parent:
# We only want the hostname without .cern.ch
parent = parent.split('.')[0]
clusters = self.client.service.vmGetClusterMembership(parent)
# vmGetClusterMembership is returning an array
if not clusters or len(clusters) == 0:
vm_cluster = None
elif len(clusters) == 1:
vm_cluster = clusters[0]
else:
# For hosts that have multiple VMPools, we need to find
# the right one
for p in clusters:
c = self.client.service.vmClusterGetInfo(p)
if service_name in c.Services:
vm_cluster = p
break
vm_cluster = self.cluster_by_service_host(parent, service_name)
if not vm_cluster:
raise Exception("Cluster for Hypervisor not found in LanDB")
......@@ -571,6 +556,31 @@ class LanDB(object):
return self.client.service.vmClusterGetInfo(cluster)
def cluster_by_service_host(self, hostname: str, service_name: str):
"""Find cluster by service & hostname.
The function returns the LanDB cluster name associated with the
hostname. If more than one cluster is associated with the host,
service_name is used to filter the correct one.
"""
host = hostname.split('.')[0]
clusters = self.client.service.vmGetClusterMembership(host)
if not clusters or len(clusters) == 0:
return None
if len(clusters) == 1:
# We assume the only cluster contains the required service
return clusters[0]
# For hosts that have multiple VMPools, we need to find the right one
for c_name in clusters:
c_info = self.client.service.vmClusterGetInfo(c_name)
if service_name in c_info.Services:
return c_name
return None
def ipservice_register(
self, ipservice, parent,
location={'Floor': '0', 'Room': '0', 'Building': '0'},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment