github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/flavors/doc.go (about) 1 /* 2 Package flavors provides information and interaction with the flavor API 3 in the OpenStack Compute service. 4 5 A flavor is an available hardware configuration for a server. Each flavor 6 has a unique combination of disk space, memory capacity and priority for CPU 7 time. 8 9 Example to List Flavors 10 11 listOpts := flavors.ListOpts{ 12 AccessType: flavors.PublicAccess, 13 } 14 15 allPages, err := flavors.ListDetail(computeClient, listOpts).AllPages() 16 if err != nil { 17 panic(err) 18 } 19 20 allFlavors, err := flavors.ExtractFlavors(allPages) 21 if err != nil { 22 panic(err) 23 } 24 25 for _, flavor := range allFlavors { 26 fmt.Printf("%+v\n", flavor) 27 } 28 29 Example to Create a Flavor 30 31 createOpts := flavors.CreateOpts{ 32 ID: "1", 33 Name: "m1.tiny", 34 Disk: golangsdk.IntToPointer(1), 35 RAM: 512, 36 VCPUs: 1, 37 RxTxFactor: 1.0, 38 } 39 40 flavor, err := flavors.Create(computeClient, createOpts).Extract() 41 if err != nil { 42 panic(err) 43 } 44 45 Example to List Flavor Access 46 47 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 48 49 allPages, err := flavors.ListAccesses(computeClient, flavorID).AllPages() 50 if err != nil { 51 panic(err) 52 } 53 54 allAccesses, err := flavors.ExtractAccesses(allPages) 55 if err != nil { 56 panic(err) 57 } 58 59 for _, access := range allAccesses { 60 fmt.Printf("%+v", access) 61 } 62 63 Example to Grant Access to a Flavor 64 65 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 66 67 accessOpts := flavors.AddAccessOpts{ 68 Tenant: "15153a0979884b59b0592248ef947921", 69 } 70 71 accessList, err := flavors.AddAccess(computeClient, flavor.ID, accessOpts).Extract() 72 if err != nil { 73 panic(err) 74 } 75 76 Example to Remove/Revoke Access to a Flavor 77 78 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 79 80 accessOpts := flavors.RemoveAccessOpts{ 81 Tenant: "15153a0979884b59b0592248ef947921", 82 } 83 84 accessList, err := flavors.RemoveAccess(computeClient, flavor.ID, accessOpts).Extract() 85 if err != nil { 86 panic(err) 87 } 88 89 Example to Create Extra Specs for a Flavor 90 91 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 92 93 createOpts := flavors.ExtraSpecsOpts{ 94 "hw:cpu_policy": "CPU-POLICY", 95 "hw:cpu_thread_policy": "CPU-THREAD-POLICY", 96 } 97 createdExtraSpecs, err := flavors.CreateExtraSpecs(computeClient, flavorID, createOpts).Extract() 98 if err != nil { 99 panic(err) 100 } 101 102 fmt.Printf("%+v", createdExtraSpecs) 103 104 Example to Get Extra Specs for a Flavor 105 106 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 107 108 extraSpecs, err := flavors.ListExtraSpecs(computeClient, flavorID).Extract() 109 if err != nil { 110 panic(err) 111 } 112 113 fmt.Printf("%+v", extraSpecs) 114 115 Example to Update Extra Specs for a Flavor 116 117 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 118 119 updateOpts := flavors.ExtraSpecsOpts{ 120 "hw:cpu_thread_policy": "CPU-THREAD-POLICY-UPDATED", 121 } 122 updatedExtraSpec, err := flavors.UpdateExtraSpec(computeClient, flavorID, updateOpts).Extract() 123 if err != nil { 124 panic(err) 125 } 126 127 fmt.Printf("%+v", updatedExtraSpec) 128 129 Example to Delete an Extra Spec for a Flavor 130 131 flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" 132 err := flavors.DeleteExtraSpec(computeClient, flavorID, "hw:cpu_thread_policy").ExtractErr() 133 if err != nil { 134 panic(err) 135 } 136 */ 137 package flavors