1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 00:09:40 +02:00

feat(docker/volumes): change how volume resource id is calculated (#5067)

[EE-494]
This commit is contained in:
Chaim Lev-Ari 2021-07-19 10:43:49 +03:00 committed by GitHub
parent 72117693fb
commit db16299aab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 187 additions and 31 deletions

View file

@ -2,6 +2,7 @@ package snapshot
import (
"context"
"errors"
"log"
"time"
@ -187,3 +188,27 @@ func (service *Service) snapshotEndpoints() error {
return nil
}
// FetchDockerID fetches info.Swarm.Cluster.ID if endpoint is swarm and info.ID otherwise
func FetchDockerID(snapshot portainer.DockerSnapshot) (string, error) {
info, done := snapshot.SnapshotRaw.Info.(map[string]interface{})
if !done {
return "", errors.New("failed getting snapshot info")
}
if !snapshot.Swarm {
return info["ID"].(string), nil
}
if info["Swarm"] == nil {
return "", errors.New("swarm endpoint is missing swarm info snapshot")
}
swarmInfo := info["Swarm"].(map[string]interface{})
if swarmInfo["Cluster"] == nil {
return "", errors.New("swarm endpoint is missing cluster info snapshot")
}
clusterInfo := swarmInfo["Cluster"].(map[string]interface{})
return clusterInfo["ID"].(string), nil
}