github.com/vmware/govmomi@v0.37.2/simulator/dataset.go (about)

     1  /*
     2  Copyright (c) 2023-2023 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 simulator
    18  
    19  import (
    20  	"github.com/vmware/govmomi/vapi/vm/dataset"
    21  )
    22  
    23  type DataSet struct {
    24  	*dataset.Info
    25  	ID      string
    26  	Entries map[string]string
    27  }
    28  
    29  func copyDataSetsForVmClone(src map[string]*DataSet) map[string]*DataSet {
    30  	copy := make(map[string]*DataSet, len(src))
    31  	for k, v := range src {
    32  		if v.OmitFromSnapshotAndClone {
    33  			continue
    34  		}
    35  		copy[k] = copyDataSet(v)
    36  	}
    37  	return copy
    38  }
    39  
    40  func copyDataSet(src *DataSet) *DataSet {
    41  	if src == nil {
    42  		return nil
    43  	}
    44  	copy := &DataSet{
    45  		Info: &dataset.Info{
    46  			Name:                     src.Name,
    47  			Description:              src.Description,
    48  			Host:                     src.Host,
    49  			Guest:                    src.Guest,
    50  			Used:                     src.Used,
    51  			OmitFromSnapshotAndClone: src.OmitFromSnapshotAndClone,
    52  		},
    53  		ID:      src.ID,
    54  		Entries: copyEntries(src.Entries),
    55  	}
    56  	return copy
    57  }
    58  
    59  func copyEntries(src map[string]string) map[string]string {
    60  	copy := make(map[string]string, len(src))
    61  	for k, v := range src {
    62  		copy[k] = v
    63  	}
    64  	return copy
    65  }