1- /*
2- Copyright (c) 2020-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- */
1+ // © Broadcom. All Rights Reserved.
2+ // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+ // SPDX-License-Identifier: Apache-2.0
164
175package policy
186
@@ -23,17 +11,18 @@ import (
2311
2412 "github.com/vmware/govmomi/cli"
2513 "github.com/vmware/govmomi/cli/flags"
14+ "github.com/vmware/govmomi/pbm"
2615 "github.com/vmware/govmomi/pbm/types"
27- vim "github.com/vmware/govmomi/vim25/types"
2816)
2917
3018type create struct {
3119 * flags.ClientFlag
3220
33- spec types. PbmCapabilityProfileCreateSpec
21+ spec pbm. CapabilityProfileCreateSpec
3422 tag string
3523 cat string
3624 zone bool
25+ enc bool
3726}
3827
3928func init () {
@@ -47,6 +36,7 @@ func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
4736 f .StringVar (& cmd .spec .Description , "d" , "" , "Description" )
4837 f .StringVar (& cmd .tag , "tag" , "" , "Tag" )
4938 f .StringVar (& cmd .cat , "category" , "" , "Category" )
39+ f .BoolVar (& cmd .enc , "e" , false , "Enable encryption" )
5040 f .BoolVar (& cmd .zone , "z" , false , "Enable Zonal topology for multi-zone Supervisor" )
5141}
5242
@@ -69,70 +59,60 @@ func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
6959
7060 cmd .spec .Name = f .Arg (0 )
7161 cmd .spec .Category = string (types .PbmProfileCategoryEnumREQUIREMENT )
72- cmd .spec .ResourceType .ResourceType = string (types .PbmProfileResourceTypeEnumSTORAGE )
7362
74- if cmd .tag == "" && ! cmd .zone {
63+ if cmd .tag == "" && ! cmd .zone && ! cmd . enc {
7564 return flag .ErrHelp
7665 }
7766
78- var profiles []types.PbmCapabilitySubProfile
79-
8067 if cmd .tag != "" {
81- id := fmt .Sprintf ("com.vmware.storage.tag.%s.property" , cmd .cat )
82- instance := types.PbmCapabilityInstance {
83- Id : types.PbmCapabilityMetadataUniqueId {
84- Namespace : "http://www.vmware.com/storage/tag" ,
85- Id : cmd .cat ,
86- },
87- Constraint : []types.PbmCapabilityConstraintInstance {{
88- PropertyInstance : []types.PbmCapabilityPropertyInstance {{
89- Id : id ,
90- Value : types.PbmCapabilityDiscreteSet {
91- Values : []vim.AnyType {cmd .tag },
92- },
93- }},
68+ cmd .spec .CapabilityList = append (cmd .spec .CapabilityList , pbm.Capability {
69+ ID : cmd .cat ,
70+ Namespace : "http://www.vmware.com/storage/tag" ,
71+ PropertyList : []pbm.Property {{
72+ ID : fmt .Sprintf ("com.vmware.storage.tag.%s.property" , cmd .cat ),
73+ Value : cmd .tag ,
74+ DataType : "set" ,
9475 }},
95- }
96- profiles = append (profiles , types.PbmCapabilitySubProfile {
97- Name : "Tag based placement" ,
98- Capability : []types.PbmCapabilityInstance {instance },
9976 })
10077 }
10178
10279 if cmd .zone {
103- instance := types.PbmCapabilityInstance {
104- Id : types.PbmCapabilityMetadataUniqueId {
105- Namespace : "com.vmware.storage.consumptiondomain" ,
106- Id : "StorageTopology" ,
107- },
108- Constraint : []types.PbmCapabilityConstraintInstance {
109- {
110- PropertyInstance : []types.PbmCapabilityPropertyInstance {
111- {
112- Id : "StorageTopologyType" ,
113- Operator : "" ,
114- Value : "Zonal" ,
115- },
116- },
117- },
118- },
119- }
120- profiles = append (profiles , types.PbmCapabilitySubProfile {
121- Name : "Consumption domain" ,
122- Capability : []types.PbmCapabilityInstance {instance },
80+ cmd .spec .CapabilityList = append (cmd .spec .CapabilityList , pbm.Capability {
81+ ID : "StorageTopology" ,
82+ Namespace : "com.vmware.storage.consumptiondomain" ,
83+ PropertyList : []pbm.Property {{
84+ ID : "StorageTopologyType" ,
85+ Value : "Zonal" ,
86+ DataType : "string" ,
87+ }},
12388 })
12489 }
12590
126- cmd .spec .Constraints = & types.PbmCapabilitySubProfileConstraints {
127- SubProfiles : profiles ,
91+ if cmd .enc {
92+ const encryptionCapabilityID = "ad5a249d-cbc2-43af-9366-694d7664fa52"
93+
94+ cmd .spec .CapabilityList = append (cmd .spec .CapabilityList , pbm.Capability {
95+ ID : encryptionCapabilityID ,
96+ Namespace : "com.vmware.storageprofile.dataservice" ,
97+ PropertyList : []pbm.Property {{
98+ ID : encryptionCapabilityID ,
99+ Value : encryptionCapabilityID ,
100+ DataType : "string" ,
101+ }},
102+ })
128103 }
129104
130105 c , err := cmd .PbmClient ()
131106 if err != nil {
132107 return err
133108 }
134109
135- pid , err := c .CreateProfile (ctx , cmd .spec )
110+ spec , err := pbm .CreateCapabilityProfileSpec (cmd .spec )
111+ if err != nil {
112+ return err
113+ }
114+
115+ pid , err := c .CreateProfile (ctx , * spec )
136116 if err != nil {
137117 return err
138118 }
0 commit comments