pxe

package
v0.0.0-...-1cf9f48 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: BSD-3-Clause Imports: 15 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 (
	// ErrConfigNotFound is returned when no suitable configuration file
	// was found by AppendFile.
	ErrConfigNotFound = errors.New("configuration file was not found")

	// 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 (
	// 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 FileScheme

	// DefaultSchemes are the schemes supported by PXE by default.
	DefaultSchemes Schemes
)
View Source
var (
	// ErrNoSuchScheme is returned by Schemes.GetFile and
	// Schemes.LazyGetFile if there is no registered FileScheme
	// implementation for the given URI scheme.
	ErrNoSuchScheme = errors.New("no such scheme")
)

Functions

func GetFile

func GetFile(uri string, wd *url.URL) (io.Reader, error)

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

func LazyGetFile

func LazyGetFile(uri string, wd *url.URL) (io.Reader, error)

LazyGetFile calls LazyGetFile on DefaultSchemes. See Schemes.LazyGetFile.

func NewLazyOpener

func NewLazyOpener(open func() (io.Reader, error)) io.Reader

NewLazyOpener returns a lazy io.Reader based on `open`.

func RegisterScheme

func RegisterScheme(scheme string, fs FileScheme)

RegisterScheme calls DefaultSchemes.Register.

Types

type CachedFileScheme

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

CachedFileScheme implements FileScheme and caches files downloaded from a FileScheme.

func (*CachedFileScheme) GetFile

func (cc *CachedFileScheme) GetFile(u *url.URL) (io.Reader, error)

GetFile implements FileScheme.GetFile.

type CachingReader

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

CachingReader is a lazily caching wrapper of an io.Reader.

The wrapped io.Reader is only read from on demand, not upfront.

func NewCachingReader

func NewCachingReader(r io.Reader) *CachingReader

NewCachingReader buffers reads from r.

r is only read from when Read() is called.

func (*CachingReader) NewReader

func (cr *CachingReader) NewReader() io.Reader

NewReader returns a new io.Reader that reads cr from offset 0.

func (*CachingReader) Read

func (cr *CachingReader) Read(p []byte) (int, error)

Read reads from cr; implementing io.Reader.

TODO(chrisko): Decide whether to keep this or only keep NewReader().

func (*CachingReader) ReadAt

func (cr *CachingReader) ReadAt(p []byte, off int64) (int, error)

ReadAt reads from cr; implementing io.ReaderAt.

type Config

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

	// 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 URI, `wd` is used as the "working directory" of that relative path; the resulting URI is roughly `wd.String()/path`.

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

func ParseConfigFile

func ParseConfigFile(uri 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(uri string) error

AppendFile parses the config file downloaded from `uri` 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.

type Entry

type Entry struct {
	// Kernel is the kernel for this label.
	Kernel io.Reader

	// Initrd is the initial ramdisk for this label.
	Initrd io.Reader

	// Cmdline is the list of kernel command line parameters.
	Cmdline string
}

Entry encapsulates a Syslinux "label" config directive.

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.Reader that downloads the file.
	GetFile(u *url.URL) (io.Reader, error)
}

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

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

func NewCachedFileScheme

func NewCachedFileScheme(fs FileScheme) FileScheme

NewCachedFileScheme returns a caching wrapper for the given FileScheme `fs`.

func NewTFTPClient

func NewTFTPClient(c *tftp.Client) FileScheme

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

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.Reader, error)

GetFile implements FileScheme.GetFile.

type LazyOpener

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

LazyOpener is a lazy io.Reader.

LazyOpener will use a given open function to derive an io.Reader when Read is first called on the LazyOpener.

func (*LazyOpener) Read

func (lr *LazyOpener) Read(p []byte) (int, error)

Read implements io.Reader.Read lazily.

If called for the first time, the underlying reader will be obtained and then used for the first and subsequent calls to Read.

type LocalFileClient

type LocalFileClient struct{}

LocalFileClient implements FileScheme for files on disk.

func (LocalFileClient) GetFile

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

GetFile implements FileScheme.GetFile.

type Schemes

type Schemes map[string]FileScheme

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

func (Schemes) GetFile

func (s Schemes) GetFile(uri string, wd *url.URL) (io.Reader, error)

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

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

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

func (Schemes) LazyGetFile

func (s Schemes) LazyGetFile(uri string, wd *url.URL) (io.Reader, error)

LazyGetFile returns a reader that will download the file given by `uri` when Read is called, based on `uri`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.Reader, error)

GetFile implements FileScheme.GetFile.

Jump to

Keyboard shortcuts

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