utils

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRequest

func CheckRequest[Structure RequestStructure](httpRequest *http.Request, expectedRequestMethod string, structure *Structure) (libvirt.Error, bool)

Check the expected HTTP request method and convert the JSON request body to structure if not HTTP GET method. HTTP GET method must be use query parameter.

Notes for HTTP GET method:

- Query parameter and structure field will be compared in case sensitive.

- Every structure field data type must be string, so You must convert it to the right data type before You use it.

- Untested for array query argument (Please use this function with caution.).

func HttpErrorCode

func HttpErrorCode(libvirtErrorNumber libvirt.ErrorNumber) int

Convert the Libvirt Error Number to HTTP Status Code

func JsonResponseBuilder

func JsonResponseBuilder[Response ResponseStructure](response Response, httpResponseWriter http.ResponseWriter, httpStatusCode int)

Create JSON response with HTTP header [Content-Type: application/json].

func NewConnect

func NewConnect(uri string) (*libvirt.Connect, libvirt.Error, bool)

This function should be called first to get a connection to the Hypervisor and xen store.

If name is NULL, if the LIBVIRT_DEFAULT_URI environment variable is set, then it will be used. Otherwise if the client configuration file has the "uri_default" parameter set, then it will be used. Finally probing will be done to determine a suitable default driver to activate. This involves trying each hypervisor in turn until one successfully opens.

If connecting to an unprivileged hypervisor driver which requires the libvirtd daemon to be active, it will automatically be launched if not already running. This can be prevented by setting the environment variable LIBVIRT_AUTOSTART=0

URIs are documented at https://libvirt.org/uri.html

Close() should be used to release the resources after the connection is no longer needed.

func NewConnectReadOnly

func NewConnectReadOnly(uri string) (*libvirt.Connect, libvirt.Error, bool)

This function should be called first to get a restricted connection to the library functionalities. The set of APIs usable are then restricted on the available methods to control the domains.

See https://pkg.go.dev/github.com/Hari-Kiri/virest-storage-pool/modules/utils#NewConnect or https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at https://libvirt.org/uri.html

func NewConnectWithAuth

func NewConnectWithAuth(uri string, auth *libvirt.ConnectAuth, flags libvirt.ConnectFlags) (*libvirt.Connect, libvirt.Error, bool)

This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback

See https://pkg.go.dev/github.com/Hari-Kiri/virest-storage-pool/modules/utils#NewConnect or https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at https://libvirt.org/uri.html

func NewConnectWithAuthDefault

func NewConnectWithAuthDefault(uri string, flags libvirt.ConnectFlags) (*libvirt.Connect, libvirt.Error, bool)

This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback

See https://pkg.go.dev/github.com/Hari-Kiri/virest-storage-pool/modules/utils#NewConnect or https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at https://libvirt.org/uri.html

func NoContentResponseBuilder

func NoContentResponseBuilder(httpResponseWriter http.ResponseWriter)

Create http response with no content (HTTP code 204).

Types

type RequestStructure

type RequestStructure interface {
	poolList.Request |
		poolDefine.Request |
		poolBuild.Request |
		poolUndefine.Request
}

Defined generic type constraint for request model structure.

type ResponseStructure

type ResponseStructure interface {
	poolList.Response |
		poolDefine.Response |
		poolBuild.Response |
		poolUndefine.Response
}

Defined generic type constraint for response model structure.

Jump to

Keyboard shortcuts

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