inventory

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package inventory specifies the inventory service for the bolt inventory manager service.

Index

Constants

View Source
const (
	// HostgroupCapacity defines the max number of hosts that can be
	// created under a single hostgroup.
	HostgroupCapacity = 65000
	// InventoryCapacity specifies the maximum number of hostgroups
	// that can be stored inside a single inventory service.
	InventoryCapacity = 32764
)

Variables

This section is empty.

Functions

func APIInit

func APIInit(dataStorePath string, flushInterval uint16) *mux.Router

APIInit initializes the API service using the mux router engine and maps the endpoints to the required call handlers

Types

type Host

type Host struct {
	// hostname The address through which the host can be reached
	Hostname string
	// fcats The host specific variable
	Facts map[string]string
}

Host defines the structure for storing the data related to individual hosts including their names and local variables.

func NewHost

func NewHost(hostname string) *Host

NewHost defines the initializer for creating a new host

func (*Host) DeleteFact

func (h *Host) DeleteFact(name string)

DeleteFact deletes a host local fact from the mapping

func (Host) GetHostFacts

func (h Host) GetHostFacts() map[string]string

GetHostFacts returns the facts specific to the host

func (Host) GetHostName

func (h Host) GetHostName() string

GetHostName returns the hostname of the host

func (*Host) SetFact

func (h *Host) SetFact(name string, value string)

SetFact sets a new host fact as defined by the name and value

type HostGroup

type HostGroup struct {
	// name defines the name of the hostgroup through which it can be identified
	Name string
	// hosts defines a slice in which the hosts belonging to a particular hostgroup can be grouped together
	Hosts map[string]*Host
}

HostGroup defines the structure used for storing the data for the hostgroups that are registered individually in the inventory service.

func NewHostGroup

func NewHostGroup(name string) *HostGroup

NewHostGroup creates a new hostgroup for the inventory

func (*HostGroup) AddHost

func (hg *HostGroup) AddHost(h *Host)

AddHost adds a new host to the existing hostgroup

func (*HostGroup) DeleteHost

func (hg *HostGroup) DeleteHost(hname string)

DeleteHost removes a host from the Hostgroup

func (HostGroup) GetHost

func (hg HostGroup) GetHost(hname string) *Host

GetHost returns the host object provided the host name If the host doesn't exists, nil is returned

func (HostGroup) GetHostgroupName

func (hg HostGroup) GetHostgroupName() string

GetHostgroupName returns the name of the hostgroup

func (HostGroup) GetHosts

func (hg HostGroup) GetHosts() map[string]*Host

GetHosts returns all the hosts from a hostgroup

type Inventory

type Inventory struct {
	// hostgroups store the created hostgroups along with the data related
	// to the individual hosts inside them.
	Hostgroups map[string]*HostGroup
	// dataStorePath defines the path where the inventory database is created
	// on the disk. Whenever the service starts, it will look for the inventory
	// database at the specified path and try to load the data from it.
	DataStorePath string
	// flushInterval defines the time in milliseconds at which the inventory
	// flush service will write the data to the disk file.
	FlushInterval uint16
	// pendingOps provide the information about how many operations are still
	// pending to be written to the disk. This provides some data into how much
	// data is inventory service storing in its volatile state. This parameter
	// can also be used in future to enhance the inventory data flush service
	// to be more consistent and aggressive in writing the inventory to disk.
	PendingOps uint32

	// A Reader Writer mutex lock to help during the Marshalling of data
	sync.RWMutex
	// contains filtered or unexported fields
}

Inventory struct defines the global service based inventory database used to store the information of all the hostgroups and hosts. The Inventory struct is used to retrieve all the data that needs to be sent back as JSON to the requesting client. Since the service can suffer errors at any point of time, this database is written to the disk periodically so as to avoid any inconsistency that may take place due to unpredicted failure of the code.

func NewInventory

func NewInventory(dataStorePath string, flushInterval uint16) *Inventory

NewInventory creates a new Inventory store to be used by the Inventory Service.

func (Inventory) GetHostgroup

func (inv Inventory) GetHostgroup(hgname string) *HostGroup

GetHostgroup retrieves the hostgroup when the name is provided if the hostgroup doesn't exists, the call returns a nil

func (Inventory) GetHosts

func (inv Inventory) GetHosts(hgname string) map[string]*Host

GetHosts returns the list of hosts based in a hostgroup

func (*Inventory) GetInventory

func (inv *Inventory) GetInventory() map[string]*HostGroup

GetInventory retrieves the inventory from the inventory database

func (*Inventory) NewHost

func (inv *Inventory) NewHost(hgname string, hname string)

NewHost creates a new host under the specified hostgroup if the hostgroup doesn't exists, then it is created and then a new host added to it.

func (*Inventory) NewHostgroup

func (inv *Inventory) NewHostgroup(hgname string)

NewHostgroup creates a new hostgroup and adds it to the inventory. If the hostgroup already exists, the call returns without making any changes.

func (*Inventory) Save

func (inv *Inventory) Save()

Save defines a public interface for the inventory structure to write its data to the datastore.

func (*Inventory) SetHostFact

func (inv *Inventory) SetHostFact(hgname string, hname string, fname string, fval string) bool

SetHostFact sets a new fact for the host. If the fact already exists, it's value is overwritten

func (*Inventory) StopInventory

func (inv *Inventory) StopInventory()

StopInventory signals the inventory service to exit gracefully

func (*Inventory) WriteData

func (inv *Inventory) WriteData(data []byte) bool

WriteData writes the binary data to the datastore and returns a boolean to indicate if the write was successful or not.

Jump to

Keyboard shortcuts

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