github.com/vmware/govmomi@v0.51.0/ovf/importer/options.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 importer
     6  
     7  import (
     8  	"encoding/json"
     9  
    10  	"github.com/vmware/govmomi/ovf"
    11  	"github.com/vmware/govmomi/vim25/types"
    12  )
    13  
    14  type KeyValue struct {
    15  	Key   string
    16  	Value string
    17  }
    18  
    19  // case insensitive for Key + Value
    20  func (kv *KeyValue) UnmarshalJSON(b []byte) error {
    21  	e := struct {
    22  		types.KeyValue
    23  		Key   *string
    24  		Value *string
    25  	}{
    26  		types.KeyValue{}, &kv.Key, &kv.Value,
    27  	}
    28  
    29  	err := json.Unmarshal(b, &e)
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	if kv.Key == "" {
    35  		kv.Key = e.KeyValue.Key // "key"
    36  	}
    37  
    38  	if kv.Value == "" {
    39  		kv.Value = e.KeyValue.Value // "value"
    40  	}
    41  
    42  	return nil
    43  }
    44  
    45  type Property struct {
    46  	KeyValue
    47  	Spec *ovf.Property `json:",omitempty"`
    48  }
    49  
    50  type Network struct {
    51  	Name    string
    52  	Network string
    53  }
    54  
    55  type Options struct {
    56  	AllDeploymentOptions []string `json:",omitempty"`
    57  	Deployment           string   `json:",omitempty"`
    58  
    59  	AllDiskProvisioningOptions []string `json:",omitempty"`
    60  	DiskProvisioning           string
    61  
    62  	AllIPAllocationPolicyOptions []string `json:",omitempty"`
    63  	IPAllocationPolicy           string
    64  
    65  	AllIPProtocolOptions []string `json:",omitempty"`
    66  	IPProtocol           string
    67  
    68  	PropertyMapping []Property `json:",omitempty"`
    69  
    70  	NetworkMapping []Network `json:",omitempty"`
    71  
    72  	Annotation string `json:",omitempty"`
    73  
    74  	MarkAsTemplate bool
    75  	PowerOn        bool
    76  	InjectOvfEnv   bool
    77  	WaitForIP      bool
    78  	Name           *string
    79  }