api

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2021 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Overview

initialization for internal data structures & processes

Index

Constants

This section is empty.

Variables

View Source
var API = &APIType{
	Store:           &ObjectStore{},
	Mounts:          &Mounts{},
	Attachments:     &Attachments{},
	Containers:      &Containers{},
	MountDir:        "/var/run/imageapi/mounts",
	LogDir:          "/var/run/imageapi/logs",
	CollectInterval: time.Second,
}
View Source
var AttachDrivers = map[string]AttachDriver{}
View Source
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

View Source
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))
})
View Source
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)
})
View Source
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

View Source
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)
})
View Source
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)
})
View Source
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)
})
View Source
var ErrBusy = errors.New("object is busy")
View Source
var ErrFail = errors.New("operation failed")
View Source
var ErrInvalDat = errors.New("invalid data type")
View Source
var ErrNoDrv = errors.New("no driver found for this object type")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrSrv = errors.New("internal server error")
View Source
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,
}
View Source
var MountDrivers = map[string]MountDriver{}
View Source
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))
})
View Source
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)
})
View Source
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

func ForkInit added in v0.1.5

func ForkInit()

func Init added in v0.2.0

func Init()

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

type Attach models.Attach

func (*Attach) EndpointObjectType added in v0.2.0

func (a *Attach) EndpointObjectType() EndpointObjectType

func (*Attach) GetID added in v0.2.0

func (a *Attach) GetID() models.ID

func (*Attach) GetRefs added in v0.2.0

func (a *Attach) GetRefs() int64

func (*Attach) RefAdd added in v0.2.0

func (a *Attach) RefAdd(i int64)

func (*Attach) SetID added in v0.2.0

func (a *Attach) SetID(id models.ID)

type AttachDriver added in v0.2.0

type AttachDriver interface {
	Init(*logrus.Entry)
	Attach(*Attach) (*Attach, error)
	Detach(*Attach) (*Attach, error)
}

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

type Container struct {
	Container *models.Container
	// contains filtered or unexported fields
}

Unlike other subsystems, we wrap models.Container with extra data

func (*Container) EndpointObjectType added in v0.2.0

func (c *Container) EndpointObjectType() EndpointObjectType

func (*Container) GetID added in v0.2.0

func (c *Container) GetID() models.ID

func (*Container) GetRefs added in v0.2.0

func (c *Container) GetRefs() int64

func (*Container) RefAdd added in v0.2.0

func (c *Container) RefAdd(i int64)

func (*Container) SetID added in v0.2.0

func (c *Container) SetID(id models.ID)

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) Get added in v0.2.0

func (c *Containers) Get(id models.ID) *Container

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 EndpointObject interface {
	SetID(models.ID)
	GetID() models.ID
	GetRefs() int64
	RefAdd(int64)
	EndpointObjectType() EndpointObjectType
}

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

type Mount models.Mount

func (*Mount) EndpointObjectType added in v0.2.0

func (m *Mount) EndpointObjectType() EndpointObjectType

func (*Mount) GetID added in v0.2.0

func (m *Mount) GetID() models.ID

func (*Mount) GetRefs added in v0.2.0

func (m *Mount) GetRefs() int64

func (*Mount) RefAdd added in v0.2.0

func (m *Mount) RefAdd(i int64)

func (*Mount) SetID added in v0.2.0

func (m *Mount) SetID(id models.ID)

type MountDriver added in v0.2.0

type MountDriver interface {
	Init(*logrus.Entry)
	Mount(*Mount) (*Mount, error)
	Unmount(*Mount) (*Mount, error)
}

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)

func (*MountDriverAttach) Mount added in v0.2.0

func (m *MountDriverAttach) Mount(mnt *Mount) (ret *Mount, err error)

func (*MountDriverAttach) Unmount added in v0.2.0

func (m *MountDriverAttach) Unmount(mnt *Mount) (ret *Mount, err error)

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)

func (*MountDriverBind) Mount added in v0.2.0

func (m *MountDriverBind) Mount(mnt *Mount) (ret *Mount, err error)

func (*MountDriverBind) Unmount added in v0.2.0

func (m *MountDriverBind) Unmount(mnt *Mount) (ret *Mount, err error)

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)

func (*MountDriverNFS) Mount added in v0.2.0

func (m *MountDriverNFS) Mount(mnt *Mount) (ret *Mount, err error)

func (*MountDriverNFS) Unmount added in v0.2.0

func (m *MountDriverNFS) Unmount(mnt *Mount) (ret *Mount, err error)

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)

func (*MountDriverOverlay) Mount added in v0.2.0

func (m *MountDriverOverlay) Mount(mnt *Mount) (r *Mount, err error)

func (*MountDriverOverlay) Unmount added in v0.2.0

func (m *MountDriverOverlay) Unmount(mnt *Mount) (ret *Mount, err error)

type Mounts added in v0.2.0

type Mounts struct {
	// contains filtered or unexported fields
}

func (*Mounts) Get added in v0.2.0

func (m *Mounts) Get(id models.ID) *Mount

Get gets a mount by id

func (*Mounts) GetOrMount added in v0.2.0

func (m *Mounts) GetOrMount(mnt *Mount) (ret *Mount, err error)

GetOrMount gets a mount if it already exists, if it does not, it attempts to mount

func (*Mounts) Init added in v0.2.0

func (m *Mounts) Init(log *logrus.Entry)

Init initializes the mounts subsystem

func (*Mounts) List added in v0.2.0

func (m *Mounts) List() (ret []*Mount)

List lists all mounts

func (*Mounts) Mount added in v0.2.0

func (m *Mounts) Mount(mnt *Mount) (ret *Mount, err error)

Mount based on a generic specification

func (*Mounts) Unmount added in v0.2.0

func (m *Mounts) Unmount(mnt *Mount, force bool) (ret *Mount, err error)

Unmount based on a generic specification

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 (*ObjectStore) RefAdd added in v0.2.0

func (s *ObjectStore) RefAdd(id models.ID, i int64)

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL