Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
Arquivo: ovf.go Projeto: vmware/vic
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
}