github.com/vmware/govmomi@v0.37.2/govc/cluster/module/create.go (about)

     1  /*
     2  Copyright (c) 2022 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 module
    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  	vapicluster "github.com/vmware/govmomi/vapi/cluster"
    27  )
    28  
    29  type create struct {
    30  	*flags.ClusterFlag
    31  }
    32  
    33  func init() {
    34  	cli.Register("cluster.module.create", &create{})
    35  }
    36  
    37  func (cmd *create) 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 *create) Process(ctx context.Context) error {
    43  	return cmd.ClusterFlag.Process(ctx)
    44  }
    45  
    46  func (cmd *create) Description() string {
    47  	return `Create cluster module.
    48  
    49  This command will output the ID of the new module.
    50  
    51  Examples:
    52    govc cluster.module.create -cluster my_cluster`
    53  }
    54  
    55  func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
    56  	if f.NArg() != 0 {
    57  		return flag.ErrHelp
    58  	}
    59  
    60  	c, err := cmd.RestClient()
    61  	if err != nil {
    62  		return err
    63  	}
    64  
    65  	cluster, err := cmd.Cluster()
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	id, err := vapicluster.NewManager(c).CreateModule(ctx, cluster.Reference())
    71  	if err != nil {
    72  		return err
    73  	}
    74  
    75  	fmt.Println(id)
    76  	return nil
    77  }