Initial commit

This commit is contained in:
2023-06-09 11:33:10 +02:00
commit 7c111f97ab
22 changed files with 2221 additions and 0 deletions

View File

@ -0,0 +1,51 @@
package services
import (
"fmt"
"git.cesium.pw/niku/virteen/internal/podman/models"
"git.cesium.pw/niku/virteen/internal/podman/repositories"
"github.com/containers/podman/v4/pkg/domain/entities"
)
type PodmanContainerService struct {
podman *repositories.PodmanRepository
}
func (pcs *PodmanContainerService) List() ([]entities.ListContainer, error) {
return pcs.podman.ListContainers()
}
func (pcs *PodmanContainerService) Create(blueprint models.ContainerBlueprint) error {
return pcs.podman.CreateContainer(blueprint)
}
func (pcs *PodmanContainerService) Delete(name string) error {
return pcs.podman.DeleteContainer(name)
}
func (pcs *PodmanContainerService) UpdateStatus(name, status string) error {
var state models.ContainerStatus
if status == "started" {
state = models.StartContainer
} else if status == "stopped" {
state = models.StopContainer
} else if status == "restarting" {
state = models.RestartContainer
} else {
return fmt.Errorf("invalid state, should be started, stopped or restarting")
}
return pcs.podman.UpdateContainerStatus(name, state)
}
func NewPodmanContainerService() (*PodmanContainerService, error) {
podmanRepo, err := repositories.NewPodmanRepository()
if err != nil {
return nil, err
}
return &PodmanContainerService{
podman: podmanRepo,
}, nil
}