mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +00:00
api: add sandbox Status API
It returns the status of current sandbox. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
b3d9683743
commit
488c3ee353
@ -50,6 +50,7 @@ type VCSandbox interface {
|
|||||||
Resume() error
|
Resume() error
|
||||||
Release() error
|
Release() error
|
||||||
Delete() error
|
Delete() error
|
||||||
|
Status() SandboxStatus
|
||||||
CreateContainer(contConfig ContainerConfig) (VCContainer, error)
|
CreateContainer(contConfig ContainerConfig) (VCContainer, error)
|
||||||
DeleteContainer(contID string) (VCContainer, error)
|
DeleteContainer(contID string) (VCContainer, error)
|
||||||
StartContainer(containerID string) (VCContainer, error)
|
StartContainer(containerID string) (VCContainer, error)
|
||||||
|
@ -89,3 +89,8 @@ func (p *Sandbox) StartContainer(contID string) (vc.VCContainer, error) {
|
|||||||
func (p *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
|
func (p *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
|
||||||
return vc.ContainerStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status implements the VCSandbox function of the same name.
|
||||||
|
func (p *Sandbox) Status() vc.SandboxStatus {
|
||||||
|
return vc.SandboxStatus{}
|
||||||
|
}
|
||||||
|
@ -535,6 +535,32 @@ func (s *Sandbox) Release() error {
|
|||||||
return s.agent.disconnect()
|
return s.agent.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status gets the status of the sandbox
|
||||||
|
// TODO: update container status properly, see kata-containers/runtime#253
|
||||||
|
func (s *Sandbox) Status() SandboxStatus {
|
||||||
|
var contStatusList []ContainerStatus
|
||||||
|
for _, c := range s.containers {
|
||||||
|
contStatusList = append(contStatusList, ContainerStatus{
|
||||||
|
ID: c.id,
|
||||||
|
State: c.state,
|
||||||
|
PID: c.process.Pid,
|
||||||
|
StartTime: c.process.StartTime,
|
||||||
|
RootFs: c.config.RootFs,
|
||||||
|
Annotations: c.config.Annotations,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return SandboxStatus{
|
||||||
|
ID: s.id,
|
||||||
|
State: s.state,
|
||||||
|
Hypervisor: s.config.HypervisorType,
|
||||||
|
HypervisorConfig: s.config.HypervisorConfig,
|
||||||
|
Agent: s.config.AgentType,
|
||||||
|
ContainersStatus: contStatusList,
|
||||||
|
Annotations: s.config.Annotations,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createAssets(sandboxConfig *SandboxConfig) error {
|
func createAssets(sandboxConfig *SandboxConfig) error {
|
||||||
kernel, err := newAsset(sandboxConfig, kernelAsset)
|
kernel, err := newAsset(sandboxConfig, kernelAsset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1356,3 +1356,11 @@ func TestStatusContainer(t *testing.T) {
|
|||||||
_, err = s.DeleteContainer(contID)
|
_, err = s.DeleteContainer(contID)
|
||||||
assert.Nil(t, err, "Failed to delete container %s in sandbox %s: %v", contID, s.ID(), err)
|
assert.Nil(t, err, "Failed to delete container %s in sandbox %s: %v", contID, s.ID(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStatusSandbox(t *testing.T) {
|
||||||
|
s, err := testCreateSandbox(t, testSandboxID, MockHypervisor, newHypervisorConfig(nil, nil), NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil)
|
||||||
|
assert.Nil(t, err, "VirtContainers should not allow empty sandboxes")
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
s.Status()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user