gofish

package module
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: BSD-3-Clause Imports: 17 Imported by: 61

README

Gofish - Redfish and Swordfish client library

Go Doc Go Report Card Releases LICENSE

Gofish Logo

Introduction

Gofish is a Golang library for interacting with DMTF Redfish and SNIA Swordfish enabled devices.

Usage

Basic usage would be:


package main

import (
    "fmt"

    "github.com/stmcginnis/gofish"
)

func main() {
    c, err := gofish.ConnectDefault("http://localhost:5000")
    if err != nil {
        panic(err)
    }

    service := c.Service
    chassis, err := service.Chassis()
    if err != nil {
        panic(err)
    }

    for _, chass := range chassis {
        fmt.Printf("Chassis: %#v\n\n", chass)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deref added in v0.21.0

func Deref[T any](v *T) T

Deref is a convenience wrapper to get optional values from schema objects.

Pointer values in objects are optional values, so if you want to see if the service reported a value, then you need to explicitly check for nil:

// Did we get a display order?
if attribuate.DisplayOrder {
		// Nothing reported
}

But if we don't care if it was reported by the service and we just want its value, being fine with its zero-value if it wasn't provided, we can do:

var value int
value = Deref(attribute.DisplayOrder)

func ToRef added in v0.21.0

func ToRef[T any](v T) *T

ToRef is a convenience wrapper to get a pointer to a value. This is useful when assigning a value to an optional API object field that expects a pointer.

Types

type APIClient

type APIClient struct {

	// HTTPClient is for direct http actions
	HTTPClient *http.Client

	// Service is the ServiceRoot of this Redfish instance
	Service *Service

	Settings schemas.ClientSettings
	// contains filtered or unexported fields
}

APIClient represents a connection to a Redfish/Swordfish enabled service or device.

func Connect

func Connect(config ClientConfig) (c *APIClient, err error)

Connect creates a new client connection to a Redfish service.

func ConnectContext added in v0.8.0

func ConnectContext(ctx context.Context, config ClientConfig) (c *APIClient, err error)

ConnectContext is the same as Connect, but sets the ctx.

func ConnectDefault

func ConnectDefault(endpoint string) (c *APIClient, err error)

ConnectDefault creates an unauthenticated connection to a Redfish service.

func ConnectDefaultContext added in v0.8.0

func ConnectDefaultContext(ctx context.Context, endpoint string) (c *APIClient, err error)

ConnectDefaultContext is the same as ConnectDefault, but sets the ctx.

func (*APIClient) CloneWithSession added in v0.8.0

func (c *APIClient) CloneWithSession() (*APIClient, error)

CloneWithSession will create a new Client with a session instead of basic auth.

func (*APIClient) Delete

func (c *APIClient) Delete(url string) (*http.Response, error)

Delete performs a Delete request against the Redfish service

func (*APIClient) DeleteWithHeaders added in v0.10.0

func (c *APIClient) DeleteWithHeaders(url string, customHeaders map[string]string) (*http.Response, error)

DeleteWithHeaders performs a Delete request against the Redfish service but allowing custom headers

func (*APIClient) Get

func (c *APIClient) Get(url string) (*http.Response, error)

Get performs a GET request against the Redfish service.

func (*APIClient) GetService added in v0.14.0

func (c *APIClient) GetService() *Service

GetService returns the APIClient's service.

func (*APIClient) GetSession added in v0.6.0

func (c *APIClient) GetSession() (*Session, error)

GetSession retrieves the session data from an initialized APIClient. An error is returned if the client is not authenticated.

func (*APIClient) GetSettings added in v0.21.0

func (c *APIClient) GetSettings() schemas.ClientSettings

func (*APIClient) GetWithHeaders added in v0.10.0

func (c *APIClient) GetWithHeaders(url string, customHeaders map[string]string) (*http.Response, error)

GetWithHeaders performs a GET request against the Redfish service but allowing custom headers

func (*APIClient) Head added in v0.15.0

func (c *APIClient) Head(url string) (*http.Response, error)

Get performs a HEAD request against the Redfish service.

func (*APIClient) HeadWithHeaders added in v0.15.0

func (c *APIClient) HeadWithHeaders(url string, customHeaders map[string]string) (*http.Response, error)

GetWithHeaders performs a HEAD request against the Redfish service but allowing custom headers

func (*APIClient) Logout

func (c *APIClient) Logout()

Logout will delete any active session. Useful to defer logout when creating a new connection.

func (*APIClient) Patch

func (c *APIClient) Patch(url string, payload any) (*http.Response, error)

Patch performs a Patch request against the Redfish service.

func (*APIClient) PatchWithHeaders added in v0.10.0

func (c *APIClient) PatchWithHeaders(url string, payload any, customHeaders map[string]string) (*http.Response, error)

PatchWithHeaders performs a Patch request against the Redfish service but allowing custom headers

func (*APIClient) Post

func (c *APIClient) Post(url string, payload any) (*http.Response, error)

Post performs a Post request against the Redfish service.

func (*APIClient) PostMultipart added in v0.8.0

func (c *APIClient) PostMultipart(url string, payload map[string]io.Reader) (*http.Response, error)

PostMultipart performs a Post request against the Redfish service with multipart payload.

func (*APIClient) PostMultipartWithHeaders added in v0.10.0

func (c *APIClient) PostMultipartWithHeaders(url string, payload map[string]io.Reader, customHeaders map[string]string) (*http.Response, error)

PostMultipartWithHeadersperforms a Post request against the Redfish service with multipart payload but allowing custom headers

func (*APIClient) PostWithHeaders added in v0.10.0

func (c *APIClient) PostWithHeaders(url string, payload any, customHeaders map[string]string) (*http.Response, error)

PostWithHeaders performs a Post request against the Redfish service but allowing custom headers

func (*APIClient) Put

func (c *APIClient) Put(url string, payload any) (*http.Response, error)

Put performs a Put request against the Redfish service.

func (*APIClient) PutWithHeaders added in v0.10.0

func (c *APIClient) PutWithHeaders(url string, payload any, customHeaders map[string]string) (*http.Response, error)

PutWithHeaders performs a Put request against the Redfish service but allowing custom headers

func (*APIClient) RunRawRequestWithHeaders added in v0.13.0

func (c *APIClient) RunRawRequestWithHeaders(method, url string, payloadBuffer io.ReadSeeker, contentType string, customHeaders map[string]string) (*http.Response, error)

RunRawRequestWithHeaders actually performs the REST calls but allowing custom headers

func (*APIClient) SetDumpWriter added in v0.8.0

func (c *APIClient) SetDumpWriter(writer io.Writer)

SetDumpWriter sets the client the DumpWriter dynamically

func (*APIClient) WithContext added in v0.21.0

func (c *APIClient) WithContext(ctx context.Context) *APIClient

WithContext returns a copy of the client using the provided context

type ClientConfig

type ClientConfig struct {
	// Endpoint is the URL of the redfish service
	Endpoint string

	// Username is the optional user name to authenticate with.
	Username string

	// Password is the password to use for authentication.
	Password string

	// Session is an optional session ID+token obtained from a previous session
	// If this is set, it is preferred over Username and Password
	Session *Session

	// Insecure controls whether to enforce SSL certificate validity.
	Insecure bool

	// Controls TLS handshake timeout
	TLSHandshakeTimeout int

	// HTTPClient is the optional client to connect with.
	HTTPClient *http.Client

	// DumpWriter is an optional io.Writer to receive dumps of HTTP
	// requests and responses.
	DumpWriter io.Writer

	// BasicAuth tells the APIClient if basic auth should be used (true) or token based auth must be used (false)
	BasicAuth bool

	// The maximum number of concurrent HTTP requests that will be made (default: 1)
	MaxConcurrentRequests int64

	// ReuseConnections can be useful if executing a lot of requests. Setting to `true` allows
	// the TCP sessions to remain open and reused betweeen subsequent calls.
	ReuseConnections bool

	// NoModifyTransport if set indicates that the API client won't attempt to make any changes to the transport
	NoModifyTransport bool

	// AutoExpand enables $expand if supported and automatically falls back if $expand fails.
	AutoExpand bool
}

ClientConfig holds the settings for establishing a connection.

type DeepOperations added in v0.16.0

type DeepOperations struct {
	// DeepPATCH shall indicate whether this service supports the Redfish
	// Specification-defined deep 'PATCH' operation.
	//
	// Version added: v1.7.0
	DeepPATCH bool
	// DeepPOST shall indicate whether this service supports the Redfish
	// Specification-defined deep 'POST' operation.
	//
	// Version added: v1.7.0
	DeepPOST bool
	// MaxLevels shall contain the maximum levels of resources allowed in deep
	// operations.
	//
	// Version added: v1.7.0
	MaxLevels uint
}

DeepOperations shall contain information about deep operations that the service supports.

type Expand

type Expand struct {
	// ExpandAll shall indicate whether this service supports the asterisk ('*')
	// option of the '$expand' query parameter.
	//
	// Version added: v1.3.0
	ExpandAll bool
	// Levels shall indicate whether the service supports the '$levels' option of
	// the '$expand' query parameter.
	//
	// Version added: v1.3.0
	Levels bool
	// Links shall be a boolean indicating whether this service supports the use
	// of tilde (expand only entries in the Links section) as a value for the
	// $expand query parameter as described by the specification.
	Links bool
	// MaxLevels shall contain the maximum '$levels' option value in the '$expand'
	// query parameter. This property shall be present if the 'Levels' property
	// contains 'true'.
	//
	// Version added: v1.3.0
	MaxLevels uint
	// NoLinks shall indicate whether the service supports the period ('.') option
	// of the '$expand' query parameter.
	//
	// Version added: v1.3.0
	NoLinks bool
	// managerProvidingService is the URI for ManagerProvidingService.
	ManagerProvidingService string
	// sessions is the URI for Sessions.
	Sessions string
}

Expand shall contain information about the support of the '$expand' query parameter by the service.

type ProtocolFeaturesSupported

type ProtocolFeaturesSupported struct {
	// DeepOperations shall contain information about deep operations that the
	// service supports.
	//
	// Version added: v1.7.0
	DeepOperations DeepOperations
	// ExcerptQuery shall indicate whether this service supports the 'excerpt'
	// query parameter.
	//
	// Version added: v1.4.0
	ExcerptQuery bool
	// ExpandQuery shall contain information about the support of the '$expand'
	// query parameter by the service.
	//
	// Version added: v1.3.0
	ExpandQuery Expand
	// FilterQuery shall indicate whether this service supports the '$filter' query
	// parameter.
	//
	// Version added: v1.3.0
	FilterQuery bool
	// FilterQueryComparisonOperations shall indicate whether the service supports
	// the 'eq', 'ge', 'gt', 'le', 'lt', and 'ne' options for the '$filter' query
	// parameter. This property shall not be present if 'FilterQuery' contains
	// 'false'.
	//
	// Version added: v1.17.0
	FilterQueryComparisonOperations bool
	// FilterQueryCompoundOperations shall indicate whether the service supports
	// the Redfish Specification-defined grouping operators '()', 'and', 'not', and
	// 'or' options for the '$filter' query parameter. This property shall not be
	// present if 'FilterQuery' contains 'false'.
	//
	// Version added: v1.17.0
	FilterQueryCompoundOperations bool
	// IncludeOriginOfConditionQuery shall indicate whether the service supports
	// the 'includeoriginofcondition' query parameter.
	//
	// Version added: v1.18.0
	IncludeOriginOfConditionQuery bool
	// MultipleHTTPRequests shall indicate whether this service supports multiple
	// outstanding HTTP requests.
	//
	// Version added: v1.14.0
	MultipleHTTPRequests bool
	// OnlyMemberQuery shall indicate whether this service supports the 'only'
	// query parameter.
	//
	// Version added: v1.4.0
	OnlyMemberQuery bool
	// SelectQuery shall indicate whether this service supports the '$select' query
	// parameter.
	//
	// Version added: v1.3.0
	SelectQuery bool
	// TopSkipQuery shall indicate whether this service supports both the '$top'
	// and '$skip' query parameters.
	//
	// Version added: v1.17.0
	TopSkipQuery bool
}

ProtocolFeaturesSupported shall contain information about protocol features that the service supports.

type Service

type Service struct {
	schemas.Entity

	// ODataContext is the odata context.
	ODataContext string `json:"@odata.context"`
	// ODataType is the odata type.
	ODataType string `json:"@odata.type"`
	// OEM shall contain the OEM extensions. All values for properties that this
	// object contains shall conform to the Redfish Specification-described
	// requirements.
	OEM json.RawMessage `json:"Oem"`

	// Product shall include the name of the product represented by this Redfish
	// service.
	//
	// Version added: v1.3.0
	Product string
	// ProtocolFeaturesSupported shall contain information about protocol features
	// that the service supports.
	//
	// Version added: v1.3.0
	ProtocolFeaturesSupported ProtocolFeaturesSupported
	// RedfishVersion shall represent the Redfish protocol version, as specified in
	// the 'Protocol version' clause of the Redfish Specification, to which this
	// service conforms.
	RedfishVersion string

	// ServiceIdentification shall contain a vendor-provided or user-provided value
	// that identifies and associates a discovered Redfish service with a
	// particular product instance. The value of the property shall contain the
	// value of the 'ServiceIdentification' property in the 'Manager' resource
	// providing the Redfish service root resource. The value of this property is
	// used in conjunction with the 'Product' and 'Vendor' properties to match user
	// credentials or other a priori product instance information necessary for
	// initial deployment to the correct, matching Redfish service. This property
	// shall not be present if the value of the 'ServiceIdentification' property in
	// the 'Manager' resource providing the Redfish service root resource is an
	// empty string or 'null'.
	//
	// Version added: v1.14.0
	ServiceIdentification string
	// ServiceUseNotification shall contain the usage notification message for this
	// service. The value of the property shall contain the value of the
	// 'ServiceUseNotification' property in the 'Manager' resource providing the
	// Redfish service root resource. This property shall not be present if the
	// value of the 'ServiceUseNotification' property in the 'Manager' resource
	// providing the Redfish service root resource is an empty string or 'null'.
	//
	// Version added: v1.20.0
	ServiceUseNotification string

	// UUID shall contain the identifier of the Redfish service instance. If SSDP
	// is used, this value shall contain the same UUID returned in an HTTP '200 OK'
	// response from an SSDP 'M-SEARCH' request during discovery. RFC4122 describes
	// methods to use to create a UUID value. The value should be considered to be
	// opaque. Client software should only treat the overall value as a universally
	// unique identifier and should not interpret any subfields within the UUID.
	UUID string

	// Vendor shall include the name of the manufacturer or vendor represented by
	// this Redfish service. If this property is supported, the vendor name shall
	// not be included in the 'Product' property value.
	//
	// Version added: v1.5.0
	Vendor string
	// contains filtered or unexported fields
}

Service shall represent the root of the Redfish service.

func ServiceRoot

func ServiceRoot(c schemas.Client) (*Service, error)

ServiceRoot will get a Service instance from the service.

func (*Service) AccountService

func (s *Service) AccountService() (*schemas.AccountService, error)

AccountService gets the AccountService linked resource.

func (*Service) AggregationService added in v0.16.0

func (s *Service) AggregationService() (*schemas.AggregationService, error)

AggregationService gets the AggregationService linked resource.

func (*Service) AutomationNodes added in v0.21.0

func (s *Service) AutomationNodes() ([]*schemas.AutomationNode, error)

AutomationNodes gets the AutomationNodes collection.

func (*Service) Cables added in v0.16.0

func (s *Service) Cables() ([]*schemas.Cable, error)

Cables gets the Cables collection.

func (*Service) CertificateService added in v0.16.0

func (s *Service) CertificateService() (*schemas.CertificateService, error)

CertificateService gets the CertificateService linked resource.

func (*Service) Chassis

func (s *Service) Chassis() ([]*schemas.Chassis, error)

Chassis gets the Chassis collection.

func (*Service) ComponentIntegrity added in v0.16.0

func (s *Service) ComponentIntegrity() ([]*schemas.ComponentIntegrity, error)

ComponentIntegrity gets the ComponentIntegrity collection.

func (*Service) CompositionService

func (s *Service) CompositionService() (*schemas.CompositionService, error)

CompositionService gets the CompositionService linked resource.

func (*Service) CreateSession

func (s *Service) CreateSession(username, password string) (*schemas.AuthToken, error)

CreateSession creates a new session and returns the token and id

func (*Service) DeleteSession

func (s *Service) DeleteSession(url string) error

DeleteSession logout the specified session

func (*Service) EventService

func (s *Service) EventService() (*schemas.EventService, error)

EventService gets the EventService linked resource.

func (*Service) Fabrics added in v0.16.0

func (s *Service) Fabrics() ([]*schemas.Fabric, error)

Fabrics gets the Fabrics collection.

func (*Service) Facilities added in v0.16.0

func (s *Service) Facilities() ([]*schemas.Facility, error)

Facilities gets the Facilities collection.

func (*Service) JSONSchemas added in v0.21.0

func (s *Service) JSONSchemas() ([]*schemas.JSONSchemaFile, error)

JSONSchemas gets the JSONSchemas collection.

func (*Service) JobService added in v0.15.0

func (s *Service) JobService() (*schemas.JobService, error)

JobService gets the JobService linked resource.

func (*Service) KeyService added in v0.16.0

func (s *Service) KeyService() (*schemas.KeyService, error)

KeyService gets the KeyService linked resource.

func (*Service) LicenseService added in v0.16.0

func (s *Service) LicenseService() (*schemas.LicenseService, error)

LicenseService gets the LicenseService linked resource.

func (*Service) ManagerProvidingService added in v0.16.0

func (s *Service) ManagerProvidingService() (*schemas.Manager, error)

ManagerProvidingService gets the ManagerProvidingService linked resource.

func (*Service) Managers

func (s *Service) Managers() ([]*schemas.Manager, error)

Managers gets the Managers collection.

func (*Service) NVMeDomains added in v0.21.0

func (s *Service) NVMeDomains() ([]*schemas.NVMeDomain, error)

NVMeDomains gets the NVMeDomains collection.

func (*Service) PowerEquipment added in v0.15.0

func (s *Service) PowerEquipment() (*schemas.PowerEquipment, error)

PowerEquipment gets the PowerEquipment linked resource.

func (*Service) RegisteredClients added in v0.16.0

func (s *Service) RegisteredClients() ([]*schemas.RegisteredClient, error)

RegisteredClients gets the RegisteredClients collection.

func (*Service) Registries added in v0.8.0

func (s *Service) Registries() ([]*schemas.MessageRegistryFile, error)

Registries gets the Registries collection.

func (*Service) ResourceBlocks added in v0.16.0

func (s *Service) ResourceBlocks() ([]*schemas.ResourceBlock, error)

ResourceBlocks gets the ResourceBlocks collection.

func (*Service) ServiceConditions added in v0.16.0

func (s *Service) ServiceConditions() (*schemas.ServiceConditions, error)

ServiceConditions gets the ServiceConditions linked resource.

func (*Service) SessionService added in v0.16.0

func (s *Service) SessionService() (*schemas.SessionService, error)

SessionService gets the SessionService linked resource.

func (*Service) Sessions

func (s *Service) Sessions() (*schemas.Session, error)

Sessions gets the Sessions linked resource.

func (*Service) Storage added in v0.16.0

func (s *Service) Storage() ([]*schemas.Storage, error)

Storage gets the Storage collection.

func (*Service) StorageServices

func (s *Service) StorageServices() ([]*schemas.StorageService, error)

StorageServices gets the StorageServices collection.

func (*Service) StorageSystems

func (s *Service) StorageSystems() ([]*schemas.ComputerSystem, error)

StorageSystems gets the StorageSystems collection.

func (*Service) Systems

func (s *Service) Systems() ([]*schemas.ComputerSystem, error)

Systems gets the Systems collection.

func (*Service) Tasks

func (s *Service) Tasks() (*schemas.TaskService, error)

Tasks gets the Tasks linked resource.

func (*Service) TelemetryService added in v0.16.0

func (s *Service) TelemetryService() (*schemas.TelemetryService, error)

TelemetryService gets the TelemetryService linked resource.

func (*Service) ThermalEquipment added in v0.16.0

func (s *Service) ThermalEquipment() (*schemas.ThermalEquipment, error)

ThermalEquipment gets the ThermalEquipment linked resource.

func (*Service) UnmarshalJSON

func (s *Service) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a Service object from the raw JSON.

func (*Service) UpdateService added in v0.6.0

func (s *Service) UpdateService() (*schemas.UpdateService, error)

UpdateService gets the UpdateService linked resource.

type Session added in v0.6.0

type Session struct {
	ID    string
	Token string
}

Session holds the session ID and auth token needed to identify an authenticated client

Directories

Path Synopsis
oem
ami
hpe
smc
zt

Jump to

Keyboard shortcuts

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