nmagent

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

package nmagent contains types and functions necessary for interacting with the Network Manager Agent (NMAgent).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContentError

func NewContentError(contentType string, in io.Reader, limit int64) error

NewContentError creates a ContentError from a provided reader and limit.

Types

type AzResponse

type AzResponse struct {
	HomeAz uint `json:"homeAz"`
}

type Client

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

Client is an agent for exchanging information with NMAgent.

func NewClient

func NewClient(c Config) (*Client, error)

NewClient returns an initialized Client using the provided configuration.

func (*Client) DeleteNetwork

func (c *Client) DeleteNetwork(ctx context.Context, dnr DeleteNetworkRequest) error

DeleteNetwork deletes a customer network and it's associated subnets.

func (*Client) DeleteNetworkContainer

func (c *Client) DeleteNetworkContainer(ctx context.Context, dcr DeleteContainerRequest) error

DeleteNetworkContainer removes a Network Container, its associated IP addresses, and network policies from an interface.

func (*Client) GetHomeAz

func (c *Client) GetHomeAz(ctx context.Context) (AzResponse, error)

GetHomeAz gets node's home az from nmagent

func (*Client) GetNCVersion

func (c *Client) GetNCVersion(ctx context.Context, ncvr NCVersionRequest) (NCVersion, error)

GetNetworkContainerVersion gets the current goal state version of a Network Container. This method can be used to detect changes in a Network Container's state that would indicate that it requires re-programming. The request must originate from a VM network interface that has a Swift Provisioning OwningServiceInstanceId property. The authentication token must match the token on the subnet containing the Network Container address.

func (*Client) GetNCVersionList

func (c *Client) GetNCVersionList(ctx context.Context) (NCVersionList, error)

func (*Client) GetNetworkConfiguration

func (c *Client) GetNetworkConfiguration(ctx context.Context, gncr GetNetworkConfigRequest) (VirtualNetwork, error)

GetNetworkConfiguration retrieves the configuration of a customer's virtual network. Only subnets which have been delegated will be returned.

func (*Client) JoinNetwork

func (c *Client) JoinNetwork(ctx context.Context, jnr JoinNetworkRequest) error

JoinNetwork joins a node to a customer's virtual network.

func (*Client) PutNetworkContainer

func (c *Client) PutNetworkContainer(ctx context.Context, pncr *PutNetworkContainerRequest) error

PutNetworkContainer applies a Network Container goal state and publishes it to PubSub.

func (*Client) SupportedAPIs

func (c *Client) SupportedAPIs(ctx context.Context) ([]string, error)

SupportedAPIs retrieves the capabilities of the nmagent running on the node. This is useful for detecting if GRE Keys are supported.

type Config

type Config struct {
	/////////////////////
	// Required Config //
	/////////////////////
	Host string // the host the client will connect to
	Port uint16 // the port the client will connect to

	/////////////////////
	// Optional Config //
	/////////////////////
	UseTLS bool // forces all connections to use TLS
}

Config is a configuration for an NMAgent Client.

func NewConfig

func NewConfig(wireserverIP string) (Config, error)

NewConfig returns a nmagent client config using the provided wireserverIP string

func (Config) Validate

func (c Config) Validate() error

Validate reports whether this configuration is a valid configuration for a client.

type ContentError

type ContentError struct {
	Type string // the mime type of the content received
	Body []byte // the received body
}

ContentError is encountered when an unexpected content type is obtained from NMAgent.

func (ContentError) Error

func (c ContentError) Error() string

type DeleteContainerRequest

type DeleteContainerRequest struct {
	NCID       string `json:"-"`          // the Network Container ID
	AzID       uint   `json:"azID"`       // home AZ of the Network Container
	AZREnabled bool   `json:"azrEnabled"` // whether AZR is enabled or not

	// PrimaryAddress is the primary customer address of the interface in the
	// management VNET
	PrimaryAddress      string `json:"-"`
	AuthenticationToken string `json:"-"`
}

