|
| 1 | +/* |
| 2 | +Copyright (c) 2020 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 tags_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "fmt" |
| 22 | + |
| 23 | + "github.com/vmware/govmomi/simulator" |
| 24 | + "github.com/vmware/govmomi/vapi/rest" |
| 25 | + "github.com/vmware/govmomi/vapi/tags" |
| 26 | + "github.com/vmware/govmomi/vim25" |
| 27 | + |
| 28 | + _ "github.com/vmware/govmomi/vapi/simulator" |
| 29 | +) |
| 30 | + |
| 31 | +func ExampleManager_CreateTag() { |
| 32 | + simulator.Run(func(ctx context.Context, vc *vim25.Client) error { |
| 33 | + c := rest.NewClient(vc) |
| 34 | + _ = c.Login(ctx, simulator.DefaultLogin) |
| 35 | + |
| 36 | + m := tags.NewManager(c) |
| 37 | + |
| 38 | + id, err := m.CreateCategory(ctx, &tags.Category{ |
| 39 | + AssociableTypes: []string{"VirtualMachine"}, |
| 40 | + Cardinality: "SINGLE", |
| 41 | + Description: "This is My Category", |
| 42 | + Name: "my-category", |
| 43 | + }) |
| 44 | + if err != nil { |
| 45 | + return err |
| 46 | + } |
| 47 | + |
| 48 | + id, err = m.CreateTag(ctx, &tags.Tag{ |
| 49 | + CategoryID: id, |
| 50 | + Description: "This is My Tag", |
| 51 | + Name: "my-tag", |
| 52 | + }) |
| 53 | + if err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + |
| 57 | + tag, err := m.GetTag(ctx, id) |
| 58 | + if err != nil { |
| 59 | + return err |
| 60 | + } |
| 61 | + |
| 62 | + fmt.Println(tag.Name) |
| 63 | + return nil |
| 64 | + }) |
| 65 | + // Output: my-tag |
| 66 | +} |
0 commit comments