Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP govc: Add virtual machine vApp configuration options #991

Closed
wants to merge 14 commits into from
Closed

WIP govc: Add virtual machine vApp configuration options #991

wants to merge 14 commits into from

Conversation

vancluever
Copy link
Contributor

@vancluever vancluever commented Jan 10, 2018

This PR (still WIP) adds/aims to add sub-commands to manage vApp settings on an individual virtual machine, useful for things like OVF authoring or if you want to use TF in its current state with OVAs that support things like cloud-init, ie: CoreOS - this allows you to remove vApp config so you can manage guestinfo directly. Of course, you could just use this to manage the VM directly too.

This also adds some flag helpers to the flags package, namely having to do with handling optional string values, string slices, and enumerations where validation is necessary (it doesn't look like vSphere properly kicks back an error on some improper vApp configuration options, like if you use lower case IPv4/IPv6 enumerations in the supported IP protocols). I didn't end up using some of these but I figured they'd be useful and will add tests to make sure they are properly accounted for.

Things present:

  • Viewing of vApp configuration (vm.vapp.info)
  • Editing of vApp configuration and product info (vm.vapp.configure)
  • Viewing of vApp properties (vm.vapp.property.info)
  • Addition of vApp properties (vm.vapp.property.add)
  • Edit of vApp properties (vm.vapp.property.edit)
  • Full removal of vApp configuration (vm.vapp.remove)

Things still remaining as of the evening of Jan 9th:

  • Removal of vApp properties (vm.vapp.property.remove)
  • Addition of vApp handling to the simulator
  • Simulator tests
  • Bats tests
  • Addition of tests for the flag helpers

Related: #574

@vancluever
Copy link
Contributor Author

I think I've gotten as far as I'm going to be able to get on this for the week (I have to turn my attention to TF stuff now).

This is functional, the govc commands work (tested them against our lab), the simulator code has been added but still needs to be tested, and the rest of the tests need to be in, which all in should hopefully not be a huge work commitment.

@dougm
Copy link
Member

dougm commented Jan 10, 2018

Awesome thanks @vancluever ! I will review by tomorrow.

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @vancluever , just a few minor comments. Happy to do a closer review and try it out when you're ready.


// enum is a value store that validates against a set of strings. The
// validation is performed at set-time.
type enum struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. We can make use of these in some of the other commands too. At some point I'd like to ditch our custom CLI framework for something else, but not in a rush to do that.

return err
}

if err := task.Wait(ctx); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use cmd.ProgressLogger here.

}

func init() {
cli.Register("vm.vapp.configure", &configure{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other Reconfigure_Task based commands are named "change", vm.change, cluster.change, etc. I wouldn't object to changing that name (no pun intended) in the future, but would prefer to keep it consistent for now.

return err
}

if err := task.Wait(ctx); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use cmd.ProgressLogger

}
}

func testBoolPtr(b bool) *bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use types.NewBool

@vancluever
Copy link
Contributor Author

Thanks @dougm! Yeah I'm just trying to get coverage on the tests right now, balancing work/life at the same time. Hopefully will have more later this week.

Thanks for the note on the type helpers - I totally missed those - might be able to clean up some TF code with that too 🙂

@vancluever
Copy link
Contributor Author

vancluever commented Feb 13, 2018

Hey all, just wanted to mention I haven't forgotten about this, it just wasn't as urgent for our process as it was a while ago now that hashicorp/terraform-provider-vsphere#303 went live, and my personal time has been quite limited as of late. I still want to complete this though, and hopefully will have the spare time to do it soon!

@dougm
Copy link
Member

dougm commented Feb 13, 2018

@vancluever totally understand, take your time man.

@bpoland
Copy link

bpoland commented Apr 26, 2018

Hey @vancluever any chance you will be able to finish this off soon? As you saw from hashicorp/terraform-provider-vsphere#489 I need to turn off vApp options on my templates (which get respun with security updates relatively frequently) and would love to be able to use govc to do that. Thanks :)

@vancluever
Copy link
Contributor Author

@bpoland I've been slowly working through my backlog of personal things, so hopefully I'll have a chance to finish this off soon! So yeah, I will be trying sometime in the next couple of weeks to close this off.

@bpoland
Copy link

bpoland commented Apr 26, 2018

Ok thanks @vancluever for this and all your work on the vsphere provider -- it is much appreciated!

@vancluever
Copy link
Contributor Author

Hey everyone! I've started to work on this again - I'm just starting with addressing @dougm's review comments and finishing up the vApp property tests on the simulator, which should allow me to make progress on finishing up the rest of the simulator stuff soon. After that, I will move on to the rest of the testing stuff.

Thanks!

@vancluever
Copy link
Contributor Author

Simulator tests are finally done! Moving on to bats tests now, in addition to looping back on an interface for adding EULAs. I added it to vm.vapp.change, but right now it's a command line argument with no easy way to view any EULAs that have been added. Since EULAs are generally large, this is kind of unwieldy right now.

This subcommand removes vApp configuration from a virtual machine.

The current reasoning: Terraform currently lacks vApp configuration
support. This is being worked on in
hashicorp/terraform-provider-vsphere#303, but in the meantime
I'm currently working on some code (not necessarily related to the work
going on in the provider) that needs to leverage guestinfo in a CoreOS
template. Working with these attributes in extraConfig is not possible
if vApp configuration is present.

This is functional and has been manually tested, but I'm going to look
at adding the rest of the functionality to govc so that vApp properties
can be largely manipulated within govc itself. This will require work to
both govc and the simulator.

Reference: #574
Adding the following commands:

