vsphere/internal/helper/dvportgroup/distributed_port_group_helper.go
func FromKey(client *govmomi.Client, dvsUUID, pgKey string) (*object.DistributedVirtualPortgroup, error) {
	dvsm := types.ManagedObjectReference{Type: "DistributedVirtualSwitchManager", Value: "DVSManager"}
	req := &types.DVSManagerLookupDvPortGroup{
		This:         dvsm,
		SwitchUuid:   dvsUUID,
		PortgroupKey: pgKey,
	}
	ctx, cancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout)
	defer cancel()
	resp, err := methods.DVSManagerLookupDvPortGroup(ctx, client, req)
	if err != nil {
		return nil, err
	}

	if resp.Returnval == nil {
		return nil, NewMissingPortGroupReferenceError(
			fmt.Sprintf(
				"portgroup lookup by key returned nil result for DVS UUID %q and portgroup key %q",
				dvsUUID,
				pgKey,
			),
		)
	}

	return FromMOID(client, resp.Returnval.Reference().Value)
}
func FromKey(client *govmomi.Client, dvsUUID, pgKey string) (*object.DistributedVirtualPortgroup, error) {
	dvsm := types.ManagedObjectReference{Type: "DistributedVirtualSwitchManager", Value: "DVSManager"}
	req := &types.DVSManagerLookupDvPortGroup{
		This:         dvsm,
		SwitchUuid:   dvsUUID,
		PortgroupKey: pgKey,
	}
	ctx, cancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout)
	defer cancel()
	resp, err := methods.DVSManagerLookupDvPortGroup(ctx, client, req)
	if err != nil {
		return nil, err
	}

	if resp.Returnval == nil {
		return nil, NewMissingPortGroupReferenceError(
			fmt.Sprintf(
				"portgroup lookup by key returned nil result for DVS UUID %q and portgroup key %q",
				dvsUUID,
				pgKey,
			),
		)
	}

	return FromMOID(client, resp.Returnval.Reference().Value)
}
// FromKey gets a portgroup object from its key.