github.com/vmware/govmomi@v0.51.0/cli/host/portgroup/add.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package portgroup
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  
    11  	"github.com/vmware/govmomi/cli"
    12  	"github.com/vmware/govmomi/cli/flags"
    13  	"github.com/vmware/govmomi/vim25/types"
    14  )
    15  
    16  type add struct {
    17  	*flags.HostSystemFlag
    18  
    19  	spec types.HostPortGroupSpec
    20  }
    21  
    22  func init() {
    23  	cli.Register("host.portgroup.add", &add{})
    24  }
    25  
    26  func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
    27  	cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
    28  	cmd.HostSystemFlag.Register(ctx, f)
    29  
    30  	f.StringVar(&cmd.spec.VswitchName, "vswitch", "", "vSwitch Name")
    31  	f.Var(flags.NewInt32(&cmd.spec.VlanId), "vlan", "VLAN ID")
    32  }
    33  
    34  func (cmd *add) Description() string {
    35  	return `Add portgroup to HOST.
    36  
    37  Examples:
    38    govc host.portgroup.add -vswitch vSwitch0 -vlan 3201 bridge`
    39  }
    40  
    41  func (cmd *add) Usage() string {
    42  	return "NAME"
    43  }
    44  
    45  func (cmd *add) Process(ctx context.Context) error {
    46  	if err := cmd.HostSystemFlag.Process(ctx); err != nil {
    47  		return err
    48  	}
    49  	return nil
    50  }
    51  
    52  func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
    53  	ns, err := cmd.HostNetworkSystem()
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	cmd.spec.Name = f.Arg(0)
    59  
    60  	return ns.AddPortGroup(ctx, cmd.spec)
    61  }