sp

package
v0.2.4-r12 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: Apache-2.0 Imports: 18 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 © 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 BindPlanCmd = &cobra.Command{
	Use:   "bind-plan [sp-uuid] [plan-uuid] [[flags]]",
	Short: "Bind Billing Plan to Services Providers",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeServicesProviderServiceClientOrFail()
		request := pb.BindPlanRequest{Uuid: args[0], PlanUuid: args[1]}
		_, err := client.BindPlan(ctx, &request)
		if err != nil {
			return err
		}
		fmt.Println("Binding Completed")
		return nil
	},
}

BindPlanCmd represents the bind-plan Command

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
		}

		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
		}

		ok, _ := tools.PrintJsonDataQ(cmd, map[string]string{"uuid": res.GetUuid()})
		if !ok {
			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
		}

		ok, err := tools.PrintJsonDataQ(cmd, res)
		if err != nil {
			return err
		}
		if !ok {
			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
	},
}

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
		}

		ok, err := tools.PrintJsonDataQ(cmd, res)
		if err != nil {
			return err
		}
		if !ok {
			return PrintServicesProvider(res)
		}

		return nil
	},
}

GetCmd represents the get command

View Source
var InvokeCmd = &cobra.Command{
	Use:     "invoke [uuid] [action] [[flags]]",
	Aliases: []string{"call", "perform"},
	Short:   "Invokes NoCloud Sp Action",
	Args:    cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeServicesProviderServiceClientOrFail()
		request := pb.InvokeRequest{
			Uuid:   args[0],
			Method: args[1],
		}
		data, err := cmd.Flags().GetString("data")
		if err != nil {
			return err
		}

		if data != "" {
			var dataMap map[string]interface{}
			err = json.Unmarshal([]byte(data), &dataMap)
			if err != nil {
				return err
			}
			dataStruct, err := structpb.NewStruct(dataMap)
			if err != nil {
				return err
			}
			request.Params = dataStruct.GetFields()
		}

		res, err := client.Invoke(ctx, &request)

		if err != nil {
			return err
		}

		_, err = tools.PrintJsonDataQ(cmd, res)
		if err != nil {
			return err
		}

		fmt.Println(res)

		return nil
	},
}

GetCmd represents the list 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{Anonymously: false}
		res, err := client.List(ctx, &request)
		if err != nil {
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, res)
		if err != nil {
			return err
		}
		if !ok {
			PrintServicesProvidersPool(res.GetPool())
		}

		return nil
	},
}

ListCmd represents the list command

View Source
var PrepCmd = &cobra.Command{
	Use:   "prep [path to template] [[flags]]",
	Short: "Prepare SP template by gathering data",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) 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.PrepSP
		err = json.Unmarshal(template, &request)
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

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

		ok, _ := tools.PrintJsonDataQ(cmd, res)
		if ok {
			return nil
		}

		out, err := yaml.Marshal(res)
		if err != nil {
			return err
		}

		fmt.Println(string(out))

		return nil
	},
}
View Source
var PrepIONeCmd = &cobra.Command{
	Use:   "ione [endpoint] [username] [password|token] [[flags]]",
	Short: "Gather data required for importing OpenNebula as SP",
	Args:  cobra.ExactArgs(3),
	RunE: func(cmd *cobra.Command, args []string) error {
		request := &pb.PrepSP{
			Sp: &pb.ServicesProvider{
				Type: "ione",
				Secrets: map[string]*structpb.Value{
					"host": structpb.NewStringValue(args[0]),
					"user": structpb.NewStringValue(args[1]),
					"pass": structpb.NewStringValue(args[2]),
				},
			},
		}

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

		ok, _ := tools.PrintJsonDataQ(cmd, res)
		if ok {
			return nil
		}

		out, err := yaml.Marshal(res)
		if err != nil {
			return err
		}

		fmt.Println(string(out))

		return nil
	},
}
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
		}

		if res.GetResult() {
			ok, _ := tools.PrintJsonDataQ(cmd, map[string]bool{"result": true})
			if !ok {
				fmt.Println("Result: Tests Passed")
			}

			return nil
		}

		ok, err := tools.PrintJsonDataQ(cmd, map[string]interface{}{"result": false, "error": res.GetError()})
		if err != nil {
			return err
		}
		if !ok {
			fmt.Println("Result: Something has failed")
			fmt.Printf("Error: %s\n", res.GetError())
		}

		return nil
	},
}

createCmd represents the create command

View Source
var UnbindPlanCmd = &cobra.Command{
	Use:   "unbind-plan [sp-uuid] [plan-uuid] [[flags]]",
	Short: "Unbind Billing Plan",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeServicesProviderServiceClientOrFail()
		request := pb.UnbindPlanRequest{Uuid: args[0], PlanUuid: args[1]}
		_, err := client.UnbindPlan(ctx, &request)
		if err != nil {
			return err
		}
		fmt.Println("Unbinding Completed")
		return nil
	},
}

UnbindPlanCmd represents the unbind-plan 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