Skip to content

Commit

Permalink
cns: Support encryption/re-encryption of volumes
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Andreev <nandreev@vmware.com>
  • Loading branch information
Nikolay Andreev committed Nov 8, 2024
1 parent a2c22f0 commit 3e8e2e5
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
44 changes: 44 additions & 0 deletions cns/methods/unreleased.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package methods

import (
"context"

"github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/vim25/soap"
)

type CnsUpdateVolumeCryptoBody struct {
Req *types.CnsUpdateVolumeCrypto `xml:"urn:vsan CnsUpdateVolumeCrypto,omitempty"`
Res *types.CnsUpdateVolumeCryptoResponse `xml:"urn:vsan CnsUpdateVolumeCryptoResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}

func (b *CnsUpdateVolumeCryptoBody) Fault() *soap.Fault { return b.Fault_ }

func CnsUpdateVolumeCrypto(ctx context.Context, r soap.RoundTripper, req *types.CnsUpdateVolumeCrypto) (*types.CnsUpdateVolumeCryptoResponse, error) {
var reqBody, resBody CnsUpdateVolumeCryptoBody

reqBody.Req = req

if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}

return resBody.Res, nil
}
34 changes: 33 additions & 1 deletion cns/types/unreleased_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,41 @@ type CnsBlockCreateSpec struct {

// Crypto specifies the encryption settings for the volume to be created.
// Works with block volumes only.
CryptoSpec *types.CryptoSpec `xml:"cryptoSpec,omitempty"`
CryptoSpec types.BaseCryptoSpec `xml:"cryptoSpec,omitempty,typeattr"`
}

func init() {
types.Add("CnsBlockCreateSpec", reflect.TypeOf((*CnsBlockCreateSpec)(nil)).Elem())
}

type CnsUpdateVolumeCryptoRequestType struct {
This types.ManagedObjectReference `xml:"_this"`
UpdateSpecs []CnsVolumeCryptoUpdateSpec `xml:"updateSpecs,omitempty"`
}

func init() {
types.Add("CnsUpdateVolumeCryptoRequestType", reflect.TypeOf((*CnsUpdateVolumeCryptoRequestType)(nil)).Elem())
}

type CnsUpdateVolumeCrypto CnsUpdateVolumeCryptoRequestType

func init() {
types.Add("CnsUpdateVolumeCrypto", reflect.TypeOf((*CnsUpdateVolumeCrypto)(nil)).Elem())
}

type CnsUpdateVolumeCryptoResponse struct {
Returnval types.ManagedObjectReference `xml:"returnval"`
}

// CnsVolumeCryptoUpdateSpec is the specification for volume crypto update operation.
type CnsVolumeCryptoUpdateSpec struct {
types.DynamicData

VolumeId CnsVolumeId `xml:"volumeId"`
Profile []types.BaseVirtualMachineProfileSpec `xml:"profile,omitempty,typeattr"`
DisksCrypto *types.DiskCryptoSpec `xml:"disksCrypto,omitempty"`
}

func init() {
types.Add("CnsVolumeCryptoUpdateSpec", reflect.TypeOf((*CnsVolumeCryptoUpdateSpec)(nil)).Elem())
}
38 changes: 38 additions & 0 deletions cns/unreleased_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cns

import (
"context"

"github.com/vmware/govmomi/cns/methods"
cnstypes "github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/object"
)

// UpdateVolumeCrypto updates container volumes with given crypto specifications.
func (c *Client) UpdateVolumeCrypto(ctx context.Context, updateSpecList []cnstypes.CnsVolumeCryptoUpdateSpec) (*object.Task, error) {
req := cnstypes.CnsUpdateVolumeCrypto{
This: CnsVolumeManagerInstance,
UpdateSpecs: updateSpecList,
}
res, err := methods.CnsUpdateVolumeCrypto(ctx, c, &req)
if err != nil {
return nil, err
}
return object.NewTask(c.vim25Client, res.Returnval), nil
}

0 comments on commit 3e8e2e5

Please sign in to comment.