Skip to content

Commit

Permalink
Add mgradm start, stop and restart functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cbosdo committed Feb 7, 2024
1 parent 5a17c08 commit f17bf17
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mgradm/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/distro"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/install"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/migrate"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/restart"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/start"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/stop"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/support"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/uninstall"
)
Expand Down Expand Up @@ -59,6 +62,9 @@ func NewUyuniadmCommand() *cobra.Command {
rootCmd.AddCommand(distro.NewCommand(globalFlags))
rootCmd.AddCommand(completion.NewCommand(globalFlags))
rootCmd.AddCommand(support.NewCommand(globalFlags))
rootCmd.AddCommand(start.NewCommand(globalFlags))
rootCmd.AddCommand(restart.NewCommand(globalFlags))
rootCmd.AddCommand(stop.NewCommand(globalFlags))

return rootCmd
}
23 changes: 23 additions & 0 deletions mgradm/cmd/restart/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

//go:build !nok8s

package restart

import (
"fmt"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func kubernetesRestart(
globalFlags *types.GlobalFlags,
flags *restartFlags,
cmd *cobra.Command,
args []string,
) error {
return fmt.Errorf("not implemented")
}
24 changes: 24 additions & 0 deletions mgradm/cmd/restart/nokubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

//go:build nok8s

package restart

import (
"fmt"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func kubernetesRestart(
globalFlags *types.GlobalFlags,
flags *restartFlags,
cmd *cobra.Command,
args []string,
) error {
return fmt.Errorf("built without kubernetes support")
}
20 changes: 20 additions & 0 deletions mgradm/cmd/restart/podman.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package restart

import (
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func podmanRestart(
globalFlags *types.GlobalFlags,
flags *restartFlags,
cmd *cobra.Command,
args []string,
) error {
return podman.RestartService(podman.ServerService)
}
46 changes: 46 additions & 0 deletions mgradm/cmd/restart/restart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package restart

import (
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared"
"github.com/uyuni-project/uyuni-tools/shared/types"
"github.com/uyuni-project/uyuni-tools/shared/utils"
)

type restartFlags struct {
Backend string
}

func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command {

restartCmd := &cobra.Command{
Use: "restart",
Short: "restart the server",
Long: "Restart the server",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var flags restartFlags
return utils.CommandHelper(globalFlags, cmd, args, &flags, restart)
},
}
restartCmd.SetUsageTemplate(restartCmd.UsageTemplate())

if utils.KubernetesBuilt {
utils.AddBackendFlag(restartCmd)
}

return restartCmd
}

func restart(globalFlags *types.GlobalFlags, flags *restartFlags, cmd *cobra.Command, args []string) error {
fn, err := shared.ChoosePodmanOrKubernetes(cmd.Flags(), podmanRestart, kubernetesRestart)
if err != nil {
return err
}

return fn(globalFlags, flags, cmd, args)
}
23 changes: 23 additions & 0 deletions mgradm/cmd/start/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

//go:build !nok8s

package start

import (
"fmt"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func kubernetesStart(
globalFlags *types.GlobalFlags,
flags *startFlags,
cmd *cobra.Command,
args []string,
) error {
return fmt.Errorf("not implemented")
}
24 changes: 24 additions & 0 deletions mgradm/cmd/start/nokubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

//go:build nok8s

package start

import (
"fmt"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func kubernetesStart(
globalFlags *types.GlobalFlags,
flags *startFlags,
cmd *cobra.Command,
args []string,
) error {
return fmt.Errorf("built without kubernetes support")
}
20 changes: 20 additions & 0 deletions mgradm/cmd/start/podman.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package start

import (
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func podmanStart(
globalFlags *types.GlobalFlags,
flags *startFlags,
cmd *cobra.Command,
args []string,
) error {
return podman.StartService(podman.ServerService)
}
46 changes: 46 additions & 0 deletions mgradm/cmd/start/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package start

import (
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared"
"github.com/uyuni-project/uyuni-tools/shared/types"
"github.com/uyuni-project/uyuni-tools/shared/utils"
)

type startFlags struct {
Backend string
}

func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command {

startCmd := &cobra.Command{
Use: "start",
Short: "start the server",
Long: "Start the server",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var flags startFlags
return utils.CommandHelper(globalFlags, cmd, args, &flags, start)
},
}
startCmd.SetUsageTemplate(startCmd.UsageTemplate())

if utils.KubernetesBuilt {
utils.AddBackendFlag(startCmd)
}

return startCmd
}

func start(globalFlags *types.GlobalFlags, flags *startFlags, cmd *cobra.Command, args []string) error {
fn, err := shared.ChoosePodmanOrKubernetes(cmd.Flags(), podmanStart, kubernetesStart)
if err != nil {
return err
}

return fn(globalFlags, flags, cmd, args)
}
23 changes: 23 additions & 0 deletions mgradm/cmd/stop/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

//go:build !nok8s

package stop

import (
"fmt"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func kubernetesStop(
globalFlags *types.GlobalFlags,
flags *stopFlags,
cmd *cobra.Command,
args []string,
) error {
return fmt.Errorf("not implemented")
}
24 changes: 24 additions & 0 deletions mgradm/cmd/stop/nokubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

//go:build nok8s

package stop

import (
"fmt"

"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func kubernetesStop(
globalFlags *types.GlobalFlags,
flags *startFlags,
cmd *cobra.Command,
args []string,
) error {
return fmt.Errorf("built without kubernetes support")
}
20 changes: 20 additions & 0 deletions mgradm/cmd/stop/podman.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package stop

import (
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
)

func podmanStop(
globalFlags *types.GlobalFlags,
flags *stopFlags,
cmd *cobra.Command,
args []string,
) error {
return podman.StopService(podman.ServerService)
}
47 changes: 47 additions & 0 deletions mgradm/cmd/stop/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package stop

import (
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared"
"github.com/uyuni-project/uyuni-tools/shared/types"
"github.com/uyuni-project/uyuni-tools/shared/utils"
)

type stopFlags struct {
Backend string
}

func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command {

stopCmd := &cobra.Command{
Use: "stop",
Short: "stop the server",
Long: "Stop the server",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var flags stopFlags
return utils.CommandHelper(globalFlags, cmd, args, &flags, stop)
},
}

stopCmd.SetUsageTemplate(stopCmd.UsageTemplate())

if utils.KubernetesBuilt {
utils.AddBackendFlag(stopCmd)
}

return stopCmd
}

func stop(globalFlags *types.GlobalFlags, flags *stopFlags, cmd *cobra.Command, args []string) error {
fn, err := shared.ChoosePodmanOrKubernetes(cmd.Flags(), podmanStop, kubernetesStop)
if err != nil {
return err
}

return fn(globalFlags, flags, cmd, args)
}
1 change: 1 addition & 0 deletions uyuni-tools.changes.cbosdonnat.start-stop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add mgradm start stop and restart commands

0 comments on commit f17bf17

Please sign in to comment.