DeleteContainerRequest represents all information necessary to request that NMAgent delete a particular network container

func (DeleteContainerRequest) Body

func (d DeleteContainerRequest) Body() (io.Reader, error)

Body returns nothing, because DeleteContainerRequests have no HTTP body

func (DeleteContainerRequest) Method

func (d DeleteContainerRequest) Method() string

Method returns the HTTP method required to submit a DeleteContainerRequest

func (DeleteContainerRequest) Path

func (d DeleteContainerRequest) Path() string

Path returns the path for submitting a DeleteContainerRequest with parameters interpolated correctly

func (DeleteContainerRequest) Validate

func (d DeleteContainerRequest) Validate() error

Validate ensures that the DeleteContainerRequest has the correct information to submit the request

type DeleteNetworkRequest

type DeleteNetworkRequest struct {
	NetworkID string `json:"-"` // the customer's VNet ID
}

DeleteNetworkRequest represents all information necessary to request that NMAgent delete a particular network

func (DeleteNetworkRequest) Body

func (d DeleteNetworkRequest) Body() (io.Reader, error)

Body returns nothing, because DeleteNetworkRequest has no request body

func (DeleteNetworkRequest) Method

func (d DeleteNetworkRequest) Method() string

Method returns the HTTP request method to submit a DeleteNetworkRequest

func (DeleteNetworkRequest) Path

func (d DeleteNetworkRequest) Path() string

Path constructs a URL path for invoking a DeleteNetworkRequest using the provided parameters

func (DeleteNetworkRequest) Validate

func (d DeleteNetworkRequest) Validate() error

Validate ensures that the provided parameters of the request are valid

type Error

type Error struct {
	Code   int    // the HTTP status code received
	Source string // the component responsible for producing the error
	Body   []byte // the body of the error returned
}

Error is a aberrent condition encountered when interacting with the NMAgent API.

func (Error) Error

func (e Error) Error() string

Error constructs a string representation of this error in accordance with the error interface.

func (Error) Message

func (e Error) Message() string

Message interprets the HTTP Status code from NMAgent and returns the corresponding explanation from the documentation.

func (Error) StatusCode

func (e Error) StatusCode() int

StatusCode returns the HTTP status associated with this error.

func (Error) Temporary

func (e Error) Temporary() bool

Temporary reports whether the error encountered from NMAgent should be considered temporary, and thus retriable.

func (Error) Unauthorized

func (e Error) Unauthorized() bool

Unauthorized reports whether the error was produced as a result of submitting the request from an interface without an OwningServiceInstanceId property. In some cases, this can be a transient condition that could be retried.

type GetHomeAzRequest

type GetHomeAzRequest struct{}

func (*GetHomeAzRequest) Body

func (g *GetHomeAzRequest) Body() (io.Reader, error)

Body is a no-op method to satisfy the Request interface while indicating that there is no body for a GetHomeAz Request.

func (*GetHomeAzRequest) Method

func (g *GetHomeAzRequest) Method() string

Method indicates that GetHomeAz requests are GET requests.

func (*GetHomeAzRequest) Path

func (g *GetHomeAzRequest) Path() string

Path returns the necessary URI path for invoking a GetHomeAz request.

func (*GetHomeAzRequest) Validate

func (g *GetHomeAzRequest) Validate() error

Validate is a no-op method because GetHomeAzRequest have no parameters, and therefore can never be invalid.

type GetNetworkConfigRequest

type GetNetworkConfigRequest struct {
	VNetID string `json:"-"` // the customer's virtual network ID
}

GetNetworkConfigRequest is a collection of necessary information for submitting a request for a customer's network configuration

func (GetNetworkConfigRequest) Body

func (g GetNetworkConfigRequest) Body() (io.Reader, error)

Body returns nothing because GetNetworkConfigRequest has no HTTP request body

