コード例 #1
0
    def delete(self, pool, force=True):
        """Delete an aggregate.

        pool can be an aggregate name or an aggregate id.
        Remove all hosts before delete aggregate (default).
        If force is False, raise exception if at least one
        host is attached to.

        """

        agg = self.get_aggregate_from_name_or_id(pool)

        hosts = agg.hosts
        if len(hosts) > 0 and not force:
            raise manager_exceptions.AggregateHaveHost(name=agg.name,
                                                       hosts=agg.hosts)
        try:
            freepool_agg = self.get(self.freepool_name)
        except manager_exceptions.AggregateNotFound:
            raise manager_exceptions.NoFreePool()
        for host in hosts:
            LOG.debug("Removing host '%s' from aggregate "
                      "'%s')" % (host, agg.id))
            self.nova.aggregates.remove_host(agg.id, host)

            if freepool_agg.id != agg.id:
                self.nova.aggregates.add_host(freepool_agg.id, host)

        self.nova.aggregates.delete(agg.id)
コード例 #2
0
    def remove_computehost(self, pool, hosts):
        """Remove compute host(s) from an aggregate."""

        if not isinstance(hosts, list):
            hosts = [hosts]

        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()

        hosts_failing_to_remove = []
        hosts_failing_to_add = []
        hosts_not_in_freepool = []
        for host in hosts:
            if freepool_agg.id == agg.id:
                if host not in freepool_agg.hosts:
                    hosts_not_in_freepool.append(host)
                    continue
            try:
                self.nova.aggregates.remove_host(agg.id, host)
            except nova_exceptions.ClientException:
                hosts_failing_to_remove.append(host)
            if freepool_agg.id != agg.id:
                # NOTE(sbauza) : We don't want to put again the host in
                # freepool if the requested pool is the freepool...
                try:
                    self.nova.aggregates.add_host(freepool_agg.id, host)
                except nova_exceptions.ClientException:
                    hosts_failing_to_add.append(host)

        if hosts_failing_to_remove:
            raise manager_exceptions.CantRemoveHost(
                host=hosts_failing_to_remove, pool=agg)
        if hosts_failing_to_add:
            raise manager_exceptions.CantAddHost(host=hosts_failing_to_add,
                                                 pool=freepool_agg)
        if hosts_not_in_freepool:
            raise manager_exceptions.HostNotInFreePool(
                host=hosts_not_in_freepool, freepool_name=freepool_agg.name)
コード例 #3
0
    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)