github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/keypairs/doc.go (about) 1 /* 2 Package keypairs provides the ability to manage key pairs as well as create 3 servers with a specified key pair. 4 5 Example to List Key Pairs 6 7 allPages, err := keypairs.List(computeClient).AllPages() 8 if err != nil { 9 panic(err) 10 } 11 12 allKeyPairs, err := keypairs.ExtractKeyPairs(allPages) 13 if err != nil { 14 panic(err) 15 } 16 17 for _, kp := range allKeyPairs { 18 fmt.Printf("%+v\n", kp) 19 } 20 21 Example to Create a Key Pair 22 23 createOpts := keypairs.CreateOpts{ 24 Name: "keypair-name", 25 } 26 27 keypair, err := keypairs.Create(computeClient, createOpts).Extract() 28 if err != nil { 29 panic(err) 30 } 31 32 fmt.Printf("%+v", keypair) 33 34 Example to Import a Key Pair 35 36 createOpts := keypairs.CreateOpts{ 37 Name: "keypair-name", 38 PublicKey: "public-key", 39 } 40 41 keypair, err := keypairs.Create(computeClient, createOpts).Extract() 42 if err != nil { 43 panic(err) 44 } 45 46 Example to Delete a Key Pair 47 48 err := keypairs.Delete(computeClient, "keypair-name").ExtractErr() 49 if err != nil { 50 panic(err) 51 } 52 53 Example to Create a Server With a Key Pair 54 55 serverCreateOpts := servers.CreateOpts{ 56 Name: "server_name", 57 ImageRef: "image-uuid", 58 FlavorRef: "flavor-uuid", 59 } 60 61 createOpts := keypairs.CreateOptsExt{ 62 CreateOptsBuilder: serverCreateOpts, 63 KeyName: "keypair-name", 64 } 65 66 server, err := servers.Create(computeClient, createOpts).Extract() 67 if err != nil { 68 panic(err) 69 } 70 */ 71 package keypairs