github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/volumes.go (about) 1 package cmd 2 3 import ( 4 "os" 5 6 "github.com/sirupsen/logrus" 7 "github.com/spf13/cobra" 8 9 "github.com/emc-advanced-dev/pkg/errors" 10 "github.com/solo-io/unik/pkg/client" 11 ) 12 13 var volumesCmd = &cobra.Command{ 14 Use: "volumes", 15 Short: "List available unik-managed volumes", 16 Long: `Lists all available unik-managed volumes across providers. 17 18 ATTACHED-INSTANCE gives the instance ID of the instance a volume 19 is attached to, if any. Only volumes that have no attachment are 20 available to be attached to an instance.`, 21 Run: func(cmd *cobra.Command, args []string) { 22 if err := func() error { 23 if err := readClientConfig(); err != nil { 24 return err 25 } 26 if host == "" { 27 host = clientConfig.Host 28 } 29 logrus.WithField("host", host).Info("listing volumes") 30 volumes, err := client.UnikClient(host).Volumes().All() 31 if err != nil { 32 return errors.New("listing volumes failed", err) 33 } 34 printVolumes(volumes...) 35 return nil 36 }(); err != nil { 37 logrus.Errorf("failed listing volumes: %v", err) 38 os.Exit(-1) 39 } 40 }, 41 } 42 43 func init() { 44 RootCmd.AddCommand(volumesCmd) 45 }