-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add create empty volume cmd * add list volume and delete volume cmd * add attach volume cmd and mount on run `ops volume attach` lets user attach volume to a stopped instance. as of this commit, `ops run` overwrite this config though. `ops run --mounts` lets user mount volume to an instance on run, but does not persist the config. as of this commit, changes made to volume during run is visible, but gets discarded on subsequent run without `--skipbuild` * mount non-empty volume on run * clean up
- Loading branch information
1 parent
5c64d11
commit 7ebc83e
Showing
11 changed files
with
774 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"path" | ||
|
||
api "github.com/nanovms/ops/lepton" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func volumeCreateCommandHandler(cmd *cobra.Command, args []string) { | ||
name := args[0] | ||
if name == "" { | ||
log.Fatal("name required") | ||
} | ||
data, _ := cmd.Flags().GetString("data") | ||
size, _ := cmd.Flags().GetString("size") | ||
config, _ := cmd.Flags().GetString("config") | ||
provider, _ := cmd.Flags().GetString("provider") | ||
nightly, _ := cmd.Flags().GetBool("nightly") | ||
|
||
conf := unWarpConfig(config) | ||
conf.NightlyBuild = nightly | ||
var err error | ||
var version string | ||
if conf.NightlyBuild { | ||
version, err = downloadNightlyImages(conf) | ||
} else { | ||
version, err = downloadReleaseImages() | ||
} | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if conf.Mkfs == "" { | ||
conf.Mkfs = path.Join(api.GetOpsHome(), version, "mkfs") | ||
} | ||
|
||
vol := api.NewVolume(conf) | ||
err = vol.Create(name, data, size, provider) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func volumeCreateCommand() *cobra.Command { | ||
var data string | ||
var size string | ||
cmdVolumeCreate := &cobra.Command{ | ||
Use: "create <volume_name>", | ||
Short: "create volume", | ||
Run: volumeCreateCommandHandler, | ||
Args: cobra.MinimumNArgs(1), | ||
} | ||
cmdVolumeCreate.PersistentFlags().StringVarP(&data, "data", "d", "", "volume data source") | ||
cmdVolumeCreate.PersistentFlags().StringVarP(&size, "size", "s", "", "volume initial size") | ||
return cmdVolumeCreate | ||
} | ||
|
||
func volumeListCommandHandler(cmd *cobra.Command, args []string) { | ||
config, _ := cmd.Flags().GetString("config") | ||
conf := unWarpConfig(config) | ||
vol := api.NewVolume(conf) | ||
err := vol.GetAll() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func volumeListCommand() *cobra.Command { | ||
cmdVolumeList := &cobra.Command{ | ||
Use: "list", | ||
Short: "list volume", | ||
Run: volumeListCommandHandler, | ||
} | ||
return cmdVolumeList | ||
} | ||
|
||
func volumeDeleteCommandHandler(cmd *cobra.Command, args []string) { | ||
id := args[0] | ||
config, _ := cmd.Flags().GetString("config") | ||
conf := unWarpConfig(config) | ||
vol := api.NewVolume(conf) | ||
err := vol.Delete(id) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func volumeDeleteCommand() *cobra.Command { | ||
cmdVolumeDelete := &cobra.Command{ | ||
Use: "delete <volume_id>", | ||
Short: "delete volume", | ||
Run: volumeDeleteCommandHandler, | ||
Args: cobra.MinimumNArgs(1), | ||
} | ||
return cmdVolumeDelete | ||
} | ||
|
||
func volumeAttachCommandHandler(cmd *cobra.Command, args []string) { | ||
image := args[0] | ||
id := args[1] | ||
mount := args[2] | ||
config, _ := cmd.Flags().GetString("config") | ||
conf := unWarpConfig(config) | ||
vol := api.NewVolume(conf) | ||
err := vol.Attach(image, id, mount) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func volumeAttachCommand() *cobra.Command { | ||
cmdVolumeAttach := &cobra.Command{ | ||
Use: "attach <image_name> <volume_id> <mount_path>", | ||
Short: "attach volume", | ||
Run: volumeAttachCommandHandler, | ||
Args: cobra.MinimumNArgs(3), | ||
} | ||
return cmdVolumeAttach | ||
} | ||
|
||
// VolumeCommands handles volumes related operations | ||
func VolumeCommands() *cobra.Command { | ||
var config string | ||
var provider string | ||
var nightly bool | ||
cmdVolume := &cobra.Command{ | ||
Use: "volume", | ||
Short: "manage nanos volumes", | ||
ValidArgs: []string{"create, list, delete, attach"}, | ||
Args: cobra.OnlyValidArgs, | ||
} | ||
cmdVolume.PersistentFlags().StringVarP(&config, "config", "c", "", "ops config file") | ||
cmdVolume.PersistentFlags().StringVarP(&provider, "provider", "p", "", "cloud provider") | ||
cmdVolume.PersistentFlags().BoolVarP(&nightly, "nightly", "n", false, "nightly build") | ||
cmdVolume.AddCommand(volumeCreateCommand()) | ||
cmdVolume.AddCommand(volumeListCommand()) | ||
cmdVolume.AddCommand(volumeDeleteCommand()) | ||
cmdVolume.AddCommand(volumeAttachCommand()) | ||
return cmdVolume | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.