qcache_inventory

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2017 License: Apache-2.0 Imports: 15 Imported by: 7

README

cache-inventory

Inventory cache for qframe, to enable queries against an in-memory inventory snapshot.

Integration test

The script within cmd/main.go uses a request to query for a given container name and reuses the respons' IP to query the same container by his IP.

Container using a bridge

The container was started like this: docker run -ti --rm --name bridge-cnt ubuntu tail -f /dev/null

$ go run main.go bridge-cnt
[  INFO] Dispatch broadcast for Data, Done and Tick
[NOTICE]       inventory Name:inventory  >> Start inventory v0.3.1
[  INFO]       inventory Name:inventory  >> Create query for container by Name 'bridge-cnt' : qcache_inventory.NewNameContainerRequest('q1', 'bridge-cnt')
[NOTICE]   docker-events Name:docker-events >> Start docker-events collector v0.3.0
[ DEBUG]       inventory Name:inventory  >> Received InventoryRequest for {2017-08-29 15:21:56.691092464 +0000 UTC m=+1.009847856 q1 1s bridge-cnt   0xc420204840}
[  INFO]   docker-events Name:docker-events >> Connected to 'moby' / v'17.07.0-ce-rc3'
[ DEBUG]       inventory Name:inventory  >> Add CntID:ad4bbcdfd71c5 into Inventory (name:/bridge-cnt, IPs:172.17.0.3)
[ DEBUG]       inventory Name:inventory  >> Add CntID:4a4b8d12da535 into Inventory (name:/modest_einstein, IPs:172.17.0.2)
[  INFO]       inventory Name:inventory  >> Got InventoryResponse: Container 'bridge-cnt' has ID-digest:ad4bbcdfd71c5
[  INFO]       inventory Name:inventory  >> Use IP from first query response container (network:bridge) to generate another query: qcache_inventory.NewIPContainerRequest('q2', '172.17.0.3')
[ DEBUG]       inventory Name:inventory  >> Received InventoryRequest for {2017-08-29 15:21:57.190813115 +0000 UTC m=+1.509569306 q2 2s   172.17.0.3 0xc4202c2900}
[  INFO]       inventory Name:inventory  >> Got InventoryResponse: Container w/ IP 172.17.0.3 has Digest:ad4bbcdfd71c5
Container connected to a network.

Container start:

$ docker network create testnet --subnet=192.168.0.0/16
b804cd1f408c7c757b2541d5ccaf75991c18d7ec005be608b774c9b49929f9a4
$ docker run -ti --rm --name testnet-cnt --network testnet ubuntu bash
root@eb1da0b083f0:/#

Run the tool.

$ go run main.go testnet-cnt
[  INFO] Dispatch broadcast for Data, Done and Tick
[NOTICE]       inventory Name:inventory  >> Start inventory v0.3.1
[  INFO]       inventory Name:inventory  >> Create query for container by Name 'testnet-cnt' : qcache_inventory.NewNameContainerRequest('q1', 'testnet-cnt')
[ DEBUG]       inventory Name:inventory  >> Received InventoryRequest for {2017-08-29 15:26:57.896243684 +0000 UTC m=+1.011992256 q1 1s testnet-cnt   0xc420204a80}
[NOTICE]   docker-events Name:docker-events >> Start docker-events collector v0.3.0
[  INFO]   docker-events Name:docker-events >> Connected to 'moby' / v'17.07.0-ce-rc3'
[ DEBUG]       inventory Name:inventory  >> Add CntID:eb1da0b083f01 into Inventory (name:/testnet-cnt, IPs:192.168.0.2)
[ DEBUG]       inventory Name:inventory  >> Add CntID:4a4b8d12da535 into Inventory (name:/modest_einstein, IPs:172.17.0.2)
[  INFO]       inventory Name:inventory  >> Got InventoryResponse: Container 'testnet-cnt' has ID-digest:eb1da0b083f01
[  INFO]       inventory Name:inventory  >> Use IP from first query response container (network:testnet) to generate another query: qcache_inventory.NewIPContainerRequest('q2', '192.168.0.2')
[ DEBUG]       inventory Name:inventory  >> Received InventoryRequest for {2017-08-29 15:26:58.404090241 +0000 UTC m=+1.519842310 q2 2s   192.168.0.2 0xc4202c27e0}
[  INFO]       inventory Name:inventory  >> Got InventoryResponse: Container w/ IP 192.168.0.2 has Digest:eb1da0b083f01

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetList added in v0.3.2

func GetList(s mapset.Set) (res []string)

Types

type ContainerRequest

type ContainerRequest struct {
	IssuedAt time.Time
	Source   string
	Timeout  time.Duration
	Name     string
	ID       string
	IP       string
	Back     chan Response
}

func NewContainerRequest

func NewContainerRequest(src string, to time.Duration) ContainerRequest

func NewIDContainerRequest

func NewIDContainerRequest(src, id string) ContainerRequest

func NewIPContainerRequest

func NewIPContainerRequest(src, ip string) ContainerRequest

func NewNameContainerRequest

func NewNameContainerRequest(src, name string) ContainerRequest

func (ContainerRequest) Equal

func (this ContainerRequest) Equal(other Response) (err error)

func (ContainerRequest) EqualCnt added in v0.3.2

func (this ContainerRequest) EqualCnt(other *types.ContainerJSON) (err error)

func (ContainerRequest) EqualIPS added in v0.3.2

func (this ContainerRequest) EqualIPS(ips []string) (err error)

func (*ContainerRequest) TimedOut

func (cr *ContainerRequest) TimedOut() bool

type Inventory

type Inventory struct {
	Version         string
	Data            map[string]Response
	PendingRequests []ContainerRequest
	// contains filtered or unexported fields
}

func NewInventory

func NewInventory() Inventory

func (*Inventory) CheckRequests

func (inv *Inventory) CheckRequests()

CheckRequests iterates over all requests and responses if the request can be fulfilled

func (*Inventory) GetItem

func (i *Inventory) GetItem(key string) (out Response, err error)

func (*Inventory) HandleRequest

func (i *Inventory) HandleRequest(req ContainerRequest) (err error)

func (*Inventory) ServeRequest

func (i *Inventory) ServeRequest(req ContainerRequest) (err error)

func (*Inventory) SetItem

func (i *Inventory) SetItem(key string, item *types.ContainerJSON, ips []string) (err error)

type Plugin

type Plugin struct {
	*qtypes_plugin.Plugin
	Inventory Inventory
	// contains filtered or unexported fields
}

func New

func New(qChan qtypes_qchannel.QChan, cfg *config.Config, name string) (Plugin, error)

func (*Plugin) AddNetworkIPs added in v0.3.2

func (p *Plugin) AddNetworkIPs(ips mapset.Set, container *types.ContainerJSON) (res []string, err error)

func (*Plugin) LookUpContainer added in v0.3.3

func (p *Plugin) LookUpContainer(cnt *types.ContainerJSON)

func (*Plugin) Run

func (p *Plugin) Run()

Run fetches everything from the Data channel and flushes it to stdout

type Response

type Response struct {
	Container *types.ContainerJSON
	Ips       []string
	Error     error
}

func NewFAILResponse

func NewFAILResponse(err error) Response

func NewOKResponse

func NewOKResponse(cnt *types.ContainerJSON, ips []string) Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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