Skip to content
New issue

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

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

Already on GitHub? # to your account

r/vapp_container: Add vapp_container resource #566

Merged
merged 10 commits into from
Aug 6, 2018
Merged

Conversation

bill-rich
Copy link
Contributor

No description provided.

@bill-rich bill-rich requested a review from a team July 13, 2018 06:20
@vancluever
Copy link
Contributor

@bill-rich could this PR be cleaned up a bit? I see a bunch of my commits in there. Maybe rebase your current changes on master?

git checkout f-vapp-container
git fetch origin master
git rebase master

That should make things a lot clearer and may resolve merge conflicts as well.

@bill-rich
Copy link
Contributor Author

@vancluever Thanks! I missed that. Got it sorted now.

Copy link
Contributor

@vancluever vancluever left a comment

Choose a reason for hiding this comment

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

Hey @bill-rich! This looks mostly good. We should address these comments I think and then maybe I'll give a manual test a spin to see how it runs. Let me know!

// If the parent resource pool is a vApp, we need to create the VM using the
// CreateChildVM vApp function instead of directly using SDRS recommendations.
if sps.ResourcePool != nil {
if vc, err := vappcontainer.FromID(client, sps.ResourcePool.Reference().Value); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic assumes that the only error that we are ever going to receive from vappcontainer.FromID will be ManagedObjectNotFound, which has implications further down the stack. You will want to handle the error, possibly in a switch:

vc, err := vappcontainer.FromID(client, sps.ResourcePool.Reference().Value)
switch {
case viapi.IsManagedObjectNotFoundError(err):
  // pass
case nil:
  // vApp container creation logic here
default:
  return err
}

return err
}

func recommendAndApplySDRS(
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than deleting this function, I'd recommend taking the de-coupled logic that has been duplicated to other parts and just throwing that here. Then the rest of the places that reference recommendAndApplySDRS that don't require a special path to address vApp containers don't need changes at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I did it this way was because I still need the recommendation in order to determine which datastore to use in the case where the VM is being created in a vApp. I didn't want to clutter up recommendAndApplySDRS with the vApp code. Does that make sense? Very possible I'm just overlooking something simple.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not saying to actually revert the de-coupling, but rather than removing the function altogether and then duplicating code a few places, just change recommendAndApplySDRS to:

func recommendAndApplySDRS(
	client *govmomi.Client,
	sps types.StoragePlacementSpec,
	timeout time.Duration,
) (*object.VirtualMachine, error) {
	placement, err := recommendSDRS(client, sps, time.Minute*time.Duration(timeout))
	if err != nil {
		return nil, err
	}
	return applySDRS(client, placement, time.Minute*time.Duration(timeout))
}

This way, you don't have to update the other places that this is being used (where you don't need the recommendation), such as #566 (comment), #566 (comment), or #566 (comment).

@@ -228,7 +250,11 @@ func CloneVM(
Type: string(types.StoragePlacementSpecPlacementTypeClone),
}

return recommendAndApplySDRS(client, sps, time.Minute*time.Duration(timeout))
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment on recommendAndApplySDRS

@@ -268,7 +294,11 @@ func ReconfigureVM(
ConfigSpec: &spec,
}

_, err = recommendAndApplySDRS(client, sps, provider.DefaultAPITimeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment on recommendAndApplySDRS

@@ -305,16 +335,16 @@ func RelocateVM(
Type: string(types.StoragePlacementSpecPlacementTypeRelocate),
}

_, err = recommendAndApplySDRS(client, sps, time.Minute*time.Duration(timeout))
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment on recommendAndApplySDRS

# vsphere\_vapp\_container

The `vsphere_vApp_container` resource can be used to create and manage
Virtual Appliances.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not accurate, correct? Eventually we might allow OVAs through it (which could allow for the deploy of multi-VM vApps), but currently it's just a container.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not correct. Seems I got Virtual Appliance in my head when I was writing the docs. Thanks for catching that!

The `vsphere_vApp_container` resource can be used to create and manage
Virtual Appliances.

For more information on vSphere Virtual Appliances, see [this
Copy link
Contributor

Choose a reason for hiding this comment

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

Terminology also here. Might be worth it to scan the doc for all reference of "Virtual Appliance" and just replace with "vApp".

or standalone host, or a resource pool itself. When moving a vApp container
from one parent resource pool to another, both must share a common root
resource pool or the move will fail.
* `parent_folder_id` - (Optional) The [manage object ID][docs-about-morefs] of
Copy link
Contributor

Choose a reason for hiding this comment

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

s/manage/managed/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}
}

func testGetVAppContainer(s *terraform.State, resourceName string) (*object.VirtualApp, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be thrown into helper_test.go just in case it's needed by other tests other than vApp container tests?

This is where most of the other test helper code is stored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


[ref-vsphere-vapp]: https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.vm_admin.doc/GUID-2A95EBB8-1779-40FA-B4FB-4D0845750879.html

## Example Usage

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. That probably isn't as obvious if you haven't been looking at it for hours.

@bill-rich bill-rich force-pushed the f-vapp-container branch 3 times, most recently from e630566 to 3cdb5b3 Compare August 3, 2018 21:01
When a VM is part of a vApp, folder should be empty.
Add support moving into resource pools.
@@ -636,6 +652,11 @@ func resourceVSphereVirtualMachineCustomizeDiff(d *schema.ResourceDiff, meta int
if err := virtualdevice.DiskDiffOperation(d, client); err != nil {
return err
}
// When a VM is a member of a vApp container, it is no longer part of the VM
// tree, and therefor cannot have its VM folder set.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/therefor/therefore/

@bill-rich bill-rich merged commit d964862 into master Aug 6, 2018
@bill-rich bill-rich deleted the f-vapp-container branch August 6, 2018 17:43
@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants