- host_list: list of hosts as retrieved from openstack (can be empty)
- az_host: either a host or a az:host string
- if a host, will check host is in the list, find the corresponding az and
- return az:host
- if az:host is passed will check the host is in the list and az matches
- if host_list is empty, will return the configured az if there is no
- az passed
- """
- if ':' in az_host:
- # no host_list, return as is (no check)
- if not host_list:
- return az_host
- # if there is a host_list, extract and verify the az and host
- az_host_list = az_host.split(':')
- zone = az_host_list[0]
- host = az_host_list[1]
- for hyp in host_list:
- if hyp.host == host:
- if hyp.zone == zone:
- # matches
- return az_host
- # else continue - another zone with same host name?
- # no match
- LOG.error('No match for availability zone and host %s', az_host)
- return None
- else:
- return self.auto_fill_az(host_list, az_host)
-
- #
- # Return a list of 0, 1 or 2 az:host
- #
- # The list is computed as follows:
- # The list of all hosts is retrieved first from openstack
- # if this fails, checks and az auto-fill are disabled
- #
- # If the user provides a configured az name (config.availability_zone)
- # up to the first 2 hosts from the list that match the az are returned
- #
- # If the user did not configure an az name
- # up to the first 2 hosts from the list are returned
- # Possible return values:
- # [ az ]
- # [ az:hyp ]
- # [ az1:hyp1, az2:hyp2 ]
- # [] if an error occurred (error message printed to console)
- #
- def get_enabled_az_host_list(self, required_count=1):
- """Check which hypervisors are enabled and on which compute nodes they are running.
-
- Pick up to the required count of hosts (can be less or zero)
-
- :param required_count: count of compute-nodes to return
- :return: list of enabled available compute nodes