github.com/vmware/govmomi@v0.43.0/ovf/importer/options.go (about)

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