def delete_computehost(self, host_id): host = db_api.host_get(host_id) if not host: raise manager_ex.HostNotFound(host=host_id) with trusts.create_ctx_from_trust(host['trust_id']): # TODO(sbauza): # - Check if no leases having this host scheduled inventory = nova_inventory.NovaInventory() servers = inventory.get_servers_per_host( host['hypervisor_hostname']) if servers: raise manager_ex.HostHavingServers( host=host['hypervisor_hostname'], servers=servers) try: pool = rp.ReservationPool() pool.remove_computehost(self.freepool_name, host['service_name']) # NOTE(sbauza): Extracapabilities will be destroyed thanks to # the DB FK. db_api.host_destroy(host_id) except db_ex.ClimateDBException: # Nothing so bad, but we need to advert the admin # he has to rerun raise manager_ex.CantRemoveHost(host=host_id, pool=self.freepool_name)
def get_host_details(self, host): """Get Nova capabilities of a single host :param host: UUID or name of nova-compute host :return: Dict of capabilities or raise HostNotFound """ try: hypervisor = self.nova.hypervisors.get(host) except nova_exceptions.NotFound: try: hypervisors_list = self.nova.hypervisors.search(host) except nova_exceptions.NotFound: raise manager_exceptions.HostNotFound(host=host) if len(hypervisors_list) > 1: raise manager_exceptions.MultipleHostsFound(host) else: hypervisor_id = hypervisors_list[0].id # NOTE(sbauza): No need to catch the exception as we're sure # that the hypervisor exists hypervisor = self.nova.hypervisors.get(hypervisor_id) try: return { 'id': hypervisor.id, 'hypervisor_hostname': hypervisor.hypervisor_hostname, 'service_name': hypervisor.service['host'], 'vcpus': hypervisor.vcpus, 'cpu_info': hypervisor.cpu_info, 'hypervisor_type': hypervisor.hypervisor_type, 'hypervisor_version': hypervisor.hypervisor_version, 'memory_mb': hypervisor.memory_mb, 'local_gb': hypervisor.local_gb } except AttributeError: raise manager_exceptions.InvalidHost(host=host)
def add_computehost(self, pool, host): """Add a compute host to an aggregate. The `host` must exist otherwise raise an error and the `host` must be in the freepool. :param pool: Name or UUID of the pool to rattach the host :param host: Name (not UUID) of the host to associate :type host: str Return the related aggregate. Raise an aggregate exception if something wrong. """ agg = self.get_aggregate_from_name_or_id(pool) try: freepool_agg = self.get(self.freepool_name) except manager_exceptions.AggregateNotFound: raise manager_exceptions.NoFreePool() if freepool_agg.id != agg.id: if host not in freepool_agg.hosts: raise manager_exceptions.HostNotInFreePool( host=host, freepool_name=freepool_agg.name) LOG.info("removing host '%s' " "from aggregate freepool %s" % (host, freepool_agg.name)) try: self.remove_computehost(freepool_agg.id, host) except nova_exceptions.NotFound: raise manager_exceptions.HostNotFound(host=host) LOG.info("adding host '%s' to aggregate %s" % (host, agg.id)) try: return self.nova.aggregates.add_host(agg.id, host) except nova_exceptions.NotFound: raise manager_exceptions.HostNotFound(host=host) except nova_exceptions.Conflict: raise manager_exceptions.AggregateAlreadyHasHost(pool=pool, host=host)
def get_servers_per_host(self, host): """List all servers of a nova-compute host :param host: Name (not UUID) of nova-compute host :return: Dict of servers or None """ try: hypervisors_list = self.nova.hypervisors.search(host, servers=True) except nova_exceptions.NotFound: raise manager_exceptions.HostNotFound(host=host) if len(hypervisors_list) > 1: raise manager_exceptions.MultipleHostsFound(host) else: try: return hypervisors_list[0].servers except AttributeError: # NOTE(sbauza): nova.hypervisors.search(servers=True) returns # a list of hosts without 'servers' attribute if no servers # are running on that host return None