// 2017 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 dcx import ( "strings" "go.mongodb.org/mongo-driver/bson" "github.com/sirupsen/logrus" "github.rackspace.com/DCM/migration/pkg/collection/mongo" "github.rackspace.com/gorax/clients/dcxAutohost" ) // MigrateVlans method takes an environment and a list of ZoneVlans as arguments to call out // to the DCX Migrate VLANs API call: // https://pages.github.rackspace.com/dcx/gateway/#/environments/migrateVlans func (c *Client) MigrateVlans(environment string, vlans []mongo.ZoneVlan) (dcxAutohost.MigratedVlans, error) { payload := dcxAutohost.MigrateVlansPayload{} vlanTranslations, err := c.dcx.EnvironmentMigrationVlans(environment) if err != nil { return dcxAutohost.MigratedVlans{}, err } for _, v := range vlanTranslations { for _, v2 := range vlans { if v.ConfiguredVlan.ZoneName == v2.ZoneName && v.ConfiguredVlan.VlanNumber == v2.VlanNumber { payload.ExcludedVlans = append( payload.ExcludedVlans, &dcxAutohost.ExcludedVlan{ ZoneName: v.ConfiguredVlan.ZoneName, VlanNumber: v.ConfiguredVlan.VlanNumber, }, ) break } } } logrus.Infof("running POST environments/%s/migrate_vlans", environment) //spew.Dump(payload) resp, err := c.dcx.MigrateVlans(environment, payload) if err != nil { // return no error for (whitebox/nonat) environments without aggex ports/vlans if strings.Contains(err.Error(), "not able to determine destination AggExNet zone") { return dcxAutohost.MigratedVlans{}, nil } return dcxAutohost.MigratedVlans{}, err } err = c.db.InsertOne( "environmentsMigrated", bson.D{{"_id", environment}, {"migrated", true}}, ) if err != nil { return dcxAutohost.MigratedVlans{}, err } return resp, nil }