Documentation
¶
Overview ¶
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CreateCmd = &cobra.Command{ Use: "create [path to template] [[flags]]", Aliases: []string{"crt", "c"}, Short: "Create Service Config", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { namespace, err := cmd.Flags().GetString("namespace") if err != nil { return err } if namespace == "" { return errors.New(" Namespace UUID isn't given") } if _, err := os.Stat(args[0]); os.IsNotExist(err) { return errors.New("Template doesn't exist at path " + args[0]) } var format string { pathSlice := strings.Split(args[0], ".") format = pathSlice[len(pathSlice)-1] } template, err := os.ReadFile(args[0]) switch format { case "json": case "yml", "yaml": template, err = yaml.YAMLToJSON(template) default: return errors.New("Unsupported template format " + format) } if err != nil { fmt.Println("Error while parsing template1") return err } service := &pb.Service{} err = json.Unmarshal(template, &service) if err != nil { fmt.Println("Error while parsing template2") return err } ctx, client := MakeServicesServiceClientOrFail() req := pb.CreateRequest{Service: service, Namespace: namespace} if _, err := SelectSPInteractive(service); err != nil { return err } fmt.Println(req) res, err := client.Create(ctx, &req) if err != nil { return err } output, err := json.MarshalIndent(res, "-", " ") if err != nil { fmt.Println(res) return err } fmt.Println("Result: ", string(output)) return nil }, }
createCmd represents the create command
var DeleteCmd = &cobra.Command{ Use: "delete [UUID]", Aliases: []string{"del", "rm", "r"}, Short: "Delete NoCloud Service", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx, client := MakeServicesServiceClientOrFail() res, err := client.Delete(ctx, &pb.DeleteRequest{ Uuid: args[0], }) if err != nil { return err } ok, err := tools.PrintJsonDataQ(cmd, res) if err != nil { return err } if !ok { fmt.Printf("Result: %t\n", res.GetResult()) if !res.GetResult() { fmt.Printf("Error: %s\n", res.GetError()) } } return nil }, }
DeleteCmd represents the delete command
var DownCmd = &cobra.Command{ Use: "down [uuid] [[flags]]", Aliases: []string{"d"}, Short: "NoCloud Service Down", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx, client := MakeServicesServiceClientOrFail() request := pb.DownRequest{Uuid: args[0]} _, err := client.Down(ctx, &request) return err }, }
GetCmd represents the list command
var GetCmd = &cobra.Command{ Use: "get [uuid] [[flags]]", Short: "Get NoCloud Service", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx, client := MakeServicesServiceClientOrFail() request := pb.GetRequest{Uuid: args[0]} res, err := client.Get(ctx, &request) if err != nil { return err } ok, err := tools.PrintJsonDataQ(cmd, res) if err != nil { return err } if !ok { return PrintService(res) } return nil }, }
GetCmd represents the list command
var ListCmd = &cobra.Command{ Use: "list [[NAMESPACE]] [[flags]]", Aliases: []string{"l"}, Short: "List NoCloud Services", Long: `Add namespace UUID after list command, to filter services by namespace`, RunE: func(cmd *cobra.Command, args []string) error { ctx, client := MakeServicesServiceClientOrFail() request := pb.ListRequest{} if len(args) > 0 { request.Namespace = &args[0] } a, _ := cmd.Flags().GetBool("show-deleted") if a { showDeletedValue := "true" request.ShowDeleted = &showDeletedValue } d, _ := cmd.Flags().GetInt32("depth") request.Depth = &d res, err := client.List(ctx, &request) if err != nil { return err } ok, err := tools.PrintJsonDataQ(cmd, res) if err != nil { return err } if !ok { PrintServicesPool(res.GetPool()) } return nil }, }
ListCmd represents the list command
var StreamCmd = &cobra.Command{ Use: "stream [service_id] [[flags]]", Aliases: []string{}, Short: "NoCloud Service Stream", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { ctx, client := MakeServicesServiceClientOrFail() req := pb.StreamRequest{Uuid: args[0]} resp, err := client.Stream(ctx, &req) if err != nil { log.Fatal(err) return err } for { respObject, err := resp.Recv() if err != nil { fmt.Println(err) return err } fmt.Println(respObject) } }, }
createCmd represents the create command
var SuspendCmd = &cobra.Command{ Use: "suspend [service_id] [[flags]]", Aliases: []string{"sus", "susp"}, Short: "NoCloud Service Suspend", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { uuid := args[0] ctx, client := MakeServicesServiceClientOrFail() req := pb.SuspendRequest{Uuid: uuid} res, err := client.Suspend(ctx, &req) if err != nil { fmt.Printf("Error while suspending Service %s. Reason: %v.\n", uuid, err) return err } ok, err := tools.PrintJsonDataQ(cmd, res) if err != nil { return err } if !ok { fmt.Printf("Successfuly suspended Service %s.\n", uuid) } return nil }, }
SuspendCmd represents the suspend command
var TestCmd = &cobra.Command{ Use: "test [path to template] [[flags]]", Short: "Test Service Config", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { if namespace == "" { return errors.New(" Namespace UUID isn't given") } if _, err := os.Stat(args[0]); os.IsNotExist(err) { return errors.New("Template doesn't exist at path " + args[0]) } var format string { pathSlice := strings.Split(args[0], ".") format = pathSlice[len(pathSlice)-1] } template, err := os.ReadFile(args[0]) switch format { case "json": case "yml", "yaml": template, err = yaml.YAMLToJSON(template) default: return errors.New("Unsupported template format " + format) } if err != nil { fmt.Println("Error while parsing template") return err } service := &pb.Service{} err = json.Unmarshal(template, service) if err != nil { fmt.Println("Error while parsing template") return err } if _, err := SelectSPInteractive(service); err != nil { return err } ctx, client := MakeServicesServiceClientOrFail() request := pb.CreateRequest{Service: service, Namespace: namespace} res, err := client.TestConfig(ctx, &request) if err != nil { return err } ok, err := tools.PrintJsonDataQ(cmd, res) if err != nil { return err } if ok { return nil } fmt.Print("Result: ") if res.GetResult() { fmt.Println("Tests Passed") return nil } fmt.Println("Something has failed. Errors:") PrintTestErrors(res.GetErrors()) return nil }, }
createCmd represents the create command
var UnsuspendCmd = &cobra.Command{ Use: "unsuspend [service_id] [[flags]]", Aliases: []string{"unsus, uns, unsusp"}, Short: "NoCloud Service Unsuspend", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { uuid := args[0] ctx, client := MakeServicesServiceClientOrFail() req := pb.UnsuspendRequest{Uuid: uuid} res, err := client.Unsuspend(ctx, &req) if err != nil { fmt.Printf("Error while unsuspending Service %s. Reason: %v.\n", uuid, err) return err } ok, err := tools.PrintJsonDataQ(cmd, res) if err != nil { return err } if !ok { fmt.Printf("Successfuly unsuspended Service %s.\n", uuid) } return nil }, }
Unsuspend represents the unsuspend command
var UpCmd = &cobra.Command{ Use: "up [service_id] [[flags]]", Aliases: []string{}, Short: "NoCloud Service Up", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { ctx, client := MakeServicesServiceClientOrFail() req := pb.UpRequest{Uuid: args[0]} _, err = client.Up(ctx, &req) return err }, }
createCmd represents the create command
var UpdateCmd = &cobra.Command{ Use: "update [path to template] [[flags]]", Aliases: []string{"upd", "u"}, Short: "Update Service Config", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { namespace, err := cmd.Flags().GetString("namespace") if err != nil { return err } if namespace == "" { return errors.New(" Namespace UUID isn't given") } if _, err := os.Stat(args[0]); os.IsNotExist(err) { return errors.New("Template doesn't exist at path " + args[0]) } var format string { pathSlice := strings.Split(args[0], ".") format = pathSlice[len(pathSlice)-1] } template, err := os.ReadFile(args[0]) switch format { case "json": case "yml", "yaml": template, err = yaml.YAMLToJSON(template) default: return errors.New("Unsupported template format " + format) } if err != nil { fmt.Println("Error while parsing template") return err } var service pb.Service err = json.Unmarshal(template, &service) if err != nil { fmt.Println("Error while parsing template") return err } ctx, client := MakeServicesServiceClientOrFail() res, err := client.Update(ctx, &service) if err != nil { return err } output, err := json.MarshalIndent(res, "-", " ") if err != nil { fmt.Println(res) return err } fmt.Println("Result: ", string(output)) return nil }, }
createCmd represents the create command
Functions ¶
func MakeServicesServiceClientOrFail ¶
func MakeServicesServiceClientOrFail() (context.Context, pb.ServicesServiceClient)
func PrintService ¶
func PrintServicesPool ¶
func PrintTestErrors ¶
func PrintTestErrors(pool []*pb.TestConfigError)
Types ¶
This section is empty.