github.com/vmware/govmomi@v0.37.2/govc/cluster/vlcm/enable.go (about)

     1  /*
     2  Copyright (c) 2024-2024 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 vlcm
    18  
    19  import (
    20  	"context"
    21  	"flag"
    22  
    23  	"github.com/vmware/govmomi/vapi/cis/tasks"
    24  
    25  	"github.com/vmware/govmomi/govc/cli"
    26  	"github.com/vmware/govmomi/govc/flags"
    27  	"github.com/vmware/govmomi/vapi/esx/settings/clusters"
    28  )
    29  
    30  type enable struct {
    31  	*flags.ClientFlag
    32  
    33  	clusterId string
    34  	skipCheck bool
    35  }
    36  
    37  func init() {
    38  	cli.Register("cluster.vlcm.enable", &enable{})
    39  }
    40  
    41  func (cmd *enable) Register(ctx context.Context, f *flag.FlagSet) {
    42  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    43  	cmd.ClientFlag.Register(ctx, f)
    44  
    45  	f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
    46  	f.BoolVar(&cmd.skipCheck, "skip-check", false, "Whether to skip the software check after enabling vLCM")
    47  }
    48  
    49  func (cmd *enable) Process(ctx context.Context) error {
    50  	return cmd.ClientFlag.Process(ctx)
    51  }
    52  
    53  func (cmd *enable) Usage() string {
    54  	return "CLUSTER"
    55  }
    56  
    57  func (cmd *enable) Description() string {
    58  	return `Enables vLCM on the provided cluster
    59  
    60  This operation is irreversible
    61  
    62  Examples:
    63    govc cluster.vlcm.enable -cluster-id=domain-c21`
    64  }
    65  
    66  func (cmd *enable) Run(ctx context.Context, f *flag.FlagSet) error {
    67  	rc, err := cmd.RestClient()
    68  
    69  	if err != nil {
    70  		return err
    71  	}
    72  
    73  	dm := clusters.NewManager(rc)
    74  
    75  	if taskId, err := dm.EnableSoftwareManagement(cmd.clusterId, cmd.skipCheck); err != nil {
    76  		return err
    77  	} else if _, err := tasks.NewManager(rc).WaitForCompletion(ctx, taskId); err != nil {
    78  		return err
    79  	} else {
    80  		return nil
    81  	}
    82  }