// 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 common import ( "fmt" "github.rackspace.com/gorax/clients/dcxAutohost" ) type ( // Translation defines a vlan translation after created in the // DCX toolset Translation struct { ConfiguredVlan VlanX `json:"configured_vlan" bson:"configured_vlan"` MigrationVlan VlanX `json:"migration_vlan" bson:"migration_vlan"` } // VlanX is the vlan details within the Translation struct VlanX struct { Vlan int `json:"vlan_number" bson:"vlan_number"` ZoneName string `json:"zone_name" bson:"zone_name"` CIDR string `json:"cidr" bson:"cidr"` NetworkSegments []string `json:"network_segments" bson:"network_segments"` } ) // Segment is a helper method that will return the first segment name // in a VlanX, if it exist, OR a empty string func (v *VlanX) Segment() string { for _, seg := range v.NetworkSegments { return seg } return "" } // AddTranslation method attached to the Translation type will add a migration translation for a given // current vlan. func (t *Translation) AddTranslation(migVl dcxAutohost.VlanResponse) error { if t.MigrationVlan.Vlan != 0 { return fmt.Errorf("translation already exist Vlan%d %v", t.MigrationVlan.Vlan, t.MigrationVlan.Segment()) } t.MigrationVlan = VlanX{ Vlan: migVl.VlanNumber, ZoneName: migVl.VlanZone, NetworkSegments: []string{migVl.SegmentName}, } return nil }