Example #1
0
func wrapSnapshotAction(config *config.TopLevelConfig, action func(config *config.TopLevelConfig, pool, volName string, volume *config.TenantConfig)) {
	pools, err := config.ListPools()
	if err != nil {
		panic(fmt.Sprintf("Runtime configuration incorrect: %v", err))
	}

	for _, pool := range pools {
		volumes, err := config.ListVolumes(pool)
		if err != nil {
			panic(fmt.Sprintf("Runtime configuration incorrect: %v", err))
		}

		for volName, volume := range volumes {
			if volume.Pool != pool {
				panic(fmt.Sprintf("Volume pool prefix %q is not the same as JSON imported %q", volume.Pool, pool))
			}

			duration, err := time.ParseDuration(volume.Snapshot.Frequency)
			if err != nil {
				panic(fmt.Sprintf("Runtime configuration incorrect; cannot use %q as a snapshot frequency", volume.Snapshot.Frequency))
			}

			if volume.UseSnapshots && time.Now().Unix()%int64(duration.Seconds()) == 0 {
				go action(config, pool, volName, volume)
			}
		}
	}
}