func (GetNetworkConfigRequest) Method

func (g GetNetworkConfigRequest) Method() string

Method returns the HTTP method required to submit a GetNetworkConfigRequest

func (GetNetworkConfigRequest) Path

Path produces a URL path used to submit a request

func (GetNetworkConfigRequest) Validate

func (g GetNetworkConfigRequest) Validate() error

Validate ensures that the request is complete and the parameters are correct

type JoinNetworkRequest

type JoinNetworkRequest struct {
	NetworkID string `json:"-"` // the customer's VNet ID
}

func (JoinNetworkRequest) Body

func (j JoinNetworkRequest) Body() (io.Reader, error)

Body returns nothing, because JoinNetworkRequest has no request body

func (JoinNetworkRequest) Method

func (j JoinNetworkRequest) Method() string

Method returns the HTTP request method to submit a JoinNetworkRequest

func (JoinNetworkRequest) Path

func (j JoinNetworkRequest) Path() string

Path constructs a URL path for invoking a JoinNetworkRequest using the provided parameters

func (JoinNetworkRequest) Validate

func (j JoinNetworkRequest) Validate() error

Validate ensures that the provided parameters of the request are valid

type NCVersion

type NCVersion struct {
	NetworkContainerID string `json:"networkContainerId"`
	Version            string `json:"version"` // the current network container version
}

NCVersion is a response produced from requests for a network container's version.

type NCVersionList

type NCVersionList struct {
	Containers []NCVersion `json:"networkContainers"`
}

NetworkContainerListResponse is a collection of network container IDs mapped to their current versions.

type NCVersionListRequest

type NCVersionListRequest struct{}

NCVersionListRequest is a collection of parameters necessary to submit a request to receive a list of NCVersions available from the NMAgent instance.

func (NCVersionListRequest) Body

func (NCVersionListRequest) Body() (io.Reader, error)

func (NCVersionListRequest) Method

func (NCVersionListRequest) Method() string

Method returns the HTTP method required for the request.

func (NCVersionListRequest) Path

Path returns the path required to issue the request.

func (NCVersionListRequest) Validate

func (NCVersionListRequest) Validate() error

Validate performs any necessary validations for the request.

type NCVersionRequest

type NCVersionRequest struct {
	AuthToken          string `json:"-"`
	NetworkContainerID string `json:"-"`
	PrimaryAddress     string `json:"-"`
}

func (NCVersionRequest) Body

func (n NCVersionRequest) Body() (io.Reader, error)

func (NCVersionRequest) Method

func (n NCVersionRequest) Method() string

Method indicates this request is a GET request

func (NCVersionRequest) Path

func (n NCVersionRequest) Path() string

Path returns the URL Path for the request with parameters interpolated as necessary.

func (NCVersionRequest) Validate

func (n NCVersionRequest) Validate() error

Validate ensures the presence of all parameters of the NCVersionRequest, as none are optional.

type Policy

type Policy struct {
	ID   string
	Type string
}

func (Policy) MarshalJSON

func (p Policy) MarshalJSON() ([]byte, error)

MarshalJson encodes policies as a JSON string, separated by a comma. This specific format is requested by the NMAgent documentation

func (*Policy) UnmarshalJSON

func (p *Policy) UnmarshalJSON(in []byte) error

UnmarshalJSON decodes a JSON-encoded policy string

type PutNetworkContainerRequest

type PutNetworkContainerRequest struct {
	// NOTE(traymond): if you are adding a new field to this struct, ensure that it is also added
	// to the MarshallJSON, UnmarshallJSON and  method as well.
	ID     string // the id of the network container
	VNetID string // the id of the customer's vnet

	// Version is the new network container version
	Version uint64

	// SubnetName is the name of the delegated subnet. This is used to
	// authenticate the request. The list of ipv4addresses must be contained in
	// the subnet's prefix.
	SubnetName string

	// IPv4 addresses in the customer virtual network that will be assigned to
	// the interface.
	IPv4Addrs []string

	Policies []Policy // policies applied to the network container

	// VlanID is used to distinguish Network Containers with duplicate customer
	// addresses. "0" is considered a default value by the API.
	VlanID int

	GREKey uint16

	// AuthenticationToken is the base64 security token for the subnet containing
	// the Network Container addresses
	AuthenticationToken string

	// PrimaryAddress is the primary customer address of the interface in the
	// management VNet
	PrimaryAddress string

	// AzID is the home AZ ID of the network container
	AzID uint

	// AZREnabled denotes whether AZR is enabled for network container or not
	AZREnabled bool
}

PutNetworkContainerRequest is a collection of parameters necessary to create a new network container

func (*PutNetworkContainerRequest) Body

Body marshals the JSON fields of the request and produces an Reader intended for use with an HTTP request

func (*PutNetworkContainerRequest) MarshalJSON

func (p *PutNetworkContainerRequest) MarshalJSON() ([]byte, error)

func (*PutNetworkContainerRequest) Method

func (p *PutNetworkContainerRequest) Method() string

Method returns the HTTP method for this request type

func (*PutNetworkContainerRequest) Path

Path returns the URL path necessary to submit this PutNetworkContainerRequest

func (*PutNetworkContainerRequest) UnmarshalJSON

func (p *PutNetworkContainerRequest) UnmarshalJSON(in []byte) error

func (*PutNetworkContainerRequest) Validate

func (p *PutNetworkContainerRequest) Validate() error

Validate ensures that all of the required parameters of the request have been filled out properly prior to submission to NMAgent

type Request

type Request interface {
	// Validate should ensure that the request is valid to submit
	Validate() error

	// Path should produce a URL path, complete with any URL parameters
	// interpolated
	Path() string

	// Body produces the HTTP request body necessary to submit the request
	Body() (io.Reader, error)

	// Method returns the HTTP Method to be used for the request.
	Method() string
}

Request represents an abstracted HTTP request, capable of validating itself, producing a valid Path, Body, and its Method.

type Subnet

type Subnet struct {
	AddressPrefix string `json:"addressPrefix"`
	SubnetName    string `json:"subnetName"`
	Tags          []Tag  `json:"tags"`
}

type SupportedAPIsRequest

type SupportedAPIsRequest struct{}

SupportedAPIsRequest is a collection of parameters necessary to submit a valid request to retrieve the supported APIs from an NMAgent instance.

func (*SupportedAPIsRequest) Body

func (s *SupportedAPIsRequest) Body() (io.Reader, error)

Body is a no-op method to satisfy the Request interface while indicating that there is no body for a SupportedAPIs Request.

func (*SupportedAPIsRequest) Method

func (s *SupportedAPIsRequest) Method() string

Method indicates that SupportedAPIs requests are GET requests.

func (*SupportedAPIsRequest) Path

func (s *SupportedAPIsRequest) Path() string

Path returns the necessary URI path for invoking a supported APIs request.

func (*SupportedAPIsRequest) Validate

func (s *SupportedAPIsRequest) Validate() error

Validate is a no-op method because SupportedAPIsRequests have no parameters, and therefore can never be invalid.

type SupportedAPIsResponseXML

type SupportedAPIsResponseXML struct {
	SupportedApis []string `xml:"type"`
}

type Tag

type Tag struct {
	Name string `json:"name"`
	Type string `json:"type"` // the type of the tag (e.g. "System" or "Custom")
}

type VirtualNetwork

type VirtualNetwork struct {
	CNetSpace      string   `json:"cnetSpace"`
	DefaultGateway string   `json:"defaultGateway"`
	DNSServers     []string `json:"dnsServers"`
	Subnets        []Subnet `json:"subnets"`
	VNetSpace      string   `json:"vnetSpace"`
	VNetVersion    string   `json:"vnetVersion"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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