github.com/vmware/govmomi@v0.43.0/object/host_network_system.go (about)

     1  /*
     2  Copyright (c) 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 object
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/vmware/govmomi/vim25"
    23  	"github.com/vmware/govmomi/vim25/methods"
    24  	"github.com/vmware/govmomi/vim25/types"
    25  )
    26  
    27  type HostNetworkSystem struct {
    28  	Common
    29  }
    30  
    31  func NewHostNetworkSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostNetworkSystem {
    32  	return &HostNetworkSystem{
    33  		Common: NewCommon(c, ref),
    34  	}
    35  }
    36  
    37  // AddPortGroup wraps methods.AddPortGroup
    38  func (o HostNetworkSystem) AddPortGroup(ctx context.Context, portgrp types.HostPortGroupSpec) error {
    39  	req := types.AddPortGroup{
    40  		This:    o.Reference(),
    41  		Portgrp: portgrp,
    42  	}
    43  
    44  	_, err := methods.AddPortGroup(ctx, o.c, &req)
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	return nil
    50  }
    51  
    52  // AddServiceConsoleVirtualNic wraps methods.AddServiceConsoleVirtualNic
    53  func (o HostNetworkSystem) AddServiceConsoleVirtualNic(ctx context.Context, portgroup string, nic types.HostVirtualNicSpec) (string, error) {
    54  	req := types.AddServiceConsoleVirtualNic{
    55  		This:      o.Reference(),
    56  		Portgroup: portgroup,
    57  		Nic:       nic,
    58  	}
    59  
    60  	res, err := methods.AddServiceConsoleVirtualNic(ctx, o.c, &req)
    61  	if err != nil {
    62  		return "", err
    63  	}
    64  
    65  	return res.Returnval, nil
    66  }
    67  
    68  // AddVirtualNic wraps methods.AddVirtualNic
    69  func (o HostNetworkSystem) AddVirtualNic(ctx context.Context, portgroup string, nic types.HostVirtualNicSpec) (string, error) {
    70  	req := types.AddVirtualNic{
    71  		This:      o.Reference(),
    72  		Portgroup: portgroup,
    73  		Nic:       nic,
    74  	}
    75  
    76  	res, err := methods.AddVirtualNic(ctx, o.c, &req)
    77  	if err != nil {
    78  		return "", err
    79  	}
    80  
    81  	return res.Returnval, nil
    82  }
    83  
    84  // AddVirtualSwitch wraps methods.AddVirtualSwitch
    85  func (o HostNetworkSystem) AddVirtualSwitch(ctx context.Context, vswitchName string, spec *types.HostVirtualSwitchSpec) error {
    86  	req := types.AddVirtualSwitch{
    87  		This:        o.Reference(),
    88  		VswitchName: vswitchName,
    89  		Spec:        spec,
    90  	}
    91  
    92  	_, err := methods.AddVirtualSwitch(ctx, o.c, &req)
    93  	if err != nil {
    94  		return err
    95  	}
    96  
    97  	return nil
    98  }
    99  
   100  // QueryNetworkHint wraps methods.QueryNetworkHint
   101  func (o HostNetworkSystem) QueryNetworkHint(ctx context.Context, device []string) ([]types.PhysicalNicHintInfo, error) {
   102  	req := types.QueryNetworkHint{
   103  		This:   o.Reference(),
   104  		Device: device,
   105  	}
   106  
   107  	res, err := methods.QueryNetworkHint(ctx, o.c, &req)
   108  	if err != nil {
   109  		return nil, err
   110  	}
   111  
   112  	return res.Returnval, err
   113  }
   114  
   115  // RefreshNetworkSystem wraps methods.RefreshNetworkSystem
   116  func (o HostNetworkSystem) RefreshNetworkSystem(ctx context.Context) error {
   117  	req := types.RefreshNetworkSystem{
   118  		This: o.Reference(),
   119  	}
   120  
   121  	_, err := methods.RefreshNetworkSystem(ctx, o.c, &req)
   122  	if err != nil {
   123  		return err
   124  	}
   125  
   126  	return nil
   127  }
   128  
   129  // RemovePortGroup wraps methods.RemovePortGroup
   130  func (o HostNetworkSystem) RemovePortGroup(ctx context.Context, pgName string) error {
   131  	req := types.RemovePortGroup{
   132  		This:   o.Reference(),
   133  		PgName: pgName,
   134  	}
   135  
   136  	_, err := methods.RemovePortGroup(ctx, o.c, &req)
   137  	if err != nil {
   138  		return err
   139  	}
   140  
   141  	return nil
   142  }
   143  
   144  // RemoveServiceConsoleVirtualNic wraps methods.RemoveServiceConsoleVirtualNic
   145  func (o HostNetworkSystem) RemoveServiceConsoleVirtualNic(ctx context.Context, device string) error {
   146  	req := types.RemoveServiceConsoleVirtualNic{
   147  		This:   o.Reference(),
   148  		Device: device,
   149  	}
   150  
   151  	_, err := methods.RemoveServiceConsoleVirtualNic(ctx, o.c, &req)
   152  	if err != nil {
   153  		return err
   154  	}
   155  
   156  	return nil
   157  }
   158  
   159  // RemoveVirtualNic wraps methods.RemoveVirtualNic
   160  func (o HostNetworkSystem) RemoveVirtualNic(ctx context.Context, device string) error {
   161  	req := types.RemoveVirtualNic{
   162  		This:   o.Reference(),
   163  		Device: device,
   164  	}
   165  
   166  	_, err := methods.RemoveVirtualNic(ctx, o.c, &req)
   167  	if err != nil {
   168  		return err
   169  	}
   170  
   171  	return nil
   172  }
   173  
   174  // RemoveVirtualSwitch wraps methods.RemoveVirtualSwitch
   175  func (o HostNetworkSystem) RemoveVirtualSwitch(ctx context.Context, vswitchName string) error {
   176  	req := types.RemoveVirtualSwitch{
   177  		This:        o.Reference(),
   178  		VswitchName: vswitchName,
   179  	}
   180  
   181  	_, err := methods.RemoveVirtualSwitch(ctx, o.c, &req)
   182  	if err != nil {
   183  		return err
   184  	}
   185  
   186  	return nil
   187  }
   188  
   189  // RestartServiceConsoleVirtualNic wraps methods.RestartServiceConsoleVirtualNic
   190  func (o HostNetworkSystem) RestartServiceConsoleVirtualNic(ctx context.Context, device string) error {
   191  	req := types.RestartServiceConsoleVirtualNic{
   192  		This:   o.Reference(),
   193  		Device: device,
   194  	}
   195  
   196  	_, err := methods.RestartServiceConsoleVirtualNic(ctx, o.c, &req)
   197  	if err != nil {
   198  		return err
   199  	}
   200  
   201  	return nil
   202  }
   203  
   204  // UpdateConsoleIpRouteConfig wraps methods.UpdateConsoleIpRouteConfig
   205  func (o HostNetworkSystem) UpdateConsoleIpRouteConfig(ctx context.Context, config types.BaseHostIpRouteConfig) error {
   206  	req := types.UpdateConsoleIpRouteConfig{
   207  		This:   o.Reference(),
   208  		Config: config,
   209  	}
   210  
   211  	_, err := methods.UpdateConsoleIpRouteConfig(ctx, o.c, &req)
   212  	if err != nil {
   213  		return err
   214  	}
   215  
   216  	return nil
   217  }
   218  
   219  // UpdateDnsConfig wraps methods.UpdateDnsConfig
   220  func (o HostNetworkSystem) UpdateDnsConfig(ctx context.Context, config types.BaseHostDnsConfig) error {
   221  	req := types.UpdateDnsConfig{
   222  		This:   o.Reference(),
   223  		Config: config,
   224  	}
   225  
   226  	_, err := methods.UpdateDnsConfig(ctx, o.c, &req)
   227  	if err != nil {
   228  		return err
   229  	}
   230  
   231  	return nil
   232  }
   233  
   234  // UpdateIpRouteConfig wraps methods.UpdateIpRouteConfig
   235  func (o HostNetworkSystem) UpdateIpRouteConfig(ctx context.Context, config types.BaseHostIpRouteConfig) error {
   236  	req := types.UpdateIpRouteConfig{
   237  		This:   o.Reference(),
   238  		Config: config,
   239  	}
   240  
   241  	_, err := methods.UpdateIpRouteConfig(ctx, o.c, &req)
   242  	if err != nil {
   243  		return err
   244  	}
   245  
   246  	return nil
   247  }
   248  
   249  // UpdateIpRouteTableConfig wraps methods.UpdateIpRouteTableConfig
   250  func (o HostNetworkSystem) UpdateIpRouteTableConfig(ctx context.Context, config types.HostIpRouteTableConfig) error {
   251  	req := types.UpdateIpRouteTableConfig{
   252  		This:   o.Reference(),
   253  		Config: config,
   254  	}
   255  
   256  	_, err := methods.UpdateIpRouteTableConfig(ctx, o.c, &req)
   257  	if err != nil {
   258  		return err
   259  	}
   260  
   261  	return nil
   262  }
   263  
   264  // UpdateNetworkConfig wraps methods.UpdateNetworkConfig
   265  func (o HostNetworkSystem) UpdateNetworkConfig(ctx context.Context, config types.HostNetworkConfig, changeMode string) (*types.HostNetworkConfigResult, error) {
   266  	req := types.UpdateNetworkConfig{
   267  		This:       o.Reference(),
   268  		Config:     config,
   269  		ChangeMode: changeMode,
   270  	}
   271  
   272  	res, err := methods.UpdateNetworkConfig(ctx, o.c, &req)
   273  	if err != nil {
   274  		return nil, err
   275  	}
   276  
   277  	return &res.Returnval, nil
   278  }
   279  
   280  // UpdatePhysicalNicLinkSpeed wraps methods.UpdatePhysicalNicLinkSpeed
   281  func (o HostNetworkSystem) UpdatePhysicalNicLinkSpeed(ctx context.Context, device string, linkSpeed *types.PhysicalNicLinkInfo) error {
   282  	req := types.UpdatePhysicalNicLinkSpeed{
   283  		This:      o.Reference(),
   284  		Device:    device,
   285  		LinkSpeed: linkSpeed,
   286  	}
   287  
   288  	_, err := methods.UpdatePhysicalNicLinkSpeed(ctx, o.c, &req)
   289  	if err != nil {
   290  		return err
   291  	}
   292  
   293  	return nil
   294  }
   295  
   296  // UpdatePortGroup wraps methods.UpdatePortGroup
   297  func (o HostNetworkSystem) UpdatePortGroup(ctx context.Context, pgName string, portgrp types.HostPortGroupSpec) error {
   298  	req := types.UpdatePortGroup{
   299  		This:    o.Reference(),
   300  		PgName:  pgName,
   301  		Portgrp: portgrp,
   302  	}
   303  
   304  	_, err := methods.UpdatePortGroup(ctx, o.c, &req)
   305  	if err != nil {
   306  		return err
   307  	}
   308  
   309  	return nil
   310  }
   311  
   312  // UpdateServiceConsoleVirtualNic wraps methods.UpdateServiceConsoleVirtualNic
   313  func (o HostNetworkSystem) UpdateServiceConsoleVirtualNic(ctx context.Context, device string, nic types.HostVirtualNicSpec) error {
   314  	req := types.UpdateServiceConsoleVirtualNic{
   315  		This:   o.Reference(),
   316  		Device: device,
   317  		Nic:    nic,
   318  	}
   319  
   320  	_, err := methods.UpdateServiceConsoleVirtualNic(ctx, o.c, &req)
   321  	if err != nil {
   322  		return err
   323  	}
   324  
   325  	return nil
   326  }
   327  
   328  // UpdateVirtualNic wraps methods.UpdateVirtualNic
   329  func (o HostNetworkSystem) UpdateVirtualNic(ctx context.Context, device string, nic types.HostVirtualNicSpec) error {
   330  	req := types.UpdateVirtualNic{
   331  		This:   o.Reference(),
   332  		Device: device,
   333  		Nic:    nic,
   334  	}
   335  
   336  	_, err := methods.UpdateVirtualNic(ctx, o.c, &req)
   337  	if err != nil {
   338  		return err
   339  	}
   340  
   341  	return nil
   342  }
   343  
   344  // UpdateVirtualSwitch wraps methods.UpdateVirtualSwitch
   345  func (o HostNetworkSystem) UpdateVirtualSwitch(ctx context.Context, vswitchName string, spec types.HostVirtualSwitchSpec) error {
   346  	req := types.UpdateVirtualSwitch{
   347  		This:        o.Reference(),
   348  		VswitchName: vswitchName,
   349  		Spec:        spec,
   350  	}
   351  
   352  	_, err := methods.UpdateVirtualSwitch(ctx, o.c, &req)
   353  	if err != nil {
   354  		return err
   355  	}
   356  
   357  	return nil
   358  }