Documentation ¶
Overview ¶
initialization for internal data structures & processes
Index ¶
- Variables
- func ForkInit()
- func Init()
- type APIType
- type Attach
- type AttachDriver
- type AttachDriverIscsi
- type AttachDriverLocal
- type AttachDriverLoopback
- type AttachDriverRbd
- type Attachments
- func (a *Attachments) Attach(at *Attach) (ret *Attach, err error)
- func (a *Attachments) Detach(at *Attach, force bool) (ret *Attach, err error)
- func (a *Attachments) Get(id models.ID) *Attach
- func (a *Attachments) GetOrAttach(at *Attach) (ret *Attach, err error)
- func (a *Attachments) Init(log *logrus.Entry)
- func (a *Attachments) List() (ret []*Attach)
- type Container
- type Containers
- func (c *Containers) Create(n *Container) (ret *Container, err error)
- func (c *Containers) Delete(id models.ID) (ret *Container, err error)
- func (c *Containers) Get(id models.ID) *Container
- func (c *Containers) Init(log *logrus.Entry)
- func (c *Containers) List() (ret []*Container)
- func (c *Containers) NameGetID(name models.Name) models.ID
- func (c *Containers) SetState(id models.ID, state models.ContainerState) (ret *Container, err error)
- type EndpointObject
- type EndpointObjectType
- type Mount
- type MountDriver
- type MountDriverAttach
- type MountDriverBind
- type MountDriverNFS
- type MountDriverOverlay
- type Mounts
- func (m *Mounts) Get(id models.ID) *Mount
- func (m *Mounts) GetOrMount(mnt *Mount) (ret *Mount, err error)
- func (m *Mounts) Init(log *logrus.Entry)
- func (m *Mounts) List() (ret []*Mount)
- func (m *Mounts) Mount(mnt *Mount) (ret *Mount, err error)
- func (m *Mounts) Unmount(mnt *Mount, force bool) (ret *Mount, err error)
- type ObjectStore
- func (s *ObjectStore) Get(id models.ID) EndpointObject
- func (s *ObjectStore) Init()
- func (s *ObjectStore) List() []EndpointObject
- func (s *ObjectStore) ListType(t EndpointObjectType) []EndpointObject
- func (s *ObjectStore) RefAdd(id models.ID, i int64)
- func (s *ObjectStore) Register(o EndpointObject) EndpointObject
- func (s *ObjectStore) Unregister(o EndpointObject)
- func (s *ObjectStore) Update(o EndpointObject)
Constants ¶
This section is empty.
Variables ¶
var API = &APIType{ Store: &ObjectStore{}, Mounts: &Mounts{}, Attachments: &Attachments{}, Containers: &Containers{}, MountDir: "/var/run/imageapi/mounts", LogDir: "/var/run/imageapi/logs", CollectInterval: time.Second, }
var AttachDrivers = map[string]AttachDriver{}
var AttachmentsAttachHandler = attachments.AttachHandlerFunc(func(params attachments.AttachParams) middleware.Responder { var err error var a *Attach if a, err = API.Attachments.Attach((*Attach)(params.Attach)); err != nil { err = errorSanitize(err) return attachments.NewAttachDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return attachments.NewAttachCreated().WithPayload((*models.Attach)(a)) })
Attachments
var AttachmentsDeleteAttachHandler = attachments.DeleteAttachHandlerFunc(func(params attachments.DeleteAttachParams) middleware.Responder { var err error var a *Attach if a, err = API.Attachments.Detach(&Attach{ID: (models.ID)(params.ID)}, *params.Force); err != nil { err = errorSanitize(err) return attachments.NewDeleteAttachDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return attachments.NewDeleteAttachOK().WithPayload((*models.Attach)(a)) })
var AttachmentsListAttachmentsHandler = attachments.ListAttachmentsHandlerFunc(func(params attachments.ListAttachmentsParams) middleware.Responder { as := []*models.Attach{} if params.ID != nil { a := API.Attachments.Get((models.ID)(*params.ID)) if a == nil { return attachments.NewDeleteAttachDefault(errorToHTTP[ErrNotFound]).WithPayload(errorPayload(ErrNotFound)) } as = append(as, (*models.Attach)(a)) } else { ia := API.Attachments.List() for _, a := range ia { if params.Kind != nil && a.Kind != *params.Kind { continue } as = append(as, (*models.Attach)(a)) } } return attachments.NewListAttachmentsOK().WithPayload(as) })
var ContainersCreateContainerHandler = containers.CreateContainerHandlerFunc(func(params containers.CreateContainerParams) middleware.Responder { var err error var c *Container if c, err = API.Containers.Create(&Container{Container: params.Container}); err != nil { err = errorSanitize(err) return containers.NewCreateContainerDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return containers.NewCreateContainerCreated().WithPayload(c.Container) })
Containers
var ContainersDeleteContainerHandler = containers.DeleteContainerHandlerFunc(func(params containers.DeleteContainerParams) middleware.Responder { var err error var c *Container var id models.ID if *params.Force { return containers.NewDeleteContainerDefault(501).WithPayload(&models.Error{Code: 501, Message: swag.String("forced container deletion is not yet implemented")}) } if params.ID == nil { if params.Name == nil { return containers.NewDeleteContainerDefault(errorToHTTP[ErrInvalDat]).WithPayload(&models.Error{Code: int64(errorToHTTP[ErrInvalDat]), Message: swag.String("either ID or Name must be provided")}) } id = API.Containers.NameGetID((models.Name)(*params.Name)) } else { id = models.ID(*params.ID) } if id < 1 { return containers.NewDeleteContainerDefault(errorToHTTP[ErrNotFound]).WithPayload(errorPayload(ErrNotFound)) } if c, err = API.Containers.Delete(id); err != nil { err = errorSanitize(err) return containers.NewDeleteContainerDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return containers.NewDeleteContainerOK().WithPayload(c.Container) })
var ContainersListContainersHandler = containers.ListContainersHandlerFunc(func(params containers.ListContainersParams) middleware.Responder { cs := []*models.Container{} if params.ID != nil || params.Name != nil { // Get var id models.ID if params.ID == nil { id = API.Containers.NameGetID((models.Name)(*params.Name)) } else { id = models.ID(*params.ID) } if id < 1 { return containers.NewListContainersDefault(errorToHTTP[ErrNotFound]).WithPayload(errorPayload(ErrNotFound)) } c := API.Containers.Get(id) if c == nil { return containers.NewListContainersDefault(errorToHTTP[ErrNotFound]).WithPayload(errorPayload(ErrNotFound)) } cs = append(cs, c.Container) } else { is := API.Containers.List() for _, c := range is { if params.State != nil && c.Container.State != models.ContainerState(*params.State) { continue } cs = append(cs, c.Container) } } return containers.NewListContainersOK().WithPayload(cs) })
var ContainersSetContainerStateHandler = containers.SetContainerStateHandlerFunc(func(params containers.SetContainerStateParams) middleware.Responder { var id models.ID if params.ID == nil { if params.Name == nil { return containers.NewSetContainerStateDefault(errorToHTTP[ErrInvalDat]).WithPayload(&models.Error{Code: int64(errorToHTTP[ErrInvalDat]), Message: swag.String("either ID or Name must be provided")}) } id = API.Containers.NameGetID((models.Name)(*params.Name)) } else { id = models.ID(*params.ID) } if id < 1 { return containers.NewSetContainerStateDefault(errorToHTTP[ErrNotFound]).WithPayload(errorPayload(ErrNotFound)) } var c *Container var err error if c, err = API.Containers.SetState(id, models.ContainerState(params.State)); err != nil { err = errorSanitize(err) return containers.NewCreateContainerDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return containers.NewSetContainerStateOK().WithPayload(c.Container) })
var ErrBusy = errors.New("object is busy")
var ErrFail = errors.New("operation failed")
var ErrInvalDat = errors.New("invalid data type")
var ErrNoDrv = errors.New("no driver found for this object type")
var ErrNotFound = errors.New("not found")
var ErrSrv = errors.New("internal server error")
var LogStringToLL = map[string]logrus.Level{ "PANIC": logrus.PanicLevel, "FATAL": logrus.FatalLevel, "ERROR": logrus.ErrorLevel, "WARN": logrus.WarnLevel, "INFO": logrus.InfoLevel, "DEBUG": logrus.DebugLevel, "TRACE": logrus.TraceLevel, }
var MountDrivers = map[string]MountDriver{}
var MountsDeleteMountHandler = mounts.DeleteMountHandlerFunc(func(params mounts.DeleteMountParams) middleware.Responder { var err error var m *Mount if m, err = API.Mounts.Unmount(&Mount{ID: (models.ID)(params.ID)}, *params.Force); err != nil { err = errorSanitize(err) return mounts.NewDeleteMountDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return mounts.NewDeleteMountOK().WithPayload((*models.Mount)(m)) })
var MountsListMountsHandler = mounts.ListMountsHandlerFunc(func(params mounts.ListMountsParams) middleware.Responder { ms := []*models.Mount{} if params.ID != nil { m := API.Mounts.Get((models.ID)(*params.ID)) if m == nil { return mounts.NewListMountsDefault(errorToHTTP[ErrNotFound]).WithPayload(errorPayload(ErrNotFound)) } ms = append(ms, (*models.Mount)(m)) } else { im := API.Mounts.List() for _, m := range im { if params.Kind != nil && m.Kind != *params.Kind { continue } ms = append(ms, (*models.Mount)(m)) } } return mounts.NewListMountsOK().WithPayload(ms) })
var MountsMountHandler = mounts.MountHandlerFunc(func(params mounts.MountParams) middleware.Responder { var err error var m *Mount if m, err = API.Mounts.Mount((*Mount)(params.Mount)); err != nil { err = errorSanitize(err) return mounts.NewMountDefault(errorToHTTP[err]).WithPayload(errorPayload(err)) } return mounts.NewMountCreated().WithPayload((*models.Mount)(m)) })
Mounts
Functions ¶
Types ¶
type APIType ¶ added in v0.2.0
type APIType struct { Store *ObjectStore Mounts *Mounts Attachments *Attachments Containers *Containers Log *logrus.Entry MountDir, LogDir string CollectInterval time.Duration }
type Attach ¶ added in v0.2.0
func (*Attach) EndpointObjectType ¶ added in v0.2.0
func (a *Attach) EndpointObjectType() EndpointObjectType
type AttachDriver ¶ added in v0.2.0
type AttachDriverIscsi ¶ added in v0.2.0
type AttachDriverIscsi struct {
// contains filtered or unexported fields
}
func (*AttachDriverIscsi) Attach ¶ added in v0.2.0
func (a *AttachDriverIscsi) Attach(att *Attach) (ret *Attach, err error)
func (*AttachDriverIscsi) Detach ¶ added in v0.2.0
func (a *AttachDriverIscsi) Detach(att *Attach) (ret *Attach, err error)
func (*AttachDriverIscsi) Init ¶ added in v0.2.0
func (a *AttachDriverIscsi) Init(log *logrus.Entry)
type AttachDriverLocal ¶ added in v0.2.0
type AttachDriverLocal struct {
// contains filtered or unexported fields
}
func (*AttachDriverLocal) Attach ¶ added in v0.2.0
func (a *AttachDriverLocal) Attach(att *Attach) (ret *Attach, err error)
func (*AttachDriverLocal) Detach ¶ added in v0.2.0
func (a *AttachDriverLocal) Detach(att *Attach) (ret *Attach, err error)
func (*AttachDriverLocal) Init ¶ added in v0.2.0
func (a *AttachDriverLocal) Init(log *logrus.Entry)
type AttachDriverLoopback ¶ added in v0.2.0
type AttachDriverLoopback struct {
// contains filtered or unexported fields
}
func (*AttachDriverLoopback) Attach ¶ added in v0.2.0
func (a *AttachDriverLoopback) Attach(att *Attach) (ret *Attach, err error)
func (*AttachDriverLoopback) Detach ¶ added in v0.2.0
func (a *AttachDriverLoopback) Detach(att *Attach) (ret *Attach, err error)
func (*AttachDriverLoopback) Init ¶ added in v0.2.0
func (a *AttachDriverLoopback) Init(log *logrus.Entry)
type AttachDriverRbd ¶ added in v0.2.0
type AttachDriverRbd struct {
// contains filtered or unexported fields
}
func (*AttachDriverRbd) Attach ¶ added in v0.2.0
func (a *AttachDriverRbd) Attach(att *Attach) (ret *Attach, err error)
func (*AttachDriverRbd) Detach ¶ added in v0.2.0
func (a *AttachDriverRbd) Detach(att *Attach) (ret *Attach, err error)
func (*AttachDriverRbd) Init ¶ added in v0.2.0
func (a *AttachDriverRbd) Init(log *logrus.Entry)
type Attachments ¶ added in v0.2.0
type Attachments struct {
// contains filtered or unexported fields
}
func (*Attachments) Attach ¶ added in v0.2.0
func (a *Attachments) Attach(at *Attach) (ret *Attach, err error)
Attach attaches an attachment
func (*Attachments) Detach ¶ added in v0.2.0
func (a *Attachments) Detach(at *Attach, force bool) (ret *Attach, err error)
Detach detaches an attachment
func (*Attachments) Get ¶ added in v0.2.0
func (a *Attachments) Get(id models.ID) *Attach
Get gets an attachment by ID
func (*Attachments) GetOrAttach ¶ added in v0.2.0
func (a *Attachments) GetOrAttach(at *Attach) (ret *Attach, err error)
GetOrAttach gets an attachment if it already exists, if it does not, it attempts to attach it
func (*Attachments) Init ¶ added in v0.2.0
func (a *Attachments) Init(log *logrus.Entry)
Init initializes the attachment subsystem
func (*Attachments) List ¶ added in v0.2.0
func (a *Attachments) List() (ret []*Attach)
List lists all attachments
type Container ¶ added in v0.2.0
Unlike other subsystems, we wrap models.Container with extra data
func (*Container) EndpointObjectType ¶ added in v0.2.0
func (c *Container) EndpointObjectType() EndpointObjectType
type Containers ¶
type Containers struct {
// contains filtered or unexported fields
}
func (*Containers) Create ¶ added in v0.2.0
func (c *Containers) Create(n *Container) (ret *Container, err error)
func (*Containers) Delete ¶ added in v0.2.0
func (c *Containers) Delete(id models.ID) (ret *Container, err error)
func (*Containers) Init ¶ added in v0.2.0
func (c *Containers) Init(log *logrus.Entry)
func (*Containers) List ¶ added in v0.2.0
func (c *Containers) List() (ret []*Container)
func (*Containers) NameGetID ¶ added in v0.2.0
func (c *Containers) NameGetID(name models.Name) models.ID
NameGetID will return the ID for a given name This is used to implement the `byname` calls If the name is not found, it will return -1
func (*Containers) SetState ¶ added in v0.2.0
func (c *Containers) SetState(id models.ID, state models.ContainerState) (ret *Container, err error)
type EndpointObject ¶ added in v0.2.0
type EndpointObjectType ¶ added in v0.2.0
type EndpointObjectType uint8
const ( EndpointObjectAttach EndpointObjectType = iota EndpointObjectMount EndpointObjectType = iota EndpointObjectContainer EndpointObjectType = iota )
Allows inspection without reflection
type Mount ¶
func (*Mount) EndpointObjectType ¶ added in v0.2.0
func (m *Mount) EndpointObjectType() EndpointObjectType
type MountDriver ¶ added in v0.2.0
type MountDriverAttach ¶ added in v0.2.0
type MountDriverAttach struct {
// contains filtered or unexported fields
}
func (*MountDriverAttach) Init ¶ added in v0.2.0
func (m *MountDriverAttach) Init(log *logrus.Entry)
type MountDriverBind ¶ added in v0.2.0
type MountDriverBind struct {
// contains filtered or unexported fields
}
func (*MountDriverBind) Init ¶ added in v0.2.0
func (m *MountDriverBind) Init(log *logrus.Entry)
type MountDriverNFS ¶ added in v0.2.0
type MountDriverNFS struct {
// contains filtered or unexported fields
}
func (*MountDriverNFS) Init ¶ added in v0.2.0
func (m *MountDriverNFS) Init(log *logrus.Entry)
type MountDriverOverlay ¶ added in v0.2.0
type MountDriverOverlay struct {
// contains filtered or unexported fields
}
func (*MountDriverOverlay) Init ¶ added in v0.2.0
func (m *MountDriverOverlay) Init(log *logrus.Entry)
type Mounts ¶ added in v0.2.0
type Mounts struct {
// contains filtered or unexported fields
}
func (*Mounts) GetOrMount ¶ added in v0.2.0
GetOrMount gets a mount if it already exists, if it does not, it attempts to mount
type ObjectStore ¶ added in v0.2.0
type ObjectStore struct {
// contains filtered or unexported fields
}
The ObjectStore centralize EndpointObject storage
func (*ObjectStore) Get ¶ added in v0.2.0
func (s *ObjectStore) Get(id models.ID) EndpointObject
func (*ObjectStore) Init ¶ added in v0.2.0
func (s *ObjectStore) Init()
func (*ObjectStore) List ¶ added in v0.2.0
func (s *ObjectStore) List() []EndpointObject
func (*ObjectStore) ListType ¶ added in v0.2.0
func (s *ObjectStore) ListType(t EndpointObjectType) []EndpointObject
func (*ObjectStore) Register ¶ added in v0.2.0
func (s *ObjectStore) Register(o EndpointObject) EndpointObject
func (*ObjectStore) Unregister ¶ added in v0.2.0
func (s *ObjectStore) Unregister(o EndpointObject)
func (*ObjectStore) Update ¶ added in v0.2.0
func (s *ObjectStore) Update(o EndpointObject)