inventory

package
v0.0.0-...-ee673a8 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Running Instance state
	Running InstanceState = "Running"
	// Stopped Instance state
	Stopped = "Stopped"
	// Terminated Instance state
	Terminated = "Terminated"
	// Unknown Instance state
	Unknown = "Unknown"
)
View Source
const (
	// AWSProvider - Amazon Web Services Cloud Provider
	AWSProvider CloudProvider = "AWS"
	// AzureProvider - Microsoft Azure Cloud Provider
	AzureProvider = "Azure"
	// GCPProvider - Google Cloud Platform Cloud Provider
	GCPProvider = "GCP"
	// UnknownProvider - Google Cloud Platform Cloud Provider
	UnknownProvider = "UNKNOWN"
)
View Source
const (
	// ClusterTagKey string to identify to which cluster is the instance associated
	ClusterTagKey string = "kubernetes.io/cluster/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	// Account's name. It's considered as an uniq key. Two accounts with same
	// name can't belong to same Inventory
	Name string `db:"name" json:"name"`

	// Infrastructure provider identifier.
	Provider CloudProvider `db:"provider" json:"provider"`

	// List of clusters deployed on this account indexed by Cluster's name
	Clusters map[string]*Cluster
	// contains filtered or unexported fields
}

Account defines an infrastructure provider account

func NewAccount

func NewAccount(name string, provider CloudProvider, user string, password string) *Account

NewAccount create a new Could Provider account to store its instances

func (*Account) AddCluster

func (a *Account) AddCluster(cluster Cluster) error

AddCluster adds a cluster to the stock

func (Account) GetCluster

func (a Account) GetCluster(name string) *Cluster

GetCluster returns cluster on stock by name

func (Account) GetPassword

func (a Account) GetPassword() string

GetPassword returns the password value

func (Account) GetUser

func (a Account) GetUser() string

GetUser returns the username value

func (Account) IsClusterOnAccount

func (a Account) IsClusterOnAccount(name string) bool

IsClusterOnAccount checks if a cluster is already in the Stock

func (Account) PrintAccount

func (a Account) PrintAccount()

PrintAccount prints account info and every cluster on it by stdout

type CloudProvider

type CloudProvider string

CloudProvider defines the cloud provider of the instance

type Cluster

type Cluster struct {
	// Cluster's Name. Must be unique per Account
	Name string `db:"name" json:"name"`

	// Infrastructure provider identifier.
	Provider CloudProvider `db:"provider" json:"provider"`

	// Defines the status of the cluster if its infrastructure is running or not
	Status InstanceState `db:"state" json:"status"`

	// The region of the infrastructure provider in which the cluster is deployed
	Region string `db:"region" json:"region"`

	// Account name which this cluster belongs to
	AccountName string `db:"account_name" json:"accountName"`

	// Openshift Console URL. Might not be accesible if its protected
	ConsoleLink string `db:"console_link" json:"consoleLink"`

	// Cluster's instance (nodes) lists
	Instances []Instance
}

Cluster is the object to store Openshift Clusters and its properties

func NewCluster

func NewCluster(name string, provider CloudProvider, region string, accountName string, consoleLink string) Cluster

NewCluster creates a new cluster instance

func (*Cluster) AddInstance

func (c *Cluster) AddInstance(instance Instance)

AddInstance add a new instance to a cluster

func (Cluster) PrintCluster

func (c Cluster) PrintCluster()

PrintCluster prints cluster info

func (*Cluster) UpdateStatus

func (c *Cluster) UpdateStatus()

UpdateStatus evaluate the status of the cluster checking how many of the nodes are in Running or Stopped status. As Openshift needs at lease 3 nodes running to be considered correctly Running (3 master nodes), but we cant' figure out which Instance is a master node, if at least 3 of the Cluster instances are running, Cluster will be considered as Running also. If the instances count is less than minInstances, Cluster would be considered as Unknown status TODO: find out a more trustable approach to evaluate cluster status

type Instance

type Instance struct {
	// Uniq Identifier of the instance
	ID string `db:"id" json:"id"`

	// Instance Name. In some Cloud Providers, the name is managed as a Tag
	Name string `db:"name" json:"name"`

	// Instance provider (public/private cloud provider)
	Provider CloudProvider `db:"provider" json:"provider"`

	// Instance type/size/flavour
	InstanceType string `db:"instance_type" json:"instanceType"`

	// Region/Availability Zone in which the instance is running on
	Region string `db:"region" json:"region"`

	// Instance Status
	State InstanceState `db:"state" json:"state"`

	// ClusterName
	ClusterName string `db:"cluster_name" json:"clusterName"`

	// Instance Tags as key-value array
	Tags []Tag `json:"tags"`
}

Instance model a cloud provider instance TODO: doc variables

func NewInstance

func NewInstance(id string, name string, provider CloudProvider, instanceType string, region string, state InstanceState, clusterName string, tags []Tag) *Instance

NewInstance returns a new Instance object

func (Instance) PrintInstance

func (i Instance) PrintInstance()

PrintInstance prints Instance details

func (Instance) String

func (i Instance) String() string

type InstanceState

type InstanceState string

InstanceState defines the status of the instance

func AsInstanceState

func AsInstanceState(status string) InstanceState

AsInstanceState converts the incoming argument into a InstanceState type

type Inventory

type Inventory struct {
	// Accounts map indexed by Account's Name
	Accounts map[string]Account `redis:"accounts" json:"accounts"`

	// Date of Inventory creation/update
	CreationTimestamp time.Time `redis:"creationTimestamp" json:"creationTimestamp"`
}

Inventory object to store inventored resources

func NewInventory

func NewInventory() *Inventory

NewInventory creates a new Inventory variable

func (*Inventory) AddAccount

func (s *Inventory) AddAccount(account Account) error

AddAccount adds a new account into the Inventory

func (Inventory) IsAccountOnInventory

func (s Inventory) IsAccountOnInventory(name string) bool

IsAccountOnInventory checks if a cluster is already in the Inventory

func (Inventory) PrintInventory

func (s Inventory) PrintInventory()

PrintInventory prints the entire Inventory content

type Tag

type Tag struct {
	// Tag's key
	Key string `redis:"key" json:"key"`

	// Tag's Value
	Value string `redis:"value" json:"value"`
}

Tag model generic tags as a Key-Value object

func ConvertEC2TagtoTag

func ConvertEC2TagtoTag(ec2Tags []*ec2.Tag) []Tag

ConvertEC2TagtoTag transforms the EC2 instance tags into Tag

func NewTag

func NewTag(key string, value string) *Tag

NewTag returns a new generic tag struct

Jump to

Keyboard shortcuts

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