diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-11-01 13:22:04 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@gmail.com> | 2017-11-01 13:22:04 -0400 |
commit | c13f61798aa7bcf7b4de7ee31aa30148a3b08d97 (patch) | |
tree | 6f0c3297f91ecbe259d8dc5ff1b0ab3d63e44744 /server/container_list.go | |
parent | 92b31c0ff7c75fab3b875fb6b10c14f8e2c031e7 (diff) | |
download | podman-c13f61798aa7bcf7b4de7ee31aa30148a3b08d97.tar.gz podman-c13f61798aa7bcf7b4de7ee31aa30148a3b08d97.tar.bz2 podman-c13f61798aa7bcf7b4de7ee31aa30148a3b08d97.zip |
Prune Server package. Convert to new github location.
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'server/container_list.go')
-rw-r--r-- | server/container_list.go | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/server/container_list.go b/server/container_list.go deleted file mode 100644 index 42204ae1f..000000000 --- a/server/container_list.go +++ /dev/null @@ -1,112 +0,0 @@ -package server - -import ( - "github.com/kubernetes-incubator/cri-o/oci" - "github.com/sirupsen/logrus" - "golang.org/x/net/context" - "k8s.io/apimachinery/pkg/fields" - pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" -) - -// filterContainer returns whether passed container matches filtering criteria -func filterContainer(c *pb.Container, filter *pb.ContainerFilter) bool { - if filter != nil { - if filter.State != nil { - if c.State != filter.State.State { - return false - } - } - if filter.LabelSelector != nil { - sel := fields.SelectorFromSet(filter.LabelSelector) - if !sel.Matches(fields.Set(c.Labels)) { - return false - } - } - } - return true -} - -// ListContainers lists all containers by filters. -func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error) { - logrus.Debugf("ListContainersRequest %+v", req) - var ctrs []*pb.Container - filter := req.Filter - ctrList, err := s.ContainerServer.ListContainers() - if err != nil { - return nil, err - } - - // Filter using container id and pod id first. - if filter.Id != "" { - id, err := s.CtrIDIndex().Get(filter.Id) - if err != nil { - // If we don't find a container ID with a filter, it should not - // be considered an error. Log a warning and return an empty struct - logrus.Warn("unable to find container ID %s", filter.Id) - return &pb.ListContainersResponse{}, nil - } - c := s.ContainerServer.GetContainer(id) - if c != nil { - if filter.PodSandboxId != "" { - if c.Sandbox() == filter.PodSandboxId { - ctrList = []*oci.Container{c} - } else { - ctrList = []*oci.Container{} - } - - } else { - ctrList = []*oci.Container{c} - } - } - } else { - if filter.PodSandboxId != "" { - pod := s.ContainerServer.GetSandbox(filter.PodSandboxId) - if pod == nil { - ctrList = []*oci.Container{} - } else { - ctrList = pod.Containers().List() - } - } - } - - for _, ctr := range ctrList { - podSandboxID := ctr.Sandbox() - cState := s.Runtime().ContainerStatus(ctr) - created := cState.Created.UnixNano() - rState := pb.ContainerState_CONTAINER_UNKNOWN - cID := ctr.ID() - img := &pb.ImageSpec{ - Image: ctr.Image(), - } - c := &pb.Container{ - Id: cID, - PodSandboxId: podSandboxID, - CreatedAt: created, - Labels: ctr.Labels(), - Metadata: ctr.Metadata(), - Annotations: ctr.Annotations(), - Image: img, - } - - switch cState.Status { - case oci.ContainerStateCreated: - rState = pb.ContainerState_CONTAINER_CREATED - case oci.ContainerStateRunning: - rState = pb.ContainerState_CONTAINER_RUNNING - case oci.ContainerStateStopped: - rState = pb.ContainerState_CONTAINER_EXITED - } - c.State = rState - - // Filter by other criteria such as state and labels. - if filterContainer(c, req.Filter) { - ctrs = append(ctrs, c) - } - } - - resp := &pb.ListContainersResponse{ - Containers: ctrs, - } - logrus.Debugf("ListContainersResponse: %+v", resp) - return resp, nil -} |