* vm.vapp.info, displaying general vApp and product details
* vm.vapp.property.info, displaying information for select properties
* vm.vapp.configure, allowing the configuration of all vApp options
except for properties (these are coming in a single CRUD-style fashion).

Also, extended the flag helpers by adding the following:

* String helpers for optional string pointers and string slices
* Enumerated helpers for when validation is needed on string and string
slice values
Basically working off of the same workflow, so the same behaviour can be
used for both operations with some slight divergences.

Basically all that remains before working with the simulator and other
tests (namely for the flag stuff) is deletion of properties
(vm.vapp.property.delete).
The enumeration for the supported IP protocols example is invalid, make
sure the capitalization was correct as it would not work in that form
(govc would kick back an error).
Missed this as I was using goland for a little bit which lacks the
ability to easily wrap comment lines on the fly, or else I just don't
know how to do it like I do in vim. :P
This completes the vApp property configuration part of this work - all
that remains is the tests and simulator work.
This adds virtual machine vApp configuration support to the simulator,
supporting all fields that we currently allow with govc (which is pretty
much everything except EULA and unrecognized OVF sections).

Tests still need to be created for this, and tests for the govc
functionality still need to be added to the bats tests.
For the property stuff - moving from the bottom up, after the property
operations are done will move on to the product config and then general
options.
* vm.vapp.configure is now vm.vapp.change, to match the rest of the
VM reconfigure commands in govc.
* Output for modification operations now uses ProgressLogger for better
output.
* Adjusted bool pointer generation in various points in the simulator to
use types.NewBool.
Add the top-level property tests for edit and remove. This should
complete the full path test and allow us to move on to adding the
additional support to the simulator, namely the product config and
general option sections.
This provides the coverage for the remaining vApp property support for
virtual machines in the simulator.

In addition to that, EULA support has been added in both the simulator
and govc. I'm thinking about making the CLI support a bit better though
as right now it's currently just a command line argument, which may be
unwieldy with larger EULAs, in addition to the fact that there's no CLI
support right now for *viewing* EULAs.
Some of these panic right now due to issues with fetching vApp
configuration in the simulator when the configuration is unset - namely
the output (nil) is not being sent in a format that the property readers
in vim25/mo seem to like. Still trying to figure this out.
vm.log.Printf was removed a while ago - changing this to log.Printf
instead to bring it in line with the other instances of logging.
@frapposelli
Copy link
Member

@vancluever hi Chris, still interested in completing this PR?

@vancluever
Copy link
Contributor Author

@frapposelli I think the truth of the matter is that I've had very little personal time to devote to non-work related projects lately, so I probably won't have the bandwidth to do this anytime soon. I've actually been meaning to post a message about this for a while.

If anyone wants to take it over, I'm totally fine with that. Honestly the last things left to do to fix/add are the two remaining tasks described by the original comment (tests), and then it should be good to go.

@mylesagray
Copy link

mylesagray commented Feb 11, 2020

Would still love to see this implemented - extremely useful for distros and cloud-images that take advantage of the hostname and user-data OVF Properties. Being able to change these on cloned VMs before boot would completely remove the need to rely on VMware Guest OS Customisation, which is a whole other layer of complexity.

Currently solutions like ClusterAPI for vSphere have to use custom cloud-init datasources to work around this meaning we have to build baked images for them, rather than letting users roll their own.

@dougm
Copy link
Member

dougm commented Feb 11, 2020

@mylesagray is there a related CAPV issue open for this?

@petervansickel
Copy link

Any plans to get this completed? I have a use case where I need to add vApp properties to a bunch of VMs as part of a Openshift cluster deployment on vSphere.

@piyushkv1
Copy link

When can we expect this to be completed?

@matteoiacovitti
Copy link

This will be amazing for my VM builds. I recently replaced packer by using the GOVC commands, except the one thing missing is modifying vApp options.

@dougm dougm mentioned this pull request Jan 30, 2021
@mooperd
Copy link

mooperd commented Apr 3, 2021

+1

@embano1 embano1 changed the title [WIP] govc: Add virtual machine vApp configuration options WIP govc: Add virtual machine vApp configuration options Apr 3, 2021
@embano1
Copy link
Contributor

embano1 commented May 26, 2021

@dougm this PR is 3y old but there's still interest in the functionality. Since the PR itself is likely outdated, I suggest closing it and let interested users raise this in an issue for further discussion.

@vancluever
Copy link
Contributor Author

Hey all, I'm closing this to clear out my old PR backlog. Will leave the repository open for now, but if anyone wants to carry on my work please clone it sooner rather than later as I may end up deleting my local fork.

@vancluever vancluever closed this Jul 26, 2021
@dougm
Copy link
Member

dougm commented Jul 29, 2021

@vancluever I just went to clone it now but your fork is gone. Sorry we hadn't been able to pick up where you left off, but it still might be possible to if you can still make your changes available in some form if you still have it locally. Even patch in a gist would be good. Thanks!

@vancluever
Copy link
Contributor Author

@dougm I thought I still had this repo, but apparently I deleted it in a security cleanup over a month ago. Sorry 😞 I really meant to keep it.

I'm going to keep this bookmarked if I find it on an older workstation I'll make sure to re-push it.

Really sorry again!

@janitha
Copy link

janitha commented Jul 29, 2021

The PRs content was still available in branch pull/991/head that you can explicitly fetch. I've placed it in my fork in branch vapp https://github.com/janitha/govmomi/tree/vapp for ease of access

@vancluever
Copy link
Contributor Author

Thank you very much @janitha!!! Good to know this trick too just in case this happens again.

Thanks again!

@drennalls
Copy link

Is it possible to to remove all vapp properties from a VM without this PR?
OR (along the same lines) remove all properties from an OVA that's being imported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.