Skip to content

Commit

Permalink
Merge pull request #802 from akutz/feature/deploy-ovf-activation-id
Browse files Browse the repository at this point in the history
🌱 Use VAPI ActivationID with DeployOVF
  • Loading branch information
akutz authored Nov 14, 2024
2 parents 47b7bd7 + 15b6bfc commit 8982df8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
10 changes: 4 additions & 6 deletions pkg/providers/vsphere/virtualmachine/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package virtualmachine

import (
"fmt"
"net/http"

"github.com/vmware/govmomi/vapi/rest"
"github.com/vmware/govmomi/vapi/vcenter"
Expand All @@ -14,14 +13,12 @@ import (

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
pkgutil "github.com/vmware-tanzu/vm-operator/pkg/util"
)

const (
sourceVirtualMachineType = "VirtualMachine"

// vAPICtxActIDHttpHeader represents the http header in vAPI to pass down the activation ID.
vAPICtxActIDHttpHeader = "vapi-ctx-actid"

itemDescriptionFormat = "virtualmachinepublishrequest.vmoperator.vmware.com: %s\n"
)

Expand Down Expand Up @@ -59,6 +56,7 @@ func CreateOVF(

// Use vmpublish uid as the act id passed down to the content library service, so that we can track
// the task status by the act id.
ctxHeader := client.WithHeader(vmCtx, http.Header{vAPICtxActIDHttpHeader: []string{actID}})
return vcenter.NewManager(client).CreateOVF(ctxHeader, ovf)
return vcenter.NewManager(client).CreateOVF(
pkgutil.WithVAPIActivationID(vmCtx, client, actID),
ovf)
}
5 changes: 4 additions & 1 deletion pkg/providers/vsphere/vmlifecycle/create_contentlibrary.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func deployOVF(

vmCtx.Logger.Info("Deploying OVF Library Item", "itemID", item.ID, "itemName", item.Name, "deploy", deploy)

return vcenter.NewManager(restClient).DeployLibraryItem(vmCtx, item.ID, deploy)
return vcenter.NewManager(restClient).DeployLibraryItem(
util.WithVAPIActivationID(vmCtx, restClient, vmCtx.VM.Spec.InstanceUUID),
item.ID,
deploy)
}

func createVM(
Expand Down
29 changes: 29 additions & 0 deletions pkg/util/vapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package util

import (
"context"
"net/http"

"github.com/vmware/govmomi/vapi/rest"
)

// vapiActivationIDHeader is the HTTP header to pass to a VAPI API in order
// to influence the activationID of the vim.Task spawned by the VAPI API.
const vapiActivationIDHeader = "vapi-ctx-actid"

// WithVAPIActivationID adds the specified id to the context to be used as the
// VAPI REST client's activation ID -- the value assigned to the activationId
// field to the vim.Task the VAPI API may spawn.
func WithVAPIActivationID(
ctx context.Context,
client *rest.Client,
id string) context.Context {

return client.WithHeader(
ctx,
http.Header{vapiActivationIDHeader: []string{id}},
)
}

0 comments on commit 8982df8

Please sign in to comment.