github.com/vmware/govmomi@v0.51.0/simulator/entity.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 simulator
     6  
     7  import (
     8  	"github.com/vmware/govmomi/vim25/methods"
     9  	"github.com/vmware/govmomi/vim25/mo"
    10  	"github.com/vmware/govmomi/vim25/soap"
    11  	"github.com/vmware/govmomi/vim25/types"
    12  )
    13  
    14  func RenameTask(ctx *Context, e mo.Entity, r *types.Rename_Task, dup ...bool) soap.HasFault {
    15  	task := CreateTask(e, "rename", func(t *Task) (types.AnyType, types.BaseMethodFault) {
    16  		obj := ctx.Map.Get(r.This).(mo.Entity).Entity()
    17  
    18  		canDup := len(dup) == 1 && dup[0]
    19  		if parent, ok := asFolderMO(ctx.Map.Get(*obj.Parent)); ok && !canDup {
    20  			if ctx.Map.FindByName(r.NewName, parent.ChildEntity) != nil {
    21  				return nil, &types.InvalidArgument{InvalidProperty: "name"}
    22  			}
    23  		}
    24  
    25  		ctx.Update(e, []types.PropertyChange{{Name: "name", Val: r.NewName}})
    26  
    27  		return nil, nil
    28  	})
    29  
    30  	return &methods.Rename_TaskBody{
    31  		Res: &types.Rename_TaskResponse{
    32  			Returnval: task.Run(ctx),
    33  		},
    34  	}
    35  }