| 1 |
/* |
| 2 |
Copyright (c) 2020 VMware, Inc. All Rights Reserved. |
| 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 cluster |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"flag" |
| 22 |
"fmt" |
| 23 |
|
| 24 |
"github.com/vmware/govmomi/govc/cli" |
| 25 |
"github.com/vmware/govmomi/govc/flags" |
| 26 |
"github.com/vmware/govmomi/vapi/namespace" |
| 27 |
) |
| 28 |
|
| 29 |
type disableCluster struct { |
| 30 |
*flags.ClusterFlag |
| 31 |
} |
| 32 |
|
| 33 |
func init() { |
| 34 |
cli.Register("namespace.cluster.disable", &disableCluster{}) |
| 35 |
} |
| 36 |
|
| 37 |
func (cmd *disableCluster) Register(ctx context.Context, f *flag.FlagSet) { |
| 38 |
cmd.ClusterFlag, ctx = flags.NewClusterFlag(ctx) |
| 39 |
cmd.ClusterFlag.Register(ctx, f) |
| 40 |
} |
| 41 |
|
| 42 |
func (cmd *disableCluster) Description() string { |
| 43 |
return `Disables vSphere Namespaces on the specified cluster. |
| 44 |
|
| 45 |
Examples: |
| 46 |
govc namespace.cluster.disable -cluster "Workload-Cluster"` |
| 47 |
} |
| 48 |
|
| 49 |
func (cmd *disableCluster) Run(ctx context.Context, f *flag.FlagSet) error { |
| 50 |
c, err := cmd.RestClient() |
| 51 |
if err != nil { |
| 52 |
return err |
| 53 |
} |
| 54 |
|
| 55 |
// Cluster object reference lookup |
| 56 |
cluster, err := cmd.Cluster() |
| 57 |
if err != nil { |
| 58 |
return err |
| 59 |
} |
| 60 |
|
| 61 |
m := namespace.NewManager(c) |
| 62 |
clusterId := cluster.Reference().Value |
| 63 |
|
| 64 |
err = m.DisableCluster(ctx, clusterId) |
| 65 |
if err != nil { |
| 66 |
return fmt.Errorf("error disabling cluster: %s", err) |
| 67 |
} |
| 68 |
|
| 69 |
return nil |
| 70 |
} |