@@ -29,6 +29,8 @@ func (c *client) listVolumes(p *cloudstack.ListVolumesParams) (*Volume, error) {
2929 Name : vol .Name ,
3030 Size : vol .Size ,
3131 DiskOfferingID : vol .Diskofferingid ,
32+ DomainID : vol .Domainid ,
33+ ProjectID : vol .Projectid ,
3234 ZoneID : vol .Zoneid ,
3335 VirtualMachineID : vol .Virtualmachineid ,
3436 DeviceID : strconv .FormatInt (vol .Deviceid , 10 ),
@@ -153,3 +155,34 @@ func (c *client) ExpandVolume(ctx context.Context, volumeID string, newSizeInGB
153155
154156 return nil
155157}
158+
159+ func (c * client ) CreateVolumeFromSnapshot (ctx context.Context , diskOfferingID , zoneID , name , domainID , projectID , snapshotID string , sizeInGB int64 ) (string , error ) {
160+ logger := klog .FromContext (ctx )
161+ snapshot , _ , err := c .Snapshot .GetSnapshotByID (snapshotID )
162+ if err != nil {
163+ return "" , fmt .Errorf ("failed to retrieve snapshot '%s': %w" , snapshotID , err )
164+ }
165+
166+ p := c .Volume .NewCreateVolumeParams ()
167+ p .SetDiskofferingid (diskOfferingID )
168+ p .SetZoneid (zoneID )
169+ if projectID != "" {
170+ p .SetProjectid (projectID )
171+ }
172+ p .SetName (name )
173+ p .SetSnapshotid (snapshot .Id )
174+
175+ logger .V (2 ).Info ("CloudStack API call" , "command" , "CreateVolume" , "params" , map [string ]string {
176+ "name" : name ,
177+ "snapshotid" : snapshotID ,
178+ "projectid" : projectID ,
179+ })
180+ // Execute the API call to create volume from snapshot
181+ vol , err := c .Volume .CreateVolume (p )
182+ if err != nil {
183+ // Handle the error accordingly
184+ return "" , fmt .Errorf ("failed to create volume from snapshot'%s': %w" , snapshotID , err )
185+ }
186+
187+ return vol .Id , err
188+ }
0 commit comments