'Determine if updates alter an aggregate\'s availability zone.
:param context: local context
:param metadata: Target metadata for updating aggregate
:param aggregate: Aggregate to update
:param hosts: Hosts to check. If None, aggregate.hosts is used
:type hosts: list
:action_name: Calling method for logging purposes'

def is_safe_to_update_az(self, context, metadata, aggregate, hosts=None, action_name=AGGREGATE_ACTION_ADD):

    if ('availability_zone' in metadata):
        if (not metadata['availability_zone']):
            msg = (_('Aggregate    %s    does    not    support    empty    named    availability    zone') % aggregate.name)
            self._raise_invalid_aggregate_exc(action_name, aggregate.id, msg)
        _hosts = (hosts or aggregate.hosts)
        host_aggregates = objects.AggregateList.get_by_metadata_key(context, 'availability_zone', hosts=_hosts)
        conflicting_azs = [agg.availability_zone for agg in host_aggregates if ((agg.availability_zone != metadata['availability_zone']) and (agg.id != aggregate.id))]
        if conflicting_azs:
            msg = (_('One    or    more    hosts    already    in    availability    zone(s)    %s') % conflicting_azs)
            self._raise_invalid_aggregate_exc(action_name, aggregate.id, msg)
