pxe

package
Version: v0.0.0-...-c97c800 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package pxe aims to implement the PXE specification.

See http://www.pix.net/software/pxeboot/archive/pxespec.pdf

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultHTTPClient is the default HTTP FileScheme.
	//
	// It is not recommended to use this for HTTPS. We recommend creating an
	// http.Client that accepts only a private pool of certificates.
	DefaultHTTPClient = NewHTTPClient(http.DefaultClient)

	// DefaultTFTPClient is the default TFTP FileScheme.
	DefaultTFTPClient = NewTFTPClient()

	// DefaultSchemes are the schemes supported by PXE by default.
	DefaultSchemes = Schemes{
		"tftp": DefaultTFTPClient,
		"http": DefaultHTTPClient,
		"file": &LocalFileClient{},
	}
)
View Source
var (
	// ErrDefaultEntryNotFound is returned when the configuration file
	// names a default label that is not part of the configuration.
	ErrDefaultEntryNotFound = errors.New("default label not found in configuration")
)
View Source
var (
	// ErrNoSuchScheme is returned by Schemes.GetFile and
	// Schemes.LazyGetFile if there is no registered FileScheme
	// implementation for the given URL scheme.
	ErrNoSuchScheme = errors.New("no such scheme")
)

Functions

func GetFile

func GetFile(u *url.URL) (io.ReaderAt, error)

GetFile downloads a file via DefaultSchemes. See Schemes.GetFile for details.

func IsURLError

func IsURLError(err error) bool

IsURLError returns true iff err is a URLError.

func LazyGetFile

func LazyGetFile(u *url.URL) (io.ReaderAt, error)

LazyGetFile calls LazyGetFile on DefaultSchemes. See Schemes.LazyGetFile.

func RegisterScheme

func RegisterScheme(scheme string, fs FileScheme)

RegisterScheme calls DefaultSchemes.Register.

Types

type Config

type Config struct {
	// Entries is a map of label name -> label configuration.
	Entries map[string]*boot.LinuxImage

	// DefaultEntry is the default label key to use.
	//
	// If DefaultEntry is non-empty, the label is guaranteed to exist in
	// `Entries`.
	DefaultEntry string
	// contains filtered or unexported fields
}

Config encapsulates a parsed Syslinux configuration file.

See http://www.syslinux.org/wiki/index.php?title=Config for the configuration file specification.

TODO: Tear apart parser internals from Config.

func NewConfig

func NewConfig(wd *url.URL) *Config

NewConfig returns a new PXE parser using working directory `wd` and default schemes.

See NewConfigWithSchemes for more details.

func NewConfigWithSchemes

func NewConfigWithSchemes(wd *url.URL, s Schemes) *Config

NewConfigWithSchemes returns a new PXE parser using working directory `wd` and schemes `s`.

If a path encountered in a configuration file is relative instead of a full URL, `wd` is used as the "working directory" of that relative path; the resulting URL is roughly `wd.String()/path`.

`s` is used to get files referred to by URLs.

func ParseConfigFile

func ParseConfigFile(url string, wd *url.URL) (*Config, error)

ParseConfigFile parses a PXE/Syslinux configuration as specified in http://www.syslinux.org/wiki/index.php?title=Config

Currently, only the APPEND, INCLUDE, KERNEL, LABEL, DEFAULT, and INITRD directives are partially supported.

`wd` is the default scheme, host, and path for any files named as a relative path. The default path for config files is assumed to be `wd.Path`/pxelinux.cfg/.

func (*Config) Append

func (c *Config) Append(config string) error

Append parses `config` and adds the respective configuration to `c`.

func (*Config) AppendFile

func (c *Config) AppendFile(url string) error

AppendFile parses the config file downloaded from `url` and adds it to `c`.

func (*Config) FindConfigFile

func (c *Config) FindConfigFile(mac net.HardwareAddr, ip net.IP) error

FindConfigFile probes for config files based on the Mac and IP given.

func (*Config) GetFile

func (c *Config) GetFile(url string) (io.ReaderAt, error)

GetFile parses `url` relative to the config's working directory and returns an io.Reader for the requested url.

If url is just a relative path and not a full URL, c.wd is used as the "working directory" of that relative path; the resulting URL is roughly path.Join(wd.String(), url).

type FileScheme

type FileScheme interface {
	// GetFile returns a reader that gives the contents of `u`.
	//
	// It may do so by downloading `u` and placing it in a buffer, or by
	// returning an io.ReaderAt that downloads the file.
	GetFile(u *url.URL) (io.ReaderAt, error)
}

FileScheme represents the implementation of a URL scheme and gives access to downloading files of that scheme.

For example, an http FileScheme implementation would download files using the HTTP protocol.

func NewTFTPClient

func NewTFTPClient(opts ...tftp.ClientOpt) FileScheme

NewTFTPClient returns a new TFTP client based on the given tftp.ClientOpt.

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient implements FileScheme for HTTP files.

func NewHTTPClient

func NewHTTPClient(c *http.Client) *HTTPClient

NewHTTPClient returns a new HTTP FileScheme based on the given http.Client.

func (HTTPClient) GetFile

func (h HTTPClient) GetFile(u *url.URL) (io.ReaderAt, error)

GetFile implements FileScheme.GetFile.

type LocalFileClient

type LocalFileClient struct{}

LocalFileClient implements FileScheme for files on disk.

func (LocalFileClient) GetFile

func (lfs LocalFileClient) GetFile(u *url.URL) (io.ReaderAt, error)

GetFile implements FileScheme.GetFile.

type Schemes

type Schemes map[string]FileScheme

Schemes is a map of URL scheme identifier -> implementation that can download a file for that scheme.

func (Schemes) GetFile

func (s Schemes) GetFile(u *url.URL) (io.ReaderAt, error)

GetFile downloads the file with the given `u`. `u.Scheme` is used to select the FileScheme via `s`.

If `s` does not contain a FileScheme for `u.Scheme`, ErrNoSuchScheme is returned.

func (Schemes) LazyGetFile

func (s Schemes) LazyGetFile(u *url.URL) (io.ReaderAt, error)

LazyGetFile returns a reader that will download the file given by `u` when Read is called, based on `u`s scheme. See Schemes.GetFile for more details.

func (Schemes) Register

func (s Schemes) Register(scheme string, fs FileScheme)

Register registers a scheme identified by `scheme` to be `fs`.

type TFTPClient

type TFTPClient struct {
	// contains filtered or unexported fields
}

TFTPClient implements FileScheme for TFTP files.

func (*TFTPClient) GetFile

func (t *TFTPClient) GetFile(u *url.URL) (io.ReaderAt, error)

GetFile implements FileScheme.GetFile.

type URLError

type URLError struct {
	URL *url.URL
	Err error
}

URLError is an error involving URLs.

func (*URLError) Error

func (s *URLError) Error() string

Error implements error.Error.

Source Files

Jump to

Keyboard shortcuts

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