Documentation ¶
Overview ¶
Package f5 provides a client for using the F5 API.
Index ¶
- Constants
- Variables
- func CreateToken(baseURL, user, password, loginProvName string) (string, time.Time, error)
- func IsRequestError(err error) bool
- type BackupResponse
- type Client
- func (c *Client) Backup(filename string) (*BackupResponse, error)
- func (c *Client) Begin() (*Client, error)
- func (c *Client) CheckAuth() error
- func (c *Client) CheckBackup(id string) (*BackupResponse, error)
- func (c *Client) Commit() error
- func (c *Client) DisableCertCheck()
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) DownloadImage(w io.Writer, filename string) (n int64, err error)
- func (c *Client) DownloadUCS(w io.Writer, filename string, opts ...FileTransferOption) (n int64, err error)
- func (c *Client) Exec(cmd string) (*ExecOutput, error)
- func (c *Client) ExecTMSH(cmd string) (*ExecOutput, error)
- func (c *Client) FailoverState(host, ip string) (string, error)
- func (c *Client) IsActive(host string) bool
- func (c *Client) MakeRequest(method, restPath string, data interface{}) (*http.Request, error)
- func (c *Client) ModQuery(method, restPath string, inputData interface{}) error
- func (c *Client) ReadError(resp *http.Response) error
- func (c *Client) ReadQuery(restPath string, outputData interface{}) error
- func (c *Client) RestoreBackup(filename string) (*BackupResponse, error)
- func (c *Client) RestoreBackupWithNoLicense(filename string) (*BackupResponse, error)
- func (c *Client) RevokeToken() error
- func (c *Client) Rollback() error
- func (c *Client) SendRequest(method, restPath string, data interface{}) (*http.Response, error)
- func (c *Client) SetHTTPClient(client http.Client)
- func (c *Client) SetTimeout(timeout time.Duration)
- func (c *Client) TransactionID() string
- func (c *Client) TransactionState() (*Transaction, error)
- func (c *Client) UploadFile(r io.Reader, filename string, filesize int64) (*UploadResponse, error)
- func (c *Client) UploadImage(r io.Reader, filename string, filesize int64) (*UploadResponse, error)
- func (c *Client) UploadUCS(r io.Reader, filename string, filesize int64, opts ...FileTransferOption) (*UploadResponse, error)
- func (c *Client) UseProxy(proxy string) error
- func (c *Client) UseSystemProxy() error
- type ExecOutput
- type F5Date
- type FileTransferOption
- type FileTransferOptions
- type RequestError
- type Transaction
- type UploadResponse
Constants ¶
const ( PathUploadImage = "/mgmt/cm/autodeploy/software-image-uploads" PathUploadFile = "/mgmt/shared/file-transfer/uploads" PathUploadUCS = "mgmt/shared/file-transfer/ucs-uploads" // For backward compatibility // DEPRECATED UploadRESTPath = PathUploadFile )
Paths for file upload.
const ( PathDownloadUCS = "/mgmt/shared/file-transfer/ucs-downloads" PathDownloadImage = "/mgmt/cm/autodeploy/software-image-downloads" )
Paths for file download.
const F5TimeLayout = "2006-01-02T15:04:05.999999999-0700"
F5TimeLayout defines the layout to use for decoding dates returned by the F5 iControl REST API.
const MaxChunkSize = 1048576
MaxChunkSize is the maximum chunk size allowed by the iControl REST
const (
PathBackup = "/mgmt/tm/shared/sys/backup"
)
Backup REST paths
const (
PathBashCmd = "/mgmt/tm/util/bash"
)
Bash util REST path.
const (
PathDeviceInfo = "/mgmt/tm/cm/device"
)
Cluster Management REST paths.
const PathTransaction = "/mgmt/tm/transaction"
PathTransaction is the path to transaction API endpoint.
Variables ¶
var DefaultTimeout = 5 * time.Second
DefaultTimeout defines the default timeout for HTTP clients.
var ErrNoToken = errors.New("no token")
ErrNoToken is the error returned when the Client does not have a token.
var ErrNoTransaction = errors.New("no active transaction")
ErrNoTransaction is the error returned when a function related to transaction management is called when there is no active transaction.
Functions ¶
func CreateToken ¶
CreateToken creates a new token with the given baseURL, user, password and loginProvName.
func IsRequestError ¶
IsRequestError reports whether err is a RequestError.
Types ¶
type BackupResponse ¶
type BackupResponse struct { // Unique ID to identify uniquely the backup action. ID string `json:"id"` // Name of the file in which the backup is saved to or restord from. File string `json:"file"` // Type of action performed. Possible values are: // - BACKUP // - RESTORE // - RESTORE_WITH_NO_LICENSE // - BACKUP_WITH_NO_PRIVATE_KEYS // - BACKUP_WITH_ENCRYPTION // - BACKUP_WITH_NO_PRIVATE_KEYS_WITH_ENCRYPTION // - RESTORE_WITH_ENCRYPTION // - RESTORE_WITH_NO_LICENSE_WITH_ENCRYPTION // - CLEANUP Action string `json:"action"` // Status of the backup. Possible values are: // - CREATED // - STARTED // - CANCEL_REQUESTED // - CANCELED // - FAILED // - FINISHED Status string `json:"status"` }
BackupResponse holds attributes returned by requests on the backup API.
func (BackupResponse) IsCanceled ¶
func (resp BackupResponse) IsCanceled() bool
IsCanceled reports whether the status is CANCELED.
func (BackupResponse) IsDone ¶
func (resp BackupResponse) IsDone() bool
IsDone reports whether the status indicates that the action is terminated, even if it is an error or that the task has been canceled.
func (BackupResponse) IsFailure ¶
func (resp BackupResponse) IsFailure() bool
IsFailure reports whether the status is FAILED.
func (BackupResponse) IsSuccess ¶
func (resp BackupResponse) IsSuccess() bool
IsSuccess reports whether the status is FINISHED.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client manages communication with the F5 API.
func NewBasicClient ¶
NewBasicClient creates a new F5 client with HTTP Basic Authentication.
baseURL is the base URL of the F5 API server.
func NewTokenClient ¶
NewTokenClient creates a new F5 client with token based authentication.
baseURL is the base URL of the F5 API server.
func TokenClientConnection ¶
TokenClientConnection creates a new client with the given token.
func (*Client) Backup ¶
func (c *Client) Backup(filename string) (*BackupResponse, error)
Backup creates a backup remotely saved into a file named according to the provided filename.
func (*Client) CheckAuth ¶
CheckAuth verifies that the credentials provided at the client initialization are correct.
func (*Client) CheckBackup ¶
func (c *Client) CheckBackup(id string) (*BackupResponse, error)
CheckBackup fetches the status of a backup process.
func (*Client) DisableCertCheck ¶
func (c *Client) DisableCertCheck()
DisableCertCheck disables certificate verification, meaning that insecure certificate will not cause any error.
func (*Client) Do ¶
Do sends an HTTP request and returns an HTTP response. It is just a wrapper arround http.Client Do method.
Callers should close resp.Body when done reading from it.
See http package documentation for more information:
https://golang.org/pkg/net/http/#Client.Do
func (*Client) DownloadImage ¶
DownloadImage downloads BIG-IP images from the API and writes it to w.
Download can take some time due to the size of the image files.
func (*Client) DownloadUCS ¶
func (c *Client) DownloadUCS(w io.Writer, filename string, opts ...FileTransferOption) (n int64, err error)
DownloadUCS downloads an UCS file and writes its content to w.
func (*Client) Exec ¶
func (c *Client) Exec(cmd string) (*ExecOutput, error)
Exec executes remotely a shell command on the Big-IP.
func (*Client) ExecTMSH ¶
func (c *Client) ExecTMSH(cmd string) (*ExecOutput, error)
ExecTMSH executes a TMSH command on the Big-IP.
func (*Client) FailoverState ¶
FailoverState returns the status of the BigIP (active, standby, forced-offline, ...).
func (*Client) IsActive ¶
IsActive returns true whether the BigIP is active and the iControl REST are accessible. In case of error, false is returned.
func (*Client) MakeRequest ¶
MakeRequest creates a request with headers appropriately set to make authenticated requests. This method must be called for every new request.
func (*Client) ReadQuery ¶
ReadQuery performs a GET query and unmarshal the response (from JSON) into outputData.
outputData must be a pointer.
func (*Client) RestoreBackup ¶
func (c *Client) RestoreBackup(filename string) (*BackupResponse, error)
RestoreBackup restores a backup from a file having the provided filename and located into /var/local/ucs directory.
func (*Client) RestoreBackupWithNoLicense ¶
func (c *Client) RestoreBackupWithNoLicense(filename string) (*BackupResponse, error)
RestoreBackupWithNoLicense works exactly as RestoreBackup but do no check the license.
func (*Client) RevokeToken ¶
RevokeToken revokes the current token. If the Client has not been initialized with NewTokenClient, ErrNoToken is returned.
func (*Client) Rollback ¶
Rollback aborts the current transaction. If there is no active transaction, ErrNoTransaction is returned.
func (*Client) SendRequest ¶
SendRequest is a shortcut for MakeRequest() + Do() + ReadError().
func (*Client) SetHTTPClient ¶
SetHTTPClient sets the underlying HTTP used to make requests.
func (*Client) SetTimeout ¶
SetTimeout sets the HTTP timeout for the underlying HTTP client.
func (*Client) TransactionID ¶
TransactionID returns the ID of the current transaction. If there is no active transaction, an empty string is returned.
func (*Client) TransactionState ¶
func (c *Client) TransactionState() (*Transaction, error)
TransactionState returns the state of the current transaction. If there is no active transaction, ErrNoTransaction is returned.
func (*Client) UploadFile ¶
UploadFile reads the content of a file from r and uploads it to the BigIP. The uploaded file will be named according to the provided filename.
filesize must be the exact file of the file.
The file is split into small chunk, therefore this method may send multiple request.
This method returns the latest upload response received.
func (*Client) UploadImage ¶
UploadImage reads the content of an disk image from r and uploads it to the BigIP.
The uploaded image will be named according to the provided filename.
filesize must be the exact file of the file.
The file is split into small chunk, therefore this method may send multiple request.
This method returns the latest upload response received.
func (*Client) UploadUCS ¶
func (c *Client) UploadUCS(r io.Reader, filename string, filesize int64, opts ...FileTransferOption) (*UploadResponse, error)
UploadUCS reads the content of an UCS archive from r and uploads it to the BigIP.
The uploaded UCS archive will be named according to the provided filename.
filesize must be the exact file of the file.
The file is split into small chunk, therefore this method may send multiple request.
This method returns the latest upload response received.
func (*Client) UseSystemProxy ¶
UseSystemProxy configures the client to use the system proxy
type ExecOutput ¶
type ExecOutput struct { Kind string `json:"kind"` Command string `json:"command"` CommandResult string `json:"commandResult"` UtilCmdArgs string `json:"utilCmdArgs"` }
ExecOutput represents the output returned by the API afeter having executed a bash command.
type F5Date ¶
F5Date wraps time.Time in order to override the time layout used during JSON decoding.
func (*F5Date) UnmarshalJSON ¶
UnmarshalJSON overrides time.Time JSON decoding to support F5 time parsing layout.
type FileTransferOption ¶
type FileTransferOption func(*FileTransferOptions)
FileTransferOption is a function type to set the transfer options.
func WithSFTP ¶
func WithSFTP(config *ssh.ClientConfig) FileTransferOption
WithSFTP sets the ssh configuration for file transfer.
type FileTransferOptions ¶
type FileTransferOptions struct { UseSFTP bool ClientConfig *ssh.ClientConfig }
FileTransferOptions contains SSH configuration for downloading and uploading UCS using SFTP.
type RequestError ¶
type RequestError struct { Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` ErrStack []string `json:"errorStack,omitempty"` }
A RequestError is returned as a HTTP Response by the F5 Big IP server in case of error.
func NewRequestError ¶
func NewRequestError(body io.Reader) (*RequestError, error)
NewRequestError unmarshal a RequestError from a HTTP response body.
func (RequestError) Error ¶
func (err RequestError) Error() string
Error implements the errors.Error interface
func (RequestError) String ¶
func (err RequestError) String() string
type Transaction ¶
type Transaction struct { TransID int64 `json:"transId"` ValidateOnly bool `json:"validateOnly"` ExecutionTimeout int64 `json:"executionTimeout"` SelfLink string `json:"selfLink"` State string `json:"state"` TimeoutSeconds int64 `json:"timeoutSeconds"` AsyncExecution bool `json:"asynExecution"` FailureReason string `json:"failureReason"` Kind string `json:"kind"` }
A Transaction holds the state of a remote transaction identified by its transaction ID.
type UploadResponse ¶
type UploadResponse struct { RemainingByteCount int64 `json:"remainingByteCount"` UsedChunks map[string]int `json:"usedChunks"` TotalByteCount int64 `json:"totalByteCount"` LocalFilePath string `json:"localFilePath"` TemporaryFilePath string `json:"temporaryFilePath"` Generation int64 `json:"generation"` LastUpdateMicros int64 `json:"lastUpdateMicros"` }
An UploadResponse holds the responses send by the BigIP API while uploading files.