예제 #1
0
// NextOp is defined on the Resolver interface.
func (s *storageResolver) NextOp(
	localState resolver.LocalState,
	remoteState remotestate.Snapshot,
	opFactory operation.Factory,
) (operation.Operation, error) {

	var changed []names.StorageTag
	for tag, storage := range remoteState.Storage {
		life, ok := s.life[tag]
		if !ok || life != storage.Life {
			s.life[tag] = storage.Life
			changed = append(changed, tag)
		}
	}
	for tag := range s.life {
		if _, ok := remoteState.Storage[tag]; !ok {
			changed = append(changed, tag)
			delete(s.life, tag)
		}
	}
	if len(changed) > 0 {
		return opFactory.NewUpdateStorage(changed)
	}
	if !localState.Installed && s.storage.Pending() == 0 {
		logger.Infof("initial storage attachments ready")
	}
	return s.nextOp(localState, remoteState, opFactory)
}