// 2020 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package status import "github.rackspace.com/DCM/gomigrate/shared" var ( // OrderedPaths is the collection of all upgrade paths that can be taken, ordered by // priority, with the first path matching being used as the upgrade path. OrderedPaths = []Path{ PathStd, } // PathStd is the scenario where we are upgrading through the standard // device upgrade/downgrade path PathStd = Path{ -1, // "Computer No Longer Active", 1, // "Order Submitted", 3, // "Received Contract", 63, // "Sent to Production", 4, // "In Assembly", 5, // "Ready for QC", 6, // "QC Complete/Ready to Rack", 64, // "Racked", 9, // "Segment Configuration", 12, // "Online/Complete", } // PathDeploymentOC is the path that devices can take if the Datapipe deployment sku // exist on the device and final status is Online/Complete PathDeploymentOC = Path{ -1, // "Computer No Longer Active", 1, // "Order Submitted", 11, // "Provisioning", 12, // "Online/Complete", } // PathDeploymentSM is the path that devices can take if the Datapipe deployment sku // exist on the device and final status is Support Maintenance PathDeploymentSM = Path{ -1, // "Computer No Longer Active", 1, // "Order Submitted", 11, // "Provisioning", 70, // "Support Maintenance", } ) // Path is a package specific type that will be used to execute helper methods on type Path []int // Reverse will reverse the index order of the upgade/downgrade paths func (p Path) Reverse() { for i, j := 0, len(p)-1; i < j; i, j = i+1, j-1 { p[i], p[j] = p[j], p[i] } } // Index will find the index value in the path for the given value func (p Path) Index(value int) int { for i := range p { if p[i] == value { return i } } return -1 } // ValidPath will return a bool if both the source and destination statuses exist in the // upgrade path, making it an eligible candidate. func (p Path) ValidPath(sourceStatus, destinationStatus int) bool { return shared.IntInSlice(sourceStatus, p) && shared.IntInSlice(destinationStatus, p) } // Steps will return the list of statuses we need to walk through, minus the statuses that // are already excluded due to the current and destination statuses. func (p Path) Steps(sourceStatus, destinationStatus int) []int { r := p // If we need to downgrade as opposed to upgrade if r.Index(destinationStatus) < r.Index(sourceStatus) { r.Reverse() } r = r[r.Index(sourceStatus)+1:] r = r[:r.Index(destinationStatus)+1] return r }