container.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package host
  15. import (
  16. "time"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. )
  19. type ContainerVolumeMountDisk struct {
  20. Index *int `json:"index,omitempty"`
  21. Id string `json:"id"`
  22. TemplateId string `json:"template_id"`
  23. SubDirectory string `json:"sub_directory"`
  24. StorageSizeFile string `json:"storage_size_file"`
  25. Overlay *apis.ContainerVolumeMountDiskOverlay `json:"overlay"`
  26. CaseInsensitivePaths []string `json:"case_insensitive_paths"`
  27. PostOverlay []*apis.ContainerVolumeMountDiskPostOverlay `json:"post_overlay"`
  28. ResGid int `json:"res_gid"`
  29. ResUid int `json:"res_uid"`
  30. }
  31. type ContainerVolumeMountCephFS struct {
  32. Id string `json:"id"`
  33. MonHost string `json:"mon_host"`
  34. Path string `json:"path"`
  35. Secret string `json:"secret"`
  36. Name string `json:"name"`
  37. }
  38. type ContainerRootfs struct {
  39. Type apis.ContainerVolumeMountType `json:"type"`
  40. Disk *ContainerVolumeMountDisk `json:"disk"`
  41. // CephFS *ContainerVolumeMountCephFS `json:"ceph_fs"`
  42. // 是否持久化
  43. Persistent bool `default:"false" list:"user" create:"admin_optional" update:"admin"`
  44. }
  45. type ContainerVolumeMount struct {
  46. // 用于标识当前 pod volume mount 的唯一性
  47. UniqueName string `json:"unique_name"`
  48. Type apis.ContainerVolumeMountType `json:"type"`
  49. Disk *ContainerVolumeMountDisk `json:"disk"`
  50. HostPath *apis.ContainerVolumeMountHostPath `json:"host_path"`
  51. Text *apis.ContainerVolumeMountText `json:"text"`
  52. CephFS *ContainerVolumeMountCephFS `json:"ceph_fs"`
  53. // Mounted read-only if true, read-write otherwise (false or unspecified).
  54. ReadOnly bool `json:"read_only"`
  55. // Path within the container at which the volume should be mounted. Must
  56. // not contain ':'.
  57. MountPath string `json:"mount_path"`
  58. // If set, the mount needs SELinux relabeling.
  59. SelinuxRelabel bool `json:"selinux_relabel,omitempty"`
  60. // Requested propagation mode.
  61. Propagation apis.ContainerMountPropagation `json:"propagation,omitempty"`
  62. FsUser *int64 `json:"fs_user,omitempty"`
  63. FsGroup *int64 `json:"fs_group,omitempty"`
  64. }
  65. type ContainerSpec struct {
  66. apis.ContainerSpec
  67. ImageCredentialToken string `json:"image_credential_token"`
  68. SecretCredentials map[string]string `json:"secret_credentials"`
  69. Rootfs *ContainerRootfs `json:"rootfs"`
  70. VolumeMounts []*ContainerVolumeMount `json:"volume_mounts"`
  71. Devices []*ContainerDevice `json:"devices"`
  72. }
  73. type ContainerDevice struct {
  74. Type apis.ContainerDeviceType `json:"type"`
  75. ContainerPath string `json:"container_path"`
  76. Permissions string `json:"permissions"`
  77. IsolatedDevice *ContainerIsolatedDevice `json:"isolated_device"`
  78. Host *ContainerHostDevice `json:"host"`
  79. Disk *ContainerDiskDevice `json:"disk"`
  80. }
  81. type ContainerIsolatedDevice struct {
  82. Id string `json:"id"`
  83. Addr string `json:"addr"`
  84. Path string `json:"path"`
  85. DeviceType string `json:"device_type"`
  86. CardPath string `json:"card_path"`
  87. RenderPath string `json:"render_path"`
  88. Index int `json:"index"`
  89. DeviceMinor int `json:"device_minor"`
  90. OnlyEnv []*apis.ContainerIsolatedDeviceOnlyEnv `json:"only_env"`
  91. CDI *apis.ContainerIsolatedDeviceCDI `json:"cdi"`
  92. }
  93. func (d *ContainerIsolatedDevice) IsCDIUsed() bool {
  94. return d.CDI != nil
  95. }
  96. type ContainerHostDevice struct {
  97. // Path of the device on the host.
  98. HostPath string `json:"host_path"`
  99. }
  100. type ContainerDiskDevice struct {
  101. Id string `json:"id"`
  102. }
  103. type ContainerCreateInput struct {
  104. Name string `json:"name"`
  105. GuestId string `json:"guest_id"`
  106. Spec *ContainerSpec `json:"spec"`
  107. RestartCount int `json:"restart_count"`
  108. }
  109. type ContainerPullImageInput struct {
  110. Image string `json:"image"`
  111. PullPolicy apis.ImagePullPolicy `json:"pull_policy"`
  112. Auth *apis.ContainerPullImageAuthConfig `json:"auth"`
  113. }
  114. type ContainerPushImageInput struct {
  115. Image string `json:"image"`
  116. Auth *apis.ContainerPullImageAuthConfig `json:"auth"`
  117. }
  118. type ContainerDesc struct {
  119. Id string `json:"id"`
  120. Name string `json:"name"`
  121. Spec *ContainerSpec `json:"spec"`
  122. StartedAt time.Time `json:"started_at"`
  123. LastFinishedAt time.Time `json:"last_finished_at"`
  124. RestartCount int `json:"restart_count"`
  125. }
  126. type ContainerSaveVolumeMountToImageInput struct {
  127. ImageId string `json:"image_id"`
  128. VolumeMountIndex int `json:"volume_mount_index"`
  129. VolumeMount *ContainerVolumeMount `json:"volume_mount"`
  130. VolumeMountDirs []string `json:"volume_mount_dirs"`
  131. VolumeMountPrefix string `json:"volume_mount_prefix"`
  132. ExcludePaths []string `json:"exclude_paths"`
  133. }
  134. type ContainerCommitInput struct {
  135. Repository string `json:"repository"`
  136. Auth *apis.ContainerPullImageAuthConfig `json:"auth"`
  137. }
  138. type ContainerStopInput struct {
  139. Timeout int64 `json:"timeout"`
  140. ShmSizeMB int `json:"shm_size_mb"`
  141. ContainerName string `json:"container_name"`
  142. Force bool `json:"force"`
  143. }