cmd

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Copyright © 2021 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.

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.

Copyright © 2021 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.

Copyright © 2021 Level27 info@level27.be

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 AppActionActivateCmd = &cobra.Command{
	Use:     "activate",
	Short:   "Activate an app",
	Example: "lvl app action activate 2077",
	Args:    cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {

		appID, err := resolveApp(args[0])
		if err != nil {
			return err
		}

		err = Level27Client.AppAction(appID, "activate")
		if err != nil {
			return err
		}

		outputFormatTemplate(nil, "templates/entities/app/activate.tmpl")

		return nil
	},
}

---- ACTIVATE APP

View Source
var AppActionCmd = &cobra.Command{
	Use:     "action",
	Short:   "commands to run specific actions on an app",
	Example: "lvl app action [subcommand]",
}

---- ACTION COMMAND

View Source
var AppActionDeactivateCmd = &cobra.Command{
	Use:     "deactivate",
	Short:   "Deactivate an app",
	Example: "lvl app action deactivate 2077",
	Args:    cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {

		appID, err := resolveApp(args[0])
		if err != nil {
			return err
		}

		err = Level27Client.AppAction(appID, "deactivate")
		if err != nil {
			return err
		}

		outputFormatTemplate(nil, "templates/entities/app/deactivate.tmpl")
		return nil
	},
}

---- DEACTIVATE APP

View Source
var AppComponentDeleteCmd = &cobra.Command{
	Use:     "delete",
	Short:   "Delete component from an app.",
	Example: "lvl app component delete MyAppName MyComponentName",
	Args:    cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {

		appID, err := resolveApp(args[0])
		if err != nil {
			return err
		}

		appComponentID, err := resolveAppComponent(appID, args[1])
		if err != nil {
			return err
		}

		if !optDeleteConfirmed {
			app, err := Level27Client.App(appID)
			if err != nil {
				return err
			}

			appComponent, err := Level27Client.AppComponentGetSingle(appID, appComponentID)
			if err != nil {
				return err
			}

			if !confirmPrompt(fmt.Sprintf("Delete app component %s (%d) on app %s (%d)?", appComponent.Name, appComponent.ID, app.Name, app.ID)) {
				return nil
			}
		}

		err = Level27Client.AppComponentsDelete(appID, appComponentID)
		if err != nil {
			return err
		}

		outputFormatTemplate(nil, "templates/entities/appComponent/delete.tmpl")
		return nil
	},
}

APP COMPONENT DELETE

View Source
var AppDescribeCmd = &cobra.Command{
	Use:     "describe",
	Short:   "Get detailed info about an app.",
	Example: "lvl app describe 2077",
	Args:    cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {

		appID, err := resolveApp(args[0])
		if err != nil {
			return err
		}

		app, err := Level27Client.App(appID)
		if err != nil {
			return err
		}

		outputFormatTemplate(app, "templates/app.tmpl")
		return nil
	},
}

---- DESCRIBE APP

View Source
var Level27Client *l27.Client
View Source
var RootCmd = &cobra.Command{
	Use:           "lvl",
	Short:         "CLI tool to manage Level27 entities",
	Long:          `lvl is a CLI tool that empowers users.`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Version:       strings.TrimSpace(version),

	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		outputSet := viper.GetString("output")
		if outputSet != "text" && outputSet != "json" && output != "yaml" && output != "id" {
			return fmt.Errorf("invalid output mode specified: '%s'", outputSet)
		}

		return nil
	},
}

rootCmd represents the base command when called without any subcommands

View Source
var SystemCookbookTypesGetCmd = &cobra.Command{
	Use:   "parameters",
	Short: "Show all default parameters for a specific cookbooktype.",
	RunE: func(cmd *cobra.Command, args []string) error {

		inputType := cmd.Flag("type").Value.String()

		validCookbooktype, _, err := Level27Client.SystemCookbookTypeGet(inputType)
		if err != nil {
			return err
		}

		outputFormatTable(validCookbooktype.CookbookType.Parameters, []string{"NAME", "DESCRIPTION", "DEFAULT_VALUE"}, []string{"Name", "Description", "DefaultValue"})
		return nil
	},
}

----------- GET COOKBOOKTYPE PARAMETERS seperate command used to see wich parameters can be used for a specific cookbooktype. also shows the description and default values

View Source
var SystemSystemgroupsAddCmd = &cobra.Command{
	Use:   "add [systemID] [systemgroupID]",
	Short: "Link a system with a systemgroup.",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {

		systemID, err := resolveSystem(args[0])
		if err != nil {
			return err
		}

		groupID, err := resolveSystemgroup(args[1])
		if err != nil {
			return err
		}

		jsonRequest := gabs.New()
		jsonRequest.Set(groupID, "systemgroup")
		err = Level27Client.SystemSystemgroupsAdd(systemID, jsonRequest)
		if err != nil {
			return err
		}

		outputFormatTemplate(nil, "templates/entities/system/groupAdd.tmpl")
		return nil
	},
}

---------------- LINK SYSTEM TO A GROUP (ADD)

View Source
var SystemSystemgroupsCmd = &cobra.Command{
	Use:   "groups",
	Short: "Manage a system's groups.",
}

------------------------------------------------- SYSTEMS/GROUPS (GET / ADD / DELETE)------------------------------------------------- ---------------- MAIN COMMAND (groups)

View Source
var SystemSystemgroupsGetCmd = &cobra.Command{
	Use:   "get [systemID]",
	Short: "Show list of all groups from a system.",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {

		systemID, err := resolveSystem(args[0])
		if err != nil {
			return err
		}

		groups, err := Level27Client.SystemSystemgroupsGet(systemID)
		if err != nil {
			return err
		}

		outputFormatTable(groups, []string{"ID", "NAME"}, []string{"ID", "Name"})
		return nil
	},
}

---------------- GET GROUPS

View Source
var SystemSystemgroupsRemoveCmd = &cobra.Command{
	Use:   "remove [systemID] [systemgroupID]",
	Short: "Unlink a system from a systemgroup.",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {

		systemID, err := resolveSystem(args[0])
		if err != nil {
			return err
		}

		groupID, err := resolveSystemgroup(args[1])
		if err != nil {
			return err
		}

		err = Level27Client.SystemSystemgroupsRemove(systemID, groupID)
		if err != nil {
			return err
		}

		outputFormatTemplate(nil, "templates/entities/system/groupRemove.tmpl")
		return nil
	},
}

---------------- UNLINK SYSTEM FROM A GROUP (DELETE)

Functions

func CheckCBValueForParameter

func CheckCBValueForParameter(value string, options l27.CookbookParameterOptionValue, givenParameter string, currentSystemOs string) (bool, error)

check a value if its a valid option for the given parameter for the cookbook. also do checks on compatibility with system and exlusivity

func CheckForMultipleIDs

func CheckForMultipleIDs(ids []string) []string

Try to split the given cmd args into ID's (works with whitespace and komma's)

func CheckSubJobs

func CheckSubJobs(job l27.Job) bool

func CheckforValidType

func CheckforValidType(input string, validTypes []string) (string, bool)

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func FindNotcompletedJobs

func FindNotcompletedJobs(jobs []l27.Job) []l27.Job

func FindNotcompletedJobsRoot added in v1.5.0

func FindNotcompletedJobsRoot(jobs []l27.HistoryRootJob) []l27.HistoryRootJob

func ParseMigrationItem

func ParseMigrationItem(appID l27.IntID, values string) (l27.AppMigrationItem, error)

func ParseMigrationItemKeyValuePair

func ParseMigrationItemKeyValuePair(keyValuePair string) (string, string, error)

func SplitCustomParameters

func SplitCustomParameters(customP []string) (map[string]interface{}, error)

--------------------------- DYNAMICALY SETTING PARAMETERS this can be used when you need flags to set different paramaters but you don't know the amount of parameters beforehand. we can use something like a parameter flag where the user has to set the keys and values himself. example lvl system cookbooks create -p key=value -p key2=value2 function used for commands with dynamic parameters. (different parameters defined by 1 flag)

Types

type DescribeSystem

type DescribeSystem struct {
	l27.System
	SshKeys                      []l27.SystemSshkey     `json:"sshKeys"`
	InstallSecurityUpdatesString string                 `json:"installSecurityUpdatesString"`
	HasNetworks                  []l27.SystemHasNetwork `json:"hasNetworks"`
	Volumes                      []l27.SystemVolume     `json:"volumes"`
	Checks                       []l27.SystemCheckGet   `json:"checks"`
}

type DescribeSystemNetworks

type DescribeSystemNetworks struct {
	Networks    []l27.SystemNetwork    `json:"networks"`
	HasNetworks []l27.SystemHasNetwork `json:"hasNetworks"`
}

type GitHubRelease added in v1.7.0

type GitHubRelease struct {
	TagName   string `json:"tag_name"`
	AssetsUrl string `json:"assets_url"`
}

type GitHubReleaseAsset added in v1.7.0

type GitHubReleaseAsset struct {
	Url  string `json:"url"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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