github.com/vmware/govmomi@v0.43.0/govc/host/portgroup/add.go (about)

     1  /*
     2  Copyright (c) 2014-2015 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 portgroup
    18  
    19  import (
    20  	"context"
    21  	"flag"
    22  
    23  	"github.com/vmware/govmomi/govc/cli"
    24  	"github.com/vmware/govmomi/govc/flags"
    25  	"github.com/vmware/govmomi/vim25/types"
    26  )
    27  
    28  type add struct {
    29  	*flags.HostSystemFlag
    30  
    31  	spec types.HostPortGroupSpec
    32  }
    33  
    34  func init() {
    35  	cli.Register("host.portgroup.add", &add{})
    36  }
    37  
    38  func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
    39  	cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
    40  	cmd.HostSystemFlag.Register(ctx, f)
    41  
    42  	f.StringVar(&cmd.spec.VswitchName, "vswitch", "", "vSwitch Name")
    43  	f.Var(flags.NewInt32(&cmd.spec.VlanId), "vlan", "VLAN ID")
    44  }
    45  
    46  func (cmd *add) Description() string {
    47  	return `Add portgroup to HOST.
    48  
    49  Examples:
    50    govc host.portgroup.add -vswitch vSwitch0 -vlan 3201 bridge`
    51  }
    52  
    53  func (cmd *add) Usage() string {
    54  	return "NAME"
    55  }
    56  
    57  func (cmd *add) Process(ctx context.Context) error {
    58  	if err := cmd.HostSystemFlag.Process(ctx); err != nil {
    59  		return err
    60  	}
    61  	return nil
    62  }
    63  
    64  func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
    65  	ns, err := cmd.HostNetworkSystem()
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	cmd.spec.Name = f.Arg(0)
    71  
    72  	return ns.AddPortGroup(ctx, cmd.spec)
    73  }