Skip to content

Commit 632c7b6

Browse files
authored
Merge pull request #143 from aleofreddi/master
Add source-volume and source-snapshot flags to the create volume command
2 parents 5caed9b + c0f7fc9 commit 632c7b6

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

csc/cmd/controller_create_volume.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"errors"
56
"os"
67

78
log "github.com/sirupsen/logrus"
@@ -11,10 +12,12 @@ import (
1112
)
1213

1314
var createVolume struct {
14-
reqBytes int64
15-
limBytes int64
16-
caps volumeCapabilitySliceArg
17-
params mapOfStringArg
15+
reqBytes int64
16+
limBytes int64
17+
caps volumeCapabilitySliceArg
18+
params mapOfStringArg
19+
sourceVol string
20+
sourceSnap string
1821
}
1922

2023
var createVolumeCmd = &cobra.Command{
@@ -52,6 +55,28 @@ CREATING MULTIPLE VOLUMES
5255
}
5356
}
5457

58+
if createVolume.sourceVol != "" && createVolume.sourceSnap != "" {
59+
return errors.New(
60+
"--source-volume and --source-snapshot are mutually exclusive")
61+
}
62+
if createVolume.sourceVol != "" {
63+
req.VolumeContentSource = &csi.VolumeContentSource{
64+
Type: &csi.VolumeContentSource_Volume{
65+
Volume: &csi.VolumeContentSource_VolumeSource{
66+
VolumeId: createVolume.sourceVol,
67+
},
68+
},
69+
}
70+
} else if createVolume.sourceSnap != "" {
71+
req.VolumeContentSource = &csi.VolumeContentSource{
72+
Type: &csi.VolumeContentSource_Snapshot{
73+
Snapshot: &csi.VolumeContentSource_SnapshotSource{
74+
SnapshotId: createVolume.sourceSnap,
75+
},
76+
},
77+
}
78+
}
79+
5580
for i := range args {
5681
ctx, cancel := context.WithTimeout(root.ctx, root.timeout)
5782
defer cancel()
@@ -84,6 +109,18 @@ func init() {
84109

85110
flagVolumeCapabilities(createVolumeCmd.Flags(), &createVolume.caps)
86111

112+
createVolumeCmd.Flags().StringVar(
113+
&createVolume.sourceVol,
114+
"source-volume",
115+
"",
116+
"Pre-populate data using a source volume")
117+
118+
createVolumeCmd.Flags().StringVar(
119+
&createVolume.sourceSnap,
120+
"source-snapshot",
121+
"",
122+
"Pre-populate data using a source snapshot")
123+
87124
flagWithRequiresVolContext(
88125
createVolumeCmd.Flags(),
89126
&root.withRequiresVolContext,

0 commit comments

Comments
 (0)