github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/blockstorage/v3/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 a Volume from a Backup 44 45 backupID := "20c792f0-bb03-434f-b653-06ef238e337e" 46 options := volumes.CreateOpts{ 47 Name: "vol-001", 48 BackupID: &backupID, 49 } 50 51 client.Microversion = "3.47" 52 volume, err := volumes.Create(context.TODO(), client, options, nil).Extract() 53 if err != nil { 54 panic(err) 55 } 56 57 fmt.Println(volume) 58 59 Example of Creating an Image from a Volume 60 61 uploadImageOpts := volumes.UploadImageOpts{ 62 ImageName: "my_vol", 63 Force: true, 64 } 65 66 volumeImage, err := volumes.UploadImage(context.TODO(), client, volume.ID, uploadImageOpts).Extract() 67 if err != nil { 68 panic(err) 69 } 70 71 fmt.Printf("%+v\n", volumeImage) 72 73 Example of Extending a Volume's Size 74 75 extendOpts := volumes.ExtendSizeOpts{ 76 NewSize: 100, 77 } 78 79 err := volumes.ExtendSize(context.TODO(), client, volume.ID, extendOpts).ExtractErr() 80 if err != nil { 81 panic(err) 82 } 83 84 Example of Initializing a Volume Connection 85 86 connectOpts := &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 connectionInfo, err := volumes.InitializeConnection(context.TODO(), client, volume.ID, connectOpts).Extract() 96 if err != nil { 97 panic(err) 98 } 99 100 fmt.Printf("%+v\n", connectionInfo["data"]) 101 102 terminateOpts := &volumes.InitializeConnectionOpts{ 103 IP: "127.0.0.1", 104 Host: "stack", 105 Initiator: "iqn.1994-05.com.redhat:17cf566367d2", 106 Multipath: gophercloud.Disabled, 107 Platform: "x86_64", 108 OSType: "linux2", 109 } 110 111 err = volumes.TerminateConnection(context.TODO(), client, volume.ID, terminateOpts).ExtractErr() 112 if err != nil { 113 panic(err) 114 } 115 116 Example of Setting a Volume's Bootable status 117 118 options := volumes.BootableOpts{ 119 Bootable: true, 120 } 121 122 err := volumes.SetBootable(context.TODO(), client, volume.ID, options).ExtractErr() 123 if err != nil { 124 panic(err) 125 } 126 127 Example of Changing Type of a Volume 128 129 changeTypeOpts := volumes.ChangeTypeOpts{ 130 NewType: "ssd", 131 MigrationPolicy: volumes.MigrationPolicyOnDemand, 132 } 133 134 err = volumes.ChangeType(context.TODO(), client, volumeID, changeTypeOpts).ExtractErr() 135 if err != nil { 136 panic(err) 137 } 138 139 Example of Attaching a Volume to an Instance 140 141 attachOpts := volumes.AttachOpts{ 142 MountPoint: "/mnt", 143 Mode: "rw", 144 InstanceUUID: server.ID, 145 } 146 147 err := volumes.Attach(context.TODO(), client, volume.ID, attachOpts).ExtractErr() 148 if err != nil { 149 panic(err) 150 } 151 152 detachOpts := volumes.DetachOpts{ 153 AttachmentID: volume.Attachments[0].AttachmentID, 154 } 155 156 err = volumes.Detach(context.TODO(), client, volume.ID, detachOpts).ExtractErr() 157 if err != nil { 158 panic(err) 159 } 160 */ 161 package volumes