sp

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

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 © 2022 NAME HERE <EMAIL ADDRESS>

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

View Source
var CreateCmd = &cobra.Command{
	Use:   "create [path to template] [flags]",
	Short: "Create Services Provider Config",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		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
		}

		fmt.Println("Template", string(template))

		var request pb.ServicesProvider
		err = json.Unmarshal(template, &request)
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

		ctx, client := MakeServicesProviderServiceClientOrFail()
		res, err := client.Create(ctx, &request)
		if err != nil {
			return err
		}

		fmt.Println("Service Provider Created, UUID:", res.GetUuid())
		return nil
	},
}

createCmd represents the create command

View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete [uuid] [[flags]]",
	Short: "Delete NoCloud Services Providers",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeServicesProviderServiceClientOrFail()
		request := pb.DeleteRequest{Uuid: args[0]}
		res, err := client.Delete(ctx, &request)

		if err != nil {
			return err
		}

		if printJson, _ := cmd.Flags().GetBool("json"); !printJson {
			if !res.GetResult() {
				fmt.Println("Can't delete ServicesProvider, some services are still UP and provisioned")
				fmt.Println("Services:")
				for _, uuid := range res.GetServices() {
					fmt.Println("- ", uuid)
				}
				return nil
			}
			fmt.Println("Done.")
			return nil
		}

		data, err := json.Marshal(res)
		if err != nil {
			return err
		}
		fmt.Println(string(data))
		return nil
	},
}

DeleteCmd represents the delete command

View Source
var ExtCmd = &cobra.Command{
	Use:   "ext",
	Short: "Manage ServicesProviders extentions",
}

ExtCmd represents the ext command

View Source
var GetCmd = &cobra.Command{
	Use:   "get [uuid] [[flags]]",
	Short: "Get NoCloud Services Providers",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeServicesProviderServiceClientOrFail()
		request := pb.GetRequest{Uuid: args[0]}
		res, err := client.Get(ctx, &request)

		if err != nil {
			return err
		}

		if printJson, _ := cmd.Flags().GetBool("json"); !printJson {
			return PrintServicesProvider(res)
		}

		data, err := json.Marshal(res)
		if err != nil {
			return err
		}
		fmt.Println(string(data))
		return nil
	},
}

GetCmd represents the get command

View Source
var ListCmd = &cobra.Command{
	Use:   "list [[NAMESPACE]] [[flags]]",
	Short: "List NoCloud Services Providers",
	Long:  `Add namespace UUID after list command, to filter services by namespace`,
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeServicesProviderServiceClientOrFail()
		request := pb.ListRequest{}
		res, err := client.List(ctx, &request)
		if err != nil {
			return err
		}

		if printJson, _ := cmd.Flags().GetBool("json"); printJson {
			data, err := json.Marshal(res)
			if err != nil {
				return err
			}
			fmt.Println(string(data))
		} else {
			PrintServicesProvidersPool(res.GetPool())
		}

		return nil
	},
}

ListCmd represents the list command

View Source
var TestCmd = &cobra.Command{
	Use:   "test [path to template] [flags]",
	Short: "Test Services Provider Config",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		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 request pb.ServicesProvider
		err = json.Unmarshal(template, &request)
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

		ctx, client := MakeServicesProviderServiceClientOrFail()
		res, err := client.Test(ctx, &request)
		if err != nil {
			return err
		}

		fmt.Print("Result: ")
		if res.GetResult() {
			fmt.Println("Tests Passed")
			return nil
		}

		fmt.Println("Something has failed")
		err = fmt.Errorf("Error: %s\n", res.GetError())
		return err
	},
}

createCmd represents the create command

View Source
var UpdateCmd = &cobra.Command{
	Use:   "update [path to template] [flags]",
	Short: "Update Services Provider Config",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		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
		}

		fmt.Println("Template", string(template))
		var request pb.ServicesProvider
		err = json.Unmarshal(template, &request)
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

		ctx, client := MakeServicesProviderServiceClientOrFail()
		res, err := client.Get(ctx, &pb.GetRequest{Uuid: request.GetUuid()})
		if err != nil {
			return err
		}
		if res.GetUuid() == "" {
			errMsg := fmt.Sprintf("Service Provider with given Uuid %v is not found", request.GetUuid())
			return errors.New(errMsg)
		}

		res, err = client.Update(ctx, &request)
		if err != nil {
			return err
		}

		fmt.Println("Service Provider Updated, UUID:", res.GetUuid())
		return nil
	},
}

updateCmd represents the update command

Functions

func MakeServicesProviderServiceClientOrFail

func MakeServicesProviderServiceClientOrFail() (context.Context, pb.ServicesProvidersServiceClient)

func PrintServicesProvider

func PrintServicesProvider(s *pb.ServicesProvider) error

func PrintServicesProvidersPool

func PrintServicesProvidersPool(pool []*pb.ServicesProvider)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL