redfish

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Redfish and Swordfish client library

fork of https://github.com/stmcginnis/gofish

Go Doc Go Report Card Releases LICENSE

Introduction

redfish is a Golang library for interacting with DMTF Redfish and SNIA Swordfish enabled devices. For the moment, the goal of this repo is to stay up to date with https://github.com/stmcginnis/gofish.

Usage

Basic usage:


package main

import (
    "fmt"

    "github.com/jacobweinstock/redfish"
)

func main() {
    config := redfish.ClientConfig{
        Endpoint: "https://localhost:5000",
        Username: "admin",
        Password: "admin",
        Insecure: true,
    }
    ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
    defer cancel()
    c, err := redfish.Connect(ctx, config)
    if err != nil {
        panic(err)
    }
    defer c.Logout(ctx)

    // Query the chassis data using the session token
    chassis, err := c.Service.Systems(ctx)
    if err != nil {
        panic(err)
    }

    for _, chass := range chassis {
        fmt.Println("Chassis:", chass.PowerState)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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
	// contains filtered or unexported fields
}

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

func Connect

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

Connect creates a new client connection to a Redfish service.

func ConnectDefault

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

ConnectDefault creates an unauthenticated connection to a Redfish service.

func (*APIClient) Delete

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

Delete performs a Delete request against the Redfish service.

func (*APIClient) Get

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

Get performs a GET request against the Redfish service.

func (*APIClient) GetSession

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) Logout

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

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

func (*APIClient) Patch

func (c *APIClient) Patch(ctx context.Context, url string, payload interface{}) (*http.Response, error)

Patch performs a Patch request against the Redfish service.

func (*APIClient) Post

func (c *APIClient) Post(ctx context.Context, url string, payload interface{}) (*http.Response, error)

Post performs a Post request against the Redfish service.

func (*APIClient) Put

func (c *APIClient) Put(ctx context.Context, url string, payload interface{}) (*http.Response, error)

Put performs a Put request against the Redfish service.

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
}

ClientConfig holds the settings for establishing a connection.

type Expand

type Expand struct {
	// ExpandAll shall be a boolean indicating whether this service supports the
	// use of asterisk (expand all entries) as a value for the $expand query
	// parameter as described by the specification.
	ExpandAll bool
	// Levels shall be a boolean indicating whether this service supports the
	// use of $levels as a value for the $expand query parameter as described by
	// the specification.
	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 be the maximum value of the $levels qualifier supported
	// by the service and shall only be included if the value of the Levels
	// property is true.
	MaxLevels int
	// NoLinks shall be a boolean indicating whether this service supports the
	// use of period (expand only entries not in the Links section) as a value
	// for the $expand query parameter as described by the specification.
	NoLinks bool
}

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

type ProtocolFeaturesSupported

type ProtocolFeaturesSupported struct {
	// ExcerptQuery shall be a boolean indicating whether this service supports
	// the use of the 'excerpt' query parameter as described by the
	// specification.
	ExcerptQuery bool
	// ExpandQuery shall contain information about the support of the $expand
	// query parameter by the service.
	ExpandQuery Expand
	// FilterQuery shall be a boolean indicating whether this service supports
	// the use of the $filter query parameter as described by the specification.
	FilterQuery bool
	// OnlyMemberQuery shall be a boolean indicating whether this service
	// supports the use of the 'only' query parameter as described by the
	// specification.
	OnlyMemberQuery bool
	// SelectQuery shall be a boolean indicating whether this service supports
	// the use of the $select query parameter as described by the specification.
	SelectQuery bool
}

ProtocolFeaturesSupported contains information about protocol features supported by the service.

type Service

type Service struct {
	common.Entity

	// ODataContext is the odata context.
	ODataContext string `json:"@odata.context"`
	// ODataID is the odata identifier.
	ODataID string `json:"@odata.id"`
	// ODataType is the odata type.
	ODataType string `json:"@odata.type"`

	// Description provides a description of this resource.
	Description string

	// Product shall include the name of the product represented by this Redfish
	// service.
	Product string
	// ProtocolFeaturesSupported contains information about protocol features
	// supported by the service.
	ProtocolFeaturesSupported ProtocolFeaturesSupported
	// RedfishVersion shall represent the version of the Redfish service. The
	// format of this string shall be of the format
	// majorversion.minorversion.errata in compliance with Protocol Version
	// section of the Redfish specification.
	RedfishVersion string

	// UUID shall be an exact match of the UUID value returned in a 200OK from
	// an SSDP M-SEARCH request during discovery. RFC4122 describes methods that
	// can be used 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 sub-fields
	// 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 value of the Product property.
	Vendor string
	// contains filtered or unexported fields
}

Service represents the root Redfish service. All values for resources described by this schema shall comply to the requirements as described in the Redfish specification.

func ServiceRoot

func ServiceRoot(ctx context.Context, c common.Client) (*Service, error)

ServiceRoot will get a Service instance from the service.

func (*Service) AccountService

func (serviceroot *Service) AccountService(ctx context.Context) (*redfish.AccountService, error)

AccountService gets the Redfish AccountService

func (*Service) Chassis

func (serviceroot *Service) Chassis(ctx context.Context) ([]*redfish.Chassis, error)

Chassis gets the chassis instances managed by this service.

func (*Service) CompositionService

func (serviceroot *Service) CompositionService(ctx context.Context) (*redfish.CompositionService, error)

CompositionService gets the composition service instance

func (*Service) CreateSession

func (serviceroot *Service) CreateSession(ctx context.Context, username string, password string) (*redfish.AuthToken, error)

CreateSession creates a new session and returns the token and id

func (*Service) DeleteSession

func (serviceroot *Service) DeleteSession(ctx context.Context, url string) error

DeleteSession logout the specified session

func (*Service) EventService

func (serviceroot *Service) EventService(ctx context.Context) (*redfish.EventService, error)

EventService gets the Redfish EventService

func (*Service) Managers

func (serviceroot *Service) Managers(ctx context.Context) ([]*redfish.Manager, error)

Managers gets the manager instances of this service.

func (*Service) Sessions

func (serviceroot *Service) Sessions(ctx context.Context) ([]*redfish.Session, error)

Sessions gets the system's active sessions

func (*Service) StorageServices

func (serviceroot *Service) StorageServices(ctx context.Context) ([]*swordfish.StorageService, error)

StorageServices gets the Swordfish storage services

func (*Service) StorageSystems

func (serviceroot *Service) StorageSystems(ctx context.Context) ([]*swordfish.StorageSystem, error)

StorageSystems gets the storage system instances managed by this service.

func (*Service) Systems

func (serviceroot *Service) Systems(ctx context.Context) ([]*redfish.ComputerSystem, error)

Systems get the system instances from the service

func (*Service) Tasks

func (serviceroot *Service) Tasks(ctx context.Context) ([]*redfish.Task, error)

Tasks gets the system's tasks

func (*Service) UnmarshalJSON

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

UnmarshalJSON unmarshals a Service object from the raw JSON.

func (*Service) UpdateService

func (serviceroot *Service) UpdateService(ctx context.Context) (*redfish.UpdateService, error)

UpdateService gets the update service instance

type Session

type Session struct {
	ID    string
	Token string
}

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

Directories

Path Synopsis
SPDX-License-Identifier: BSD-3-Clause SPDX-License-Identifier: BSD-3-Clause SPDX-License-Identifier: BSD-3-Clause
SPDX-License-Identifier: BSD-3-Clause SPDX-License-Identifier: BSD-3-Clause SPDX-License-Identifier: BSD-3-Clause

Jump to

Keyboard shortcuts

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