func (n *assigner) getJobStaticIpsToReuse(previousInput bftinput.Input, jobName string, networkName string) []string { staticIps := []string{} previousJob, found := previousInput.FindJobByName(jobName) if !found { return staticIps } for _, jobNetwork := range previousJob.Networks { if jobNetwork.Name == networkName { for _, ip := range jobNetwork.StaticIps { staticIps = append(staticIps, ip) } } } if len(staticIps) == 0 { return staticIps } shuffledStaticIPsIdsx := rand.Perm(len(staticIps)) ipsToReuse := rand.Intn(len(staticIps)) shuffledStaticIps := []string{} for i := 0; i < ipsToReuse; i++ { shuffledStaticIps = append(shuffledStaticIps, staticIps[shuffledStaticIPsIdsx[i]]) } return shuffledStaticIps }
func (s *stemcellComparator) jobStemcellChanged(job bftinput.Job, currentInput bftinput.Input, mostRecentInput bftinput.Input) bool { prevJob, found := mostRecentInput.FindJobByName(job.Name) if !found { return false } var currentStemcell bftinput.StemcellConfig if job.Stemcell != "" { currentStemcell = s.findStemcellByAlias(job.Stemcell, currentInput) } else { currentStemcell = s.findResourcePoolStemcell(job.ResourcePool, currentInput) } if prevJob.Stemcell != "" { prevStemcell := s.findStemcellByAlias(prevJob.Stemcell, mostRecentInput) if prevStemcell.Version != currentStemcell.Version { s.logger.Debug("stemcell_comparator", "Stemcell versions don't match. Previous input: %#v, new input: %#v", mostRecentInput, currentInput) return true } } else { prevStemcell := s.findResourcePoolStemcell(prevJob.ResourcePool, mostRecentInput) if prevStemcell.Version != currentStemcell.Version { s.logger.Debug("stemcell_comparator", "Stemcell versions don't match. Previous input: %#v, new input: %#v", mostRecentInput, currentInput) return true } } return false }
func (f *fixedMigratedFrom) Apply(input bftinput.Input, previousInput bftinput.Input) bftinput.Input { for foundJobIdx, job := range input.Jobs { previousJob, found := previousInput.FindJobByName(job.Name) if found { if len(previousJob.AvailabilityZones) == 0 && len(job.AvailabilityZones) > 0 { staticIPs := f.sameStaticIps(job, previousJob, input) for _, ip := range staticIPs { f.assignMigratedFromBasedOnIp(ip, &input.Jobs[foundJobIdx]) } } } } return input }
func (a *analyzer) isMigratingFromAzsToNoAzsAndReusingStaticIps(previousInput bftinput.Input, currentInput bftinput.Input) bool { for _, job := range currentInput.Jobs { previousJob, found := previousInput.FindJobByName(job.Name) if found && (len(previousJob.AvailabilityZones) > 0 && len(job.AvailabilityZones) == 0) { for _, network := range job.Networks { previousNetwork, networkFound := previousJob.FindNetworkByName(network.Name) if networkFound { for _, currentIP := range network.StaticIps { for _, prevIP := range previousNetwork.StaticIps { if prevIP == currentIP { return true } } } } } } } return false }