diff --git a/virtcontainers/api.go b/virtcontainers/api.go index 1d439d8cf0..8302737e6f 100644 --- a/virtcontainers/api.go +++ b/virtcontainers/api.go @@ -82,17 +82,17 @@ func DeleteSandbox(sandboxID string) (VCSandbox, error) { defer unlockSandbox(lockFile) // Fetch the sandbox from storage and create it. - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return nil, err } // Delete it. - if err := p.Delete(); err != nil { + if err := s.Delete(); err != nil { return nil, err } - return p, nil + return s, nil } // FetchSandbox is the virtcontainers sandbox fetching entry point. @@ -129,27 +129,27 @@ func StartSandbox(sandboxID string) (VCSandbox, error) { defer unlockSandbox(lockFile) // Fetch the sandbox from storage and create it. - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return nil, err } - return startSandbox(p) + return startSandbox(s) } -func startSandbox(p *Sandbox) (*Sandbox, error) { +func startSandbox(s *Sandbox) (*Sandbox, error) { // Start it - err := p.start() + err := s.start() if err != nil { return nil, err } // Execute poststart hooks. - if err := p.config.Hooks.postStartHooks(p); err != nil { + if err := s.config.Hooks.postStartHooks(s); err != nil { return nil, err } - return p, nil + return s, nil } // StopSandbox is the virtcontainers sandbox stopping entry point. @@ -166,45 +166,45 @@ func StopSandbox(sandboxID string) (VCSandbox, error) { defer unlockSandbox(lockFile) // Fetch the sandbox from storage and create it. - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return nil, err } // Stop it. - err = p.stop() + err = s.stop() if err != nil { return nil, err } // Remove the network. - if err := p.removeNetwork(); err != nil { + if err := s.removeNetwork(); err != nil { return nil, err } // Execute poststop hooks. - if err := p.config.Hooks.postStopHooks(p); err != nil { + if err := s.config.Hooks.postStopHooks(s); err != nil { return nil, err } - return p, nil + return s, nil } // RunSandbox is the virtcontainers sandbox running entry point. // RunSandbox creates a sandbox and its containers and then it starts them. func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) { - p, err := createSandboxFromConfig(sandboxConfig) + s, err := createSandboxFromConfig(sandboxConfig) if err != nil { return nil, err } - lockFile, err := rwLockSandbox(p.id) + lockFile, err := rwLockSandbox(s.id) if err != nil { return nil, err } defer unlockSandbox(lockFile) - return startSandbox(p) + return startSandbox(s) } // ListSandbox is the virtcontainers sandbox listing entry point. @@ -250,7 +250,7 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) { return SandboxStatus{}, err } - sandbox, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { unlockSandbox(lockFile) return SandboxStatus{}, err @@ -263,12 +263,12 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) { // will need to lock an exclusive lock, meaning that all other locks have // to be released to let this happen. This call ensures this will be the // last operation executed by this function. - defer sandbox.wg.Wait() + defer s.wg.Wait() defer unlockSandbox(lockFile) var contStatusList []ContainerStatus - for _, container := range sandbox.containers { - contStatus, err := statusContainer(sandbox, container.id) + for _, container := range s.containers { + contStatus, err := statusContainer(s, container.id) if err != nil { return SandboxStatus{}, err } @@ -277,13 +277,13 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) { } sandboxStatus := SandboxStatus{ - ID: sandbox.id, - State: sandbox.state, - Hypervisor: sandbox.config.HypervisorType, - HypervisorConfig: sandbox.config.HypervisorConfig, - Agent: sandbox.config.AgentType, + ID: s.id, + State: s.state, + Hypervisor: s.config.HypervisorType, + HypervisorConfig: s.config.HypervisorConfig, + Agent: s.config.AgentType, ContainersStatus: contStatusList, - Annotations: sandbox.config.Annotations, + Annotations: s.config.Annotations, } return sandboxStatus, nil @@ -388,13 +388,13 @@ func StopContainer(sandboxID, containerID string) (VCContainer, error) { } defer unlockSandbox(lockFile) - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return nil, err } // Fetch the container. - c, err := p.findContainer(containerID) + c, err := s.findContainer(containerID) if err != nil { return nil, err } @@ -454,7 +454,7 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) { return ContainerStatus{}, err } - sandbox, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { unlockSandbox(lockFile) return ContainerStatus{}, err @@ -467,10 +467,10 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) { // will need to lock an exclusive lock, meaning that all other locks have // to be released to let this happen. This call ensures this will be the // last operation executed by this function. - defer sandbox.wg.Wait() + defer s.wg.Wait() defer unlockSandbox(lockFile) - return statusContainer(sandbox, containerID) + return statusContainer(s, containerID) } // This function is going to spawn a goroutine and it needs to be waited for @@ -541,13 +541,13 @@ func KillContainer(sandboxID, containerID string, signal syscall.Signal, all boo } defer unlockSandbox(lockFile) - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return err } // Fetch the container. - c, err := p.findContainer(containerID) + c, err := s.findContainer(containerID) if err != nil { return err } @@ -590,13 +590,13 @@ func ProcessListContainer(sandboxID, containerID string, options ProcessListOpti } defer unlockSandbox(lockFile) - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return nil, err } // Fetch the container. - c, err := p.findContainer(containerID) + c, err := s.findContainer(containerID) if err != nil { return nil, err } diff --git a/virtcontainers/pkg/vcmock/sandbox.go b/virtcontainers/pkg/vcmock/sandbox.go index 270958f744..68b40fc36a 100644 --- a/virtcontainers/pkg/vcmock/sandbox.go +++ b/virtcontainers/pkg/vcmock/sandbox.go @@ -14,30 +14,30 @@ import ( ) // ID implements the VCSandbox function of the same name. -func (p *Sandbox) ID() string { - return p.MockID +func (s *Sandbox) ID() string { + return s.MockID } // Annotations implements the VCSandbox function of the same name. -func (p *Sandbox) Annotations(key string) (string, error) { - return p.MockAnnotations[key], nil +func (s *Sandbox) Annotations(key string) (string, error) { + return s.MockAnnotations[key], nil } // SetAnnotations implements the VCSandbox function of the same name. -func (p *Sandbox) SetAnnotations(annotations map[string]string) error { +func (s *Sandbox) SetAnnotations(annotations map[string]string) error { return nil } // GetAnnotations implements the VCSandbox function of the same name. -func (p *Sandbox) GetAnnotations() map[string]string { - return p.MockAnnotations +func (s *Sandbox) GetAnnotations() map[string]string { + return s.MockAnnotations } // GetAllContainers implements the VCSandbox function of the same name. -func (p *Sandbox) GetAllContainers() []vc.VCContainer { - var ifa = make([]vc.VCContainer, len(p.MockContainers)) +func (s *Sandbox) GetAllContainers() []vc.VCContainer { + var ifa = make([]vc.VCContainer, len(s.MockContainers)) - for i, v := range p.MockContainers { + for i, v := range s.MockContainers { ifa[i] = v } @@ -45,8 +45,8 @@ func (p *Sandbox) GetAllContainers() []vc.VCContainer { } // GetContainer implements the VCSandbox function of the same name. -func (p *Sandbox) GetContainer(containerID string) vc.VCContainer { - for _, c := range p.MockContainers { +func (s *Sandbox) GetContainer(containerID string) vc.VCContainer { + for _, c := range s.MockContainers { if c.MockID == containerID { return c } @@ -55,86 +55,86 @@ func (p *Sandbox) GetContainer(containerID string) vc.VCContainer { } // Release implements the VCSandbox function of the same name. -func (p *Sandbox) Release() error { +func (s *Sandbox) Release() error { return nil } // Pause implements the VCSandbox function of the same name. -func (p *Sandbox) Pause() error { +func (s *Sandbox) Pause() error { return nil } // Resume implements the VCSandbox function of the same name. -func (p *Sandbox) Resume() error { +func (s *Sandbox) Resume() error { return nil } // Delete implements the VCSandbox function of the same name. -func (p *Sandbox) Delete() error { +func (s *Sandbox) Delete() error { return nil } // CreateContainer implements the VCSandbox function of the same name. -func (p *Sandbox) CreateContainer(conf vc.ContainerConfig) (vc.VCContainer, error) { +func (s *Sandbox) CreateContainer(conf vc.ContainerConfig) (vc.VCContainer, error) { return &Container{}, nil } // DeleteContainer implements the VCSandbox function of the same name. -func (p *Sandbox) DeleteContainer(contID string) (vc.VCContainer, error) { +func (s *Sandbox) DeleteContainer(contID string) (vc.VCContainer, error) { return &Container{}, nil } // StartContainer implements the VCSandbox function of the same name. -func (p *Sandbox) StartContainer(contID string) (vc.VCContainer, error) { +func (s *Sandbox) StartContainer(contID string) (vc.VCContainer, error) { return &Container{}, nil } // StatusContainer implements the VCSandbox function of the same name. -func (p *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) { +func (s *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) { return vc.ContainerStatus{}, nil } // StatsContainer implements the VCSandbox function of the same name. -func (p *Sandbox) StatsContainer(contID string) (vc.ContainerStats, error) { +func (s *Sandbox) StatsContainer(contID string) (vc.ContainerStats, error) { return vc.ContainerStats{}, nil } // Status implements the VCSandbox function of the same name. -func (p *Sandbox) Status() vc.SandboxStatus { +func (s *Sandbox) Status() vc.SandboxStatus { return vc.SandboxStatus{} } // EnterContainer implements the VCSandbox function of the same name. -func (p *Sandbox) EnterContainer(containerID string, cmd vc.Cmd) (vc.VCContainer, *vc.Process, error) { +func (s *Sandbox) EnterContainer(containerID string, cmd vc.Cmd) (vc.VCContainer, *vc.Process, error) { return &Container{}, &vc.Process{}, nil } // Monitor implements the VCSandbox function of the same name. -func (p *Sandbox) Monitor() (chan error, error) { +func (s *Sandbox) Monitor() (chan error, error) { return nil, nil } // UpdateContainer implements the VCSandbox function of the same name. -func (p *Sandbox) UpdateContainer(containerID string, resources specs.LinuxResources) error { +func (s *Sandbox) UpdateContainer(containerID string, resources specs.LinuxResources) error { return nil } // WaitProcess implements the VCSandbox function of the same name. -func (p *Sandbox) WaitProcess(containerID, processID string) (int32, error) { +func (s *Sandbox) WaitProcess(containerID, processID string) (int32, error) { return 0, nil } // SignalProcess implements the VCSandbox function of the same name. -func (p *Sandbox) SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error { +func (s *Sandbox) SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error { return nil } // WinsizeProcess implements the VCSandbox function of the same name. -func (p *Sandbox) WinsizeProcess(containerID, processID string, height, width uint32) error { +func (s *Sandbox) WinsizeProcess(containerID, processID string, height, width uint32) error { return nil } // IOStream implements the VCSandbox function of the same name. -func (p *Sandbox) IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) { +func (s *Sandbox) IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) { return nil, nil, nil, nil } diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index fbe2238683..d644a67e0c 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -1326,22 +1326,22 @@ func togglePauseSandbox(sandboxID string, pause bool) (*Sandbox, error) { defer unlockSandbox(lockFile) // Fetch the sandbox from storage and create it. - p, err := fetchSandbox(sandboxID) + s, err := fetchSandbox(sandboxID) if err != nil { return nil, err } if pause { - err = p.Pause() + err = s.Pause() } else { - err = p.Resume() + err = s.Resume() } if err != nil { return nil, err } - return p, nil + return s, nil } // HotplugAddDevice is used for add a device to sandbox