diff --git a/cli/cmd/networkElementPath.go b/cli/cmd/networkElementPath.go new file mode 100644 index 0000000000000000000000000000000000000000..3ccff97cb7f0640bf8c143154084c0eaa0f02098 --- /dev/null +++ b/cli/cmd/networkElementPath.go @@ -0,0 +1,48 @@ +/* +Copyright © 2021 da/net Research Group <danet@h-da.de> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +package cmd + +import ( + "github.com/spf13/cobra" +) + +// networkElementPathCmd represents the path interaction command. +var networkElementPathCmd = &cobra.Command{ + Use: "path {get,set,delete}", + Short: "the path command contains all sub-commands for YANG path interaction", + Long: `The path command contains all sub-commands for YANG path interaction, +including get, set and delete operations.`, +} + +func init() { + networkElementCmd.AddCommand(networkElementPathCmd) +} diff --git a/cli/cmd/networkElementDelete.go b/cli/cmd/networkElementPathDelete.go similarity index 94% rename from cli/cmd/networkElementDelete.go rename to cli/cmd/networkElementPathDelete.go index e937fb30cd43f4920fee867cf98ea54626d392ce..51f1c9f34593aae20206bdbedabab8b5a812f56e 100644 --- a/cli/cmd/networkElementDelete.go +++ b/cli/cmd/networkElementPathDelete.go @@ -40,8 +40,8 @@ import ( "github.com/spf13/cobra" ) -// networkElementDeleteCmd represents the delete command. -var networkElementDeleteCmd = &cobra.Command{ +// networkElementPathDeleteCmd represents the delete path command. +var networkElementPathDeleteCmd = &cobra.Command{ Use: "delete [uuid] [path]", Args: cobra.ExactArgs(2), Short: "delete a path on a network element", @@ -86,5 +86,5 @@ The network element UUID and request path must be specified as a positional argu } func init() { - networkElementCmd.AddCommand(networkElementDeleteCmd) + networkElementPathCmd.AddCommand(networkElementPathDeleteCmd) } diff --git a/cli/cmd/networkElementGetPath.go b/cli/cmd/networkElementPathGet.go similarity index 95% rename from cli/cmd/networkElementGetPath.go rename to cli/cmd/networkElementPathGet.go index 90679c43f0be276dc02c98e4d3be247694eece60..d02fccf2e8ea5e5668f36daffecb264847699206 100644 --- a/cli/cmd/networkElementGetPath.go +++ b/cli/cmd/networkElementPathGet.go @@ -39,8 +39,8 @@ import ( "google.golang.org/protobuf/encoding/protojson" ) -// networkElementGetCmd represents the get command. -var networkElementGetPathCmd = &cobra.Command{ +// networkElementPathGetCmd represents the get path command. +var networkElementPathGetCmd = &cobra.Command{ Use: "get [uuid] [path]", Args: cobra.ExactArgs(2), Short: "gets a path from a specified network element on the controller", @@ -96,5 +96,5 @@ The network element UUID and request path must be specified as a positional argu } func init() { - networkElementCmd.AddCommand(networkElementGetPathCmd) + networkElementPathCmd.AddCommand(networkElementPathGetCmd) } diff --git a/cli/cmd/networkElementGetIntendedPath.go b/cli/cmd/networkElementPathGetIntended.go similarity index 94% rename from cli/cmd/networkElementGetIntendedPath.go rename to cli/cmd/networkElementPathGetIntended.go index 6b4b8563c7924326d217140488e2e1dc728255ea..1e7e3c3a4c0632f298daa57f378c2c3419f05b2c 100644 --- a/cli/cmd/networkElementGetIntendedPath.go +++ b/cli/cmd/networkElementPathGetIntended.go @@ -41,8 +41,8 @@ import ( "google.golang.org/protobuf/encoding/protojson" ) -// networkElementGetCmd represents the get command. -var networkElementGetIntendedPathCmd = &cobra.Command{ +// networkElementPathGetIntendedCmd represents the get intended path command. +var networkElementPathGetIntendedCmd = &cobra.Command{ Use: "getIntended [uuid] [path]", Args: cobra.ExactArgs(2), Short: "gets the intended path from a specified network element on the controller", @@ -106,5 +106,5 @@ The network element UUID and request path must be specified as a positional argu } func init() { - networkElementCmd.AddCommand(networkElementGetIntendedPathCmd) + networkElementPathCmd.AddCommand(networkElementPathGetIntendedCmd) } diff --git a/cli/cmd/networkElementSet.go b/cli/cmd/networkElementPathSet.go similarity index 88% rename from cli/cmd/networkElementSet.go rename to cli/cmd/networkElementPathSet.go index c9c1a41e294cf0329d7cb91f0ade86b80ab51794..6dd9e1ddcc072a8328c0ef03153eb3fb826ce2ff 100644 --- a/cli/cmd/networkElementSet.go +++ b/cli/cmd/networkElementPathSet.go @@ -47,12 +47,12 @@ var replace bool var file string var forcePush bool -// networkElementSetCmd represents the set command. -var networkElementSetCmd = &cobra.Command{ +// networkElementPathSetCmd represents the set path command. +var networkElementPathSetCmd = &cobra.Command{ Use: "set [uuid] [path] [value]", Args: cobra.RangeArgs(2, 3), Short: "set a value on a network element", - Long: `Set a path value for a given orchestrated network network element. Only one path and + Long: `Set a path value for a given managed network element. Only one path and only one value supported for now. The network element UUID, request path and value must be specified as positional arguments. @@ -159,8 +159,8 @@ func fileContentToString(path string) (string, error) { } func init() { - networkElementCmd.AddCommand(networkElementSetCmd) - networkElementSetCmd.Flags().BoolVarP(&replace, "replace", "r", false, "enables replace behaviour") - networkElementSetCmd.Flags().StringVar(&file, "file", "", "reference the path to a file containing your changes as JSON") - networkElementSetCmd.Flags().BoolVar(&forcePush, "force-push", false, "enables the possibility to instantly push the set without commit/confirm") + networkElementPathCmd.AddCommand(networkElementPathSetCmd) + networkElementPathSetCmd.Flags().BoolVarP(&replace, "replace", "r", false, "enables replace behaviour") + networkElementPathSetCmd.Flags().StringVar(&file, "file", "", "reference the path to a file containing your changes as JSON") + networkElementPathSetCmd.Flags().BoolVar(&forcePush, "force-push", false, "enables the possibility to instantly push the set without commit/confirm") } diff --git a/cli/cmd/prompt.go b/cli/cmd/prompt.go index a11286d34d9366bec759977b1aee08b2f93edc42..97f05b90645109cdbf1d585bf0e51624c7b485c4 100644 --- a/cli/cmd/prompt.go +++ b/cli/cmd/prompt.go @@ -135,11 +135,11 @@ func filterFlagSlice(input []string) (commandSlice []string, flagSlice []string) return commandSlice, flagSlice } -func networkElementGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []string) []prompt.Suggest { +func networkElementPathCompletion(c *PromptCompleter, d prompt.Document, inputSplit []string) []prompt.Suggest { switch inputLen := len(inputSplit); inputLen { - case 2: - return c.updateSuggestionsThroughFunc(d, getNetworkElements) case 3: + return c.updateSuggestionsThroughFunc(d, getNetworkElements) + case 4: id, err := uuid.Parse(inputSplit[inputLen-1]) if err != nil { return c.updateSuggestionsThroughFunc(d, getNetworkElements) @@ -155,7 +155,7 @@ func networkElementGetCompletion(c *PromptCompleter, d prompt.Document, inputSpl if yc, ok := c.YangSchemaCompleterMap[id]; ok { return yc.Complete(d) } - case 4: + case 5: if d.GetWordBeforeCursor() == "" || d.GetWordAfterCursor() != "" { id, err := uuid.Parse(inputSplit[inputLen-2]) if err != nil { @@ -243,8 +243,8 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s } else { return cobraCommandCompletion(cmd, d, inputFlags, []prompt.Suggest{}) } - case networkElementGetPathCmd, networkElementGetIntendedPathCmd, networkElementSetCmd: - return networkElementGetCompletion(c, d, inputSplitFiltered) + case networkElementPathGetCmd, networkElementPathGetIntendedCmd, networkElementPathSetCmd: + return networkElementPathCompletion(c, d, inputSplitFiltered) case networkElementShowCmd: networkElements, err := getNetworkElements() if err != nil {