mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
refactor(master): list cluster interface (#909)
This commit is contained in:
+12
-11
@@ -58,6 +58,15 @@ func (*ClusterService) Inspect(name string) (*types.ClusterManifest, error) {
|
||||
return inspectContainer(data)
|
||||
}
|
||||
|
||||
func (*ClusterService) List() ([]types.ClusterInfo, error) {
|
||||
data := exec.BashEval("buildah containers --json")
|
||||
infos, err := listContainer(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func inspectContainer(data string) (*types.ClusterManifest, error) {
|
||||
if data != "" {
|
||||
var outStruct map[string]interface{}
|
||||
@@ -78,24 +87,16 @@ func inspectContainer(data string) (*types.ClusterManifest, error) {
|
||||
return nil, errors.New("inspect output is empty")
|
||||
}
|
||||
|
||||
type ClusterInfo struct {
|
||||
ID string `json:"id"`
|
||||
Builder bool `json:"builder"`
|
||||
Imageid string `json:"imageid"`
|
||||
Imagename string `json:"imagename"`
|
||||
Containername string `json:"containername"`
|
||||
}
|
||||
|
||||
func listContainer(data string) ([]ClusterInfo, error) {
|
||||
func listContainer(data string) ([]types.ClusterInfo, error) {
|
||||
if data != "" {
|
||||
var outStruct []ClusterInfo
|
||||
var outStruct []types.ClusterInfo
|
||||
err := json.Unmarshal([]byte(data), &outStruct)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "decode out json from list container failed")
|
||||
}
|
||||
return outStruct, nil
|
||||
}
|
||||
return nil, errors.New("inspect output is empty")
|
||||
return nil, errors.New("containers output is empty")
|
||||
}
|
||||
|
||||
func NewClusterService() (types.ClusterService, error) {
|
||||
|
||||
@@ -43,4 +43,5 @@ type ClusterService interface {
|
||||
Delete(name string) error
|
||||
// Inspect return cluster(container) manifest
|
||||
Inspect(name string) (*ClusterManifest, error)
|
||||
List() ([]ClusterInfo, error)
|
||||
}
|
||||
|
||||
@@ -27,3 +27,11 @@ type ClusterManifest struct {
|
||||
ContainerID string
|
||||
MountPoint string
|
||||
}
|
||||
|
||||
type ClusterInfo struct {
|
||||
ID string `json:"id"`
|
||||
Builder bool `json:"builder"`
|
||||
Imageid string `json:"imageid"`
|
||||
Imagename string `json:"imagename"`
|
||||
Containername string `json:"containername"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user