本文整理匯總了Golang中github.com/vmware/govmomi/ovf.Env類的典型用法代碼示例。如果您正苦於以下問題:Golang Env類的具體用法?Golang Env怎麽用?Golang Env使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Env類的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
}