sources

package
v0.0.0-...-6fc9130 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedGetRemoteAddress = errors.New("failed to parse remote address")
View Source
var ErrNoDatasourceFound = errors.New("no datasource found")
View Source
var ErrNoMatchingMetadata = errors.New("no matching metadata found")

Functions

func GetServer

func GetServer(r *http.Request) net.IP

func Register

func Register(t config.SourceType, source Source)

Types

type CloudInitEventType

type CloudInitEventType string
const (
	CloudInitEventTypeStart CloudInitEventType = "start"
	CloudInitEventTypeEnd   CloudInitEventType = "finish"
)

type CloudInitReport

type CloudInitReport struct {
	Name        string              `json:"name"`
	Description string              `json:"description"`
	EventType   CloudInitEventType  `json:"event_type"`
	Origin      string              `json:"origin"`
	Timestamp   float64             `json:"timestamp"`
	Result      CloudInitResultType `json:"result"`
}

func (*CloudInitReport) ToReportMessage

func (c *CloudInitReport) ToReportMessage() ReportMessage

type CloudInitResultType

type CloudInitResultType string
const (
	CloudInitResultTypeSuccess CloudInitResultType = "SUCCESS"
	CloudInitResultTypeWarn    CloudInitResultType = "WARN"
	CloudInitResultTypeFail    CloudInitResultType = "FAIL"
)

type InterfaceType

type InterfaceType string
const (
	InterfaceTypePhysical InterfaceType = "physical"
	InterfaceTypeBond     InterfaceType = "bond"
	InterfaceTypeBridge   InterfaceType = "bridge"
	InterfaceTypeVLAN     InterfaceType = "vlan"
)

type Metadata

type Metadata struct {
	InstanceID       string                   `json:"id"`
	ProjectID        *string                  `json:"project_id"`
	InstanceType     string                   `json:"instance_type"`
	LocalHostname    string                   `json:"local_hostname"`
	PublicHostname   string                   `json:"public_hostname"`
	AvailabilityZone *string                  `json:"availability_zone"`
	UserData         []byte                   `json:"user_data"`
	VendorData       []byte                   `json:"vendor_data"`
	VendorData2      []byte                   `json:"vendor_data_2"`
	PublicKeys       map[string]ssh.PublicKey `json:"public_keys"`
	Username         *string                  `json:"username,omitempty"`
	Password         *string                  `json:"password,omitempty"`
	Interfaces       []MetadataInterface      `json:"interfaces"`
	Routes           []MetadataRoute          `json:"routes"`
}

func GetMetadata

func GetMetadata(r *http.Request) (*Metadata, error)

GetMetadata Try to find a valid metadata response by the registered sources.

func (Metadata) GetRoutes

func (m Metadata) GetRoutes() Routes

GetRoutes returns a map of all routes that are available for the given metadata.

func (Metadata) OpenStackMetaData

func (m Metadata) OpenStackMetaData() render.JSON

func (Metadata) OpenStackNetworkData

func (m Metadata) OpenStackNetworkData() render.JSON

func (Metadata) OpenStackVendorData

func (m Metadata) OpenStackVendorData(data []byte) render.JSON

type MetadataInterface

type MetadataInterface struct {
	MacAddress string           `json:"mac_address"`
	Name       string           `json:"name"`
	Type       InterfaceType    `json:"type"`
	Subnets    []MetadataSubnet `json:"subnets"`
	AcceptRA   *bool            `json:"accept-ra,omitempty"` //nolint:tagliatelle // cloud-init metadata requirement
}

type MetadataRoute

type MetadataRoute struct {
	Network string  `json:"network"`
	Netmask string  `json:"netmask"`
	Gateway *string `json:"gateway"`
}

type MetadataSubnet

type MetadataSubnet struct {
	IPv4       bool               `json:"ipv4"`
	IPv6       bool               `json:"ipv6"`
	Type       MetadataSubnetType `json:"type"`
	Address    *net.IP            `json:"address,omitempty"`
	Network    *net.IPNet         `json:"network,omitempty"`
	Gateway    *net.IP            `json:"gateway,omitempty"`
	DNSServers []string           `json:"dns_nameservers,omitempty"`
}

type MetadataSubnetType

type MetadataSubnetType string
const (
	MetadataSubnetTypeDHCP   MetadataSubnetType = "dhcp"
	MetadataSubnetTypeStatic MetadataSubnetType = "static"
)

type ReportMessage

type ReportMessage struct {
	IP        net.IP
	Message   string
	Timestamp time.Time
	Level     ReportMessageLevelType
}

type ReportMessageLevelType

type ReportMessageLevelType string
const (
	ReportMessageLevelTypeInfo    ReportMessageLevelType = "INFO"
	ReportMessageLevelTypeWarning ReportMessageLevelType = "WARNING"
	ReportMessageLevelTypeError   ReportMessageLevelType = "ERROR"
)

type Routes

type Routes map[string]render.Render

func (Routes) GetIndex

func (r Routes) GetIndex(c *gin.Context) render.Render

GetIndex Returns a directory index for the given response and URL.

type Source

type Source interface {
	Type() string
	Initialize(cfg SourceConfig) error
	GetMetadata(ip net.IP) (*Metadata, error)
	ReportLog(log ReportMessage) error
}

Source defines the interface for a metadata source, each source needs to implement this.

func Load

func Load() ([]Source, error)

type SourceConfig

type SourceConfig map[string]interface{}

func (SourceConfig) GetString

func (s SourceConfig) GetString(key string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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