本文整理汇总了Golang中github.com/vmware/govmomi/ovf.Env.MarshalManual方法的典型用法代码示例。如果您正苦于以下问题:Golang Env.MarshalManual方法的具体用法?Golang Env.MarshalManual怎么用?Golang Env.MarshalManual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/ovf.Env
的用法示例。
在下文中一共展示了Env.MarshalManual方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InjectOvfEnv
func (cmd *ovfx) InjectOvfEnv(vm *object.VirtualMachine) error {
if !cmd.Options.InjectOvfEnv {
return nil
}
cmd.Log("Injecting OVF environment...\n")
var opts []types.BaseOptionValue
a := cmd.Client.ServiceContent.About
// build up Environment in order to marshal to xml
var props []ovf.EnvProperty
for _, p := range cmd.Options.PropertyMapping {
props = append(props, ovf.EnvProperty{
Key: p.Key,
Value: p.Value,
})
}
env := ovf.Env{
EsxID: vm.Reference().Value,
Platform: &ovf.PlatformSection{
Kind: a.Name,
Version: a.Version,
Vendor: a.Vendor,
Locale: "US",
},
Property: &ovf.PropertySection{
Properties: props,
},
}
opts = append(opts, &types.OptionValue{
Key: "guestinfo.ovfEnv",
Value: env.MarshalManual(),
})
ctx := context.Background()
task, err := vm.Reconfigure(ctx, types.VirtualMachineConfigSpec{
ExtraConfig: opts,
})
if err != nil {
return err
}
return task.Wait(ctx)
}
示例2: InjectOvfEnv
func (cmd *ovfx) InjectOvfEnv(vm *object.VirtualMachine) error {
ctx := context.TODO()
if !cmd.Options.PowerOn || !cmd.Options.InjectOvfEnv {
return nil
}
a := cmd.Client.ServiceContent.About
if strings.EqualFold(a.ProductLineId, "esx") || strings.EqualFold(a.ProductLineId, "embeddedEsx") || strings.EqualFold(a.ProductLineId, "vpx") {
cmd.Log("Injecting OVF environment...\n")
// build up Environment in order to marshal to xml
var epa []ovf.EnvProperty
for _, p := range cmd.Options.PropertyMapping {
epa = append(epa, ovf.EnvProperty{
Key: p.Key,
Value: p.Value})
}
env := ovf.Env{
EsxID: vm.Reference().Value,
Platform: &ovf.PlatformSection{
Kind: a.Name,
Version: a.Version,
Vendor: a.Vendor,
Locale: "US",
},
Property: &ovf.PropertySection{
Properties: epa},
}
xenv := env.MarshalManual()
vmConfigSpec := types.VirtualMachineConfigSpec{
ExtraConfig: []types.BaseOptionValue{&types.OptionValue{
Key: "guestinfo.ovfEnv",
Value: xenv}}}
task, err := vm.Reconfigure(ctx, vmConfigSpec)
if err != nil {
return err
}
if err := task.Wait(ctx); err != nil {
return err
}
}
return nil
}