github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/blockstorage/v2/volumes/doc.go (about) 1 /* 2 Package volumes provides information and interaction with volumes in the 3 OpenStack Block Storage service. A volume is a detachable block storage 4 device, akin to a USB hard drive. It can only be attached to one instance at 5 a time. 6 7 Example of creating Volume B on a Different Host than Volume A 8 9 schedulerHintOpts := volumes.SchedulerHintCreateOpts{ 10 DifferentHost: []string{ 11 "volume-a-uuid", 12 } 13 } 14 15 createOpts := volumes.CreateOpts{ 16 Name: "volume_b", 17 Size: 10, 18 } 19 20 volume, err := volumes.Create(context.TODO(), computeClient, createOpts, schedulerHintOpts).Extract() 21 if err != nil { 22 panic(err) 23 } 24 25 Example of creating Volume B on the Same Host as Volume A 26 27 schedulerHintOpts := volumes.SchedulerHintCreateOpts{ 28 SameHost: []string{ 29 "volume-a-uuid", 30 } 31 } 32 33 createOpts := volumes.CreateOpts{ 34 Name: "volume_b", 35 Size: 10 36 } 37 38 volume, err := volumes.Create(context.TODO(), computeClient, createOpts, schedulerHintOpts).Extract() 39 if err != nil { 40 panic(err) 41 } 42 43 Example of Creating an Image from a Volume 44 45 uploadImageOpts := volumes.UploadImageOpts{ 46 ImageName: "my_vol", 47 Force: true, 48 } 49 50 volumeImage, err := volumes.UploadImage(context.TODO(), client, volume.ID, uploadImageOpts).Extract() 51 if err != nil { 52 panic(err) 53 } 54 55 fmt.Printf("%+v\n", volumeImage) 56 57 Example of Extending a Volume's Size 58 59 extendOpts := volumes.ExtendSizeOpts{ 60 NewSize: 100, 61 } 62 63 err := volumes.ExtendSize(context.TODO(), client, volume.ID, extendOpts).ExtractErr() 64 if err != nil { 65 panic(err) 66 } 67 68 Example of Initializing a Volume Connection 69 70 connectOpts := &volumes.InitializeConnectionOpts{ 71 IP: "127.0.0.1", 72 Host: "stack", 73 Initiator: "iqn.1994-05.com.redhat:17cf566367d2", 74 Multipath: gophercloud.Disabled, 75 Platform: "x86_64", 76 OSType: "linux2", 77 } 78 79 connectionInfo, err := volumes.InitializeConnection(context.TODO(), client, volume.ID, connectOpts).Extract() 80 if err != nil { 81 panic(err) 82 } 83 84 fmt.Printf("%+v\n", connectionInfo["data"]) 85 86 terminateOpts := &volumes.InitializeConnectionOpts{ 87 IP: "127.0.0.1", 88 Host: "stack", 89 Initiator: "iqn.1994-05.com.redhat:17cf566367d2", 90 Multipath: gophercloud.Disabled, 91 Platform: "x86_64", 92 OSType: "linux2", 93 } 94 95 err = volumes.TerminateConnection(context.TODO(), client, volume.ID, terminateOpts).ExtractErr() 96 if err != nil { 97 panic(err) 98 } 99 100 Example of Setting a Volume's Bootable status 101 102 options := volumes.BootableOpts{ 103 Bootable: true, 104 } 105 106 err := volumes.SetBootable(context.TODO(), client, volume.ID, options).ExtractErr() 107 if err != nil { 108 panic(err) 109 } 110 111 Example of Changing Type of a Volume 112 113 changeTypeOpts := volumes.ChangeTypeOpts{ 114 NewType: "ssd", 115 MigrationPolicy: volumes.MigrationPolicyOnDemand, 116 } 117 118 err = volumes.ChangeType(context.TODO(), client, volumeID, changeTypeOpts).ExtractErr() 119 if err != nil { 120 panic(err) 121 } 122 123 Example of Attaching a Volume to an Instance 124 125 attachOpts := volumes.AttachOpts{ 126 MountPoint: "/mnt", 127 Mode: "rw", 128 InstanceUUID: server.ID, 129 } 130 131 err := volumes.Attach(context.TODO(), client, volume.ID, attachOpts).ExtractErr() 132 if err != nil { 133 panic(err) 134 } 135 136 detachOpts := volumes.DetachOpts{ 137 AttachmentID: volume.Attachments[0].AttachmentID, 138 } 139 140 err = volumes.Detach(context.TODO(), client, volume.ID, detachOpts).ExtractErr() 141 if err != nil { 142 panic(err) 143 } 144 */ 145 package volumes