Skip to content

Commit 321b6f0

Browse files
Merge pull request #3618 from nikolay-andreev/feature/cns-volume-crypto-bindings
cns: Support encryption/re-encryption of volumes
2 parents 8f2493a + 3e8e2e5 commit 321b6f0

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

cns/methods/unreleased.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package methods
18+
19+
import (
20+
"context"
21+
22+
"github.com/vmware/govmomi/cns/types"
23+
"github.com/vmware/govmomi/vim25/soap"
24+
)
25+
26+
type CnsUpdateVolumeCryptoBody struct {
27+
Req *types.CnsUpdateVolumeCrypto `xml:"urn:vsan CnsUpdateVolumeCrypto,omitempty"`
28+
Res *types.CnsUpdateVolumeCryptoResponse `xml:"urn:vsan CnsUpdateVolumeCryptoResponse,omitempty"`
29+
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
30+
}
31+
32+
func (b *CnsUpdateVolumeCryptoBody) Fault() *soap.Fault { return b.Fault_ }
33+
34+
func CnsUpdateVolumeCrypto(ctx context.Context, r soap.RoundTripper, req *types.CnsUpdateVolumeCrypto) (*types.CnsUpdateVolumeCryptoResponse, error) {
35+
var reqBody, resBody CnsUpdateVolumeCryptoBody
36+
37+
reqBody.Req = req
38+
39+
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
40+
return nil, err
41+
}
42+
43+
return resBody.Res, nil
44+
}

cns/types/unreleased_types.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,41 @@ type CnsBlockCreateSpec struct {
2828

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

3434
func init() {
3535
types.Add("CnsBlockCreateSpec", reflect.TypeOf((*CnsBlockCreateSpec)(nil)).Elem())
3636
}
37+
38+
type CnsUpdateVolumeCryptoRequestType struct {
39+
This types.ManagedObjectReference `xml:"_this"`
40+
UpdateSpecs []CnsVolumeCryptoUpdateSpec `xml:"updateSpecs,omitempty"`
41+
}
42+
43+
func init() {
44+
types.Add("CnsUpdateVolumeCryptoRequestType", reflect.TypeOf((*CnsUpdateVolumeCryptoRequestType)(nil)).Elem())
45+
}
46+
47+
type CnsUpdateVolumeCrypto CnsUpdateVolumeCryptoRequestType
48+
49+
func init() {
50+
types.Add("CnsUpdateVolumeCrypto", reflect.TypeOf((*CnsUpdateVolumeCrypto)(nil)).Elem())
51+
}
52+
53+
type CnsUpdateVolumeCryptoResponse struct {
54+
Returnval types.ManagedObjectReference `xml:"returnval"`
55+
}
56+
57+
// CnsVolumeCryptoUpdateSpec is the specification for volume crypto update operation.
58+
type CnsVolumeCryptoUpdateSpec struct {
59+
types.DynamicData
60+
61+
VolumeId CnsVolumeId `xml:"volumeId"`
62+
Profile []types.BaseVirtualMachineProfileSpec `xml:"profile,omitempty,typeattr"`
63+
DisksCrypto *types.DiskCryptoSpec `xml:"disksCrypto,omitempty"`
64+
}
65+
66+
func init() {
67+
types.Add("CnsVolumeCryptoUpdateSpec", reflect.TypeOf((*CnsVolumeCryptoUpdateSpec)(nil)).Elem())
68+
}

cns/unreleased_client.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cns
18+
19+
import (
20+
"context"
21+
22+
"github.com/vmware/govmomi/cns/methods"
23+
cnstypes "github.com/vmware/govmomi/cns/types"
24+
"github.com/vmware/govmomi/object"
25+
)
26+
27+
// UpdateVolumeCrypto updates container volumes with given crypto specifications.
28+
func (c *Client) UpdateVolumeCrypto(ctx context.Context, updateSpecList []cnstypes.CnsVolumeCryptoUpdateSpec) (*object.Task, error) {
29+
req := cnstypes.CnsUpdateVolumeCrypto{
30+
This: CnsVolumeManagerInstance,
31+
UpdateSpecs: updateSpecList,
32+
}
33+
res, err := methods.CnsUpdateVolumeCrypto(ctx, c, &req)
34+
if err != nil {
35+
return nil, err
36+
}
37+
return object.NewTask(c.vim25Client, res.Returnval), nil
38+
}

0 commit comments

Comments
 (0)