vitess.io/vitess@v0.16.2/go/vt/wrangler/external_cluster.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package wrangler 18 19 import ( 20 "context" 21 "fmt" 22 23 "vitess.io/vitess/go/vt/proto/topodata" 24 ) 25 26 // MountExternalVitessCluster adds a topo record for cluster with specified parameters so that it is available to a Migrate command 27 func (wr *Wrangler) MountExternalVitessCluster(ctx context.Context, clusterName, topoType, topoServer, topoRoot string) error { 28 vci, err := wr.TopoServer().GetExternalVitessCluster(ctx, clusterName) 29 if err != nil { 30 return err 31 } 32 if vci != nil { 33 return fmt.Errorf("there is already a vitess cluster named %s", clusterName) 34 } 35 vc := &topodata.ExternalVitessCluster{ 36 TopoConfig: &topodata.TopoConfig{ 37 TopoType: topoType, 38 Server: topoServer, 39 Root: topoRoot, 40 }, 41 } 42 return wr.TopoServer().CreateExternalVitessCluster(ctx, clusterName, vc) 43 } 44 45 // UnmountExternalVitessCluster deletes a mounted cluster from the topo 46 func (wr *Wrangler) UnmountExternalVitessCluster(ctx context.Context, clusterName string) error { 47 vci, err := wr.TopoServer().GetExternalVitessCluster(ctx, clusterName) 48 if err != nil { 49 return err 50 } 51 if vci == nil { 52 return fmt.Errorf("there is no vitess cluster named %s", clusterName) 53 } 54 return wr.TopoServer().DeleteExternalVitessCluster(ctx, clusterName) 55 }