tbclient

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Package tbclient provides client functions to interact with CB-Tumblebug API

Index

Constants

View Source
const (
	// VeryShortDuration is a duration for very short-term cache
	VeryShortDuration = 1 * time.Second
	// ShortDuration is a duration for short-term cache
	ShortDuration = 2 * time.Second
	// MediumDuration is a duration for medium-term cache
	MediumDuration = 5 * time.Second
	// LongDuration is a duration for long-term cache
	LongDuration = 10 * time.Second
)
View Source
const (
	// MaxDebugBodyLength is the maximum length of response body for debug logs
	MaxDebugBodyLength = 50000
)

Variables

This section is empty.

Functions

func GetCacheDuration added in v0.5.1

func GetCacheDuration(ctx context.Context) (time.Duration, bool)

GetCacheDuration retrieves cache duration from the context

func Init added in v0.5.1

func Init(cfg ApiConfig)

Init initializes the global Tumblebug client.

func SetCacheDuration added in v0.5.1

func SetCacheDuration(ctx context.Context, d time.Duration) context.Context

SetCacheDuration adds cache duration to the context

Types

type ApiConfig

type ApiConfig struct {
	RestUrl       string
	Username      string
	Password      string
	Timeout       time.Duration
	CacheDuration time.Duration
	HttpTransport http.RoundTripper
}

ApiConfig holds the configuration for the Tumblebug client.

type CacheItem added in v0.5.1

type CacheItem struct {
	ResponseBytes []byte
	StatusCode    int
	Header        http.Header
	ExpiresAt     time.Time
}

CacheItem is a struct to store cached item

type CircuitBreakerState added in v0.5.1

type CircuitBreakerState struct {
	FailureCount int
	LastFailure  time.Time
	IsOpen       bool
}

CircuitBreakerState represents the state of a circuit breaker for a specific request

type NLBListResponse added in v0.5.3

type NLBListResponse struct {
	NLB []tbmodel.NLBInfo `json:"nlb"`
}

NLBListResponse is the response body for GET /ns/{nsId}/infra/{infraId}/nlb.

type Session added in v0.5.1

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

Session represents a single request scope. It holds the request-specific configuration (headers, context, etc.).

func NewSession added in v0.5.1

func NewSession() *Session

NewSession creates a new Session using the global client.

func (*Session) CreateInfra added in v0.5.1

func (s *Session) CreateInfra(nsId string, reqBody tbmodel.InfraReq) (tbmodel.InfraInfo, error)

CreateInfra creates a new Infra (Infrastructure) in the specified namespace

func (*Session) CreateInfraDynamic added in v0.5.1

func (s *Session) CreateInfraDynamic(nsId string, reqBody tbmodel.InfraDynamicReq) (tbmodel.InfraInfo, error)

CreateInfraDynamic creates a new Infra (Infrastructure) with defaults in the specified namespace

func (*Session) CreateNamespace added in v0.5.1

func (s *Session) CreateNamespace(nsReq tbmodel.NsReq) (tbmodel.NsInfo, error)

CreateNamespace creates a new namespace in Tumblebug

func (*Session) CreateNlb added in v0.5.3

func (s *Session) CreateNlb(nsId, infraId string, req tbmodel.NLBReq) (tbmodel.NLBInfo, error)

CreateNlb creates a new NLB in the specified namespace and infra.

func (*Session) CreateObjectStorage added in v0.5.1

func (s *Session) CreateObjectStorage(nsId string, req tbmodel.ObjectStorageCreateRequest) (tbmodel.ObjectStorageInfo, error)

CreateObjectStorage creates a new object storage (bucket)

func (*Session) CreateSecurityGroup added in v0.5.1

func (s *Session) CreateSecurityGroup(nsId string, reqBody tbmodel.SecurityGroupReq, option string) (tbmodel.SecurityGroupInfo, error)

CreateSecurityGroup creates a new Security Group in the specified namespace

func (*Session) CreateSshKey added in v0.5.1

func (s *Session) CreateSshKey(nsId string, reqBody tbmodel.SshKeyReq) (tbmodel.SshKeyInfo, error)

CreateSshKey creates a new SSH Key in the specified namespace

func (*Session) CreateVNet added in v0.5.1

func (s *Session) CreateVNet(nsId string, reqBody tbmodel.VNetReq) (tbmodel.VNetInfo, error)

CreateVNet creates a new Virtual Network (VNet) in the specified namespace

func (*Session) Delete added in v0.5.1

func (s *Session) Delete(url string) (*resty.Response, error)

Delete executes a DELETE request.

func (*Session) DeleteInfra added in v0.5.1

func (s *Session) DeleteInfra(nsId, infraId, option string) (tbmodel.IdList, error)

DeleteInfra deletes a specific Infra (Infrastructure) in the specified namespace

func (*Session) DeleteNlb added in v0.5.3

func (s *Session) DeleteNlb(nsId, infraId, nlbId string) error

DeleteNlb deletes a specific NLB.

func (*Session) DeleteObjectStorage added in v0.5.1

func (s *Session) DeleteObjectStorage(nsId string, osId string, option string) error

DeleteObjectStorage deletes an object storage (bucket). option controls the deletion behavior (mutually exclusive):

  • "" : Standard delete — fails if the bucket is not empty.
  • "empty" : Empty the bucket first, then delete.
  • "force" : Force-delete with all contents (passed to Spider as force=true).
  • "reconcile": Remove only Tumblebug metadata without calling the CSP delete API.

func (*Session) DeleteObjectStorageCORS added in v0.5.1

func (s *Session) DeleteObjectStorageCORS(nsId string, osId string) error

DeleteObjectStorageCORS deletes the CORS configuration of an object storage (bucket)

func (*Session) DeleteSecurityGroup added in v0.5.1

func (s *Session) DeleteSecurityGroup(nsId, securityGroupId string) (tbmodel.SimpleMsg, error)

DeleteSecurityGroup deletes a specific Security Group in the specified namespace

func (*Session) DeleteSharedResources added in v0.5.1

func (s *Session) DeleteSharedResources(nsId string) (tbmodel.IdList, error)

func (*Session) DeleteSshKey added in v0.5.1

func (s *Session) DeleteSshKey(nsId, sshKeyId string) (tbmodel.SimpleMsg, error)

func (*Session) DeleteStorageObject added in v0.5.1

func (s *Session) DeleteStorageObject(nsId, osId, objectKey string) error

DeleteStorageObject deletes a specific object from an object storage bucket.

func (*Session) DeleteVNet added in v0.5.1

func (s *Session) DeleteVNet(nsId, vNetId, action string) (tbmodel.SimpleMsg, error)

func (*Session) Execute added in v0.5.1

func (s *Session) Execute(method, url string) (*resty.Response, error)

Execute executes the request with the given method and URL.

func (*Session) ExistObjectStorage added in v0.5.1

func (s *Session) ExistObjectStorage(nsId string, osId string) (bool, error)

ExistObjectStorage checks the existence of an object storage (bucket)

func (*Session) Get added in v0.5.1

func (s *Session) Get(url string) (*resty.Response, error)

Get executes a GET request.

func (*Session) GetConnConfig added in v0.5.1

func (s *Session) GetConnConfig(connectionConfigName string) (tbmodel.ConnConfig, error)

func (*Session) GetNlb added in v0.5.3

func (s *Session) GetNlb(nsId, infraId, nlbId string) (tbmodel.NLBInfo, error)

GetNlb retrieves a specific NLB.

func (*Session) GetObjectStorage added in v0.5.1

func (s *Session) GetObjectStorage(nsId string, osId string) (tbmodel.ObjectStorageInfo, error)

GetObjectStorage retrieves details of an object storage (bucket)

func (*Session) GetObjectStorageCORS added in v0.5.1

func (s *Session) GetObjectStorageCORS(nsId string, osId string) (tbmodel.ObjectStorageGetCorsResponse, error)

GetObjectStorageCORS retrieves the CORS configuration of an object storage (bucket)

func (*Session) GetObjectStorageLocation added in v0.5.1

func (s *Session) GetObjectStorageLocation(nsId string, osId string) (tbmodel.ObjectStorageLocationResponse, error)

GetObjectStorageLocation retrieves the location of an object storage (bucket)

func (*Session) GetObjectStorageSupport added in v0.5.1

func (s *Session) GetObjectStorageSupport(cspType string) (tbmodel.ObjectStorageSupportResponse, error)

GetObjectStorageSupport retrieves CSP support information for object storage features If cspType is empty, returns support information for all CSPs

func (*Session) GetObjectStorageVersioning added in v0.5.1

func (s *Session) GetObjectStorageVersioning(nsId string, osId string) (tbmodel.ObjectStorageGetVersioningResponse, error)

GetObjectStorageVersioning retrieves the versioning configuration of an object storage (bucket)

func (*Session) GetStorageObject added in v0.5.1

func (s *Session) GetStorageObject(nsId, osId, objectKey string) (tbmodel.Object, error)

GetStorageObject retrieves metadata of a specific object in an object storage bucket.

func (*Session) Head added in v0.5.1

func (s *Session) Head(url string) (*resty.Response, error)

Head executes a HEAD request.

func (*Session) InfraRecommendSpec added in v0.5.1

func (s *Session) InfraRecommendSpec(planToSearchProperVm string) ([]tbmodel.SpecInfo, error)

InfraRecommendSpec finds appropriate VM specs by filtering and prioritzing.

func (*Session) IsReady added in v0.5.1

func (s *Session) IsReady() (bool, *string, error)

IsReady checks if Tumblebug is ready

func (*Session) ListNlbs added in v0.5.3

func (s *Session) ListNlbs(nsId, infraId string) (NLBListResponse, error)

ListNlbs retrieves all NLBs in the specified namespace and infra.

func (*Session) ListObjectStorageObjects added in v0.5.1

func (s *Session) ListObjectStorageObjects(nsId string, osId string) (tbmodel.ObjectStorageListObjectsResponse, error)

ListObjectStorageObjects lists objects in a specific object storage bucket.

func (*Session) ListObjectStorages added in v0.5.1

func (s *Session) ListObjectStorages(nsId string, option string, filterKey string, filterVal string) (tbmodel.ObjectStorageListResponse, error)

ListObjectStorages retrieves the list of all object storages (buckets) in a namespace

func (*Session) NoCache added in v0.5.1

func (s *Session) NoCache() *Session

NoCache disables caching for the request.

func (*Session) Post added in v0.5.1

func (s *Session) Post(url string) (*resty.Response, error)

Post executes a POST request.

func (*Session) Put added in v0.5.1

func (s *Session) Put(url string) (*resty.Response, error)

Put executes a PUT request.

func (*Session) ReadAllInfra added in v0.5.1

func (s *Session) ReadAllInfra(nsId string) (TbInfraInfoList, error)

ReadAllInfra retrieves all Infras (Infrastructure) in the specified namespace

func (*Session) ReadInfra added in v0.5.1

func (s *Session) ReadInfra(nsId, infraId string) (tbmodel.InfraInfo, error)

ReadInfra retrieves information about a specific Infra (Infrastructure) in the specified namespace

func (*Session) ReadInfraAccessInfo added in v0.5.1

func (s *Session) ReadInfraAccessInfo(nsId, infraId, option, accessInfoOption string) (tbmodel.InfraAccessInfo, error)

func (*Session) ReadInfraIDs added in v0.5.1

func (s *Session) ReadInfraIDs(nsId string) (tbmodel.IdList, error)

func (*Session) ReadNamespace added in v0.5.1

func (s *Session) ReadNamespace(nsId string) (tbmodel.NsInfo, error)

ReadNamespace retrieves information about a specific namespace

func (*Session) ReadRegionInfo added in v0.5.1

func (s *Session) ReadRegionInfo(providerName string, regionName string) (tbmodel.RegionDetail, error)

ReadRegionInfo reads region information in a specific provider

func (*Session) ReadSecurityGroup added in v0.5.1

func (s *Session) ReadSecurityGroup(nsId, securityGroupId string) (tbmodel.SecurityGroupInfo, error)

ReadSecurityGroup retrieves information about a specific Security Group in the specified namespace

func (*Session) ReadSshKey added in v0.5.1

func (s *Session) ReadSshKey(nsId, sshKeyId string) (tbmodel.SshKeyInfo, error)

ReadSshKey retrieves information about a specific SSH Key in the specified namespace

func (*Session) ReadVNet added in v0.5.1

func (s *Session) ReadVNet(nsId, vNetId string) (tbmodel.VNetInfo, error)

ReadVNet retrieves information about a specific Virtual Network (VNet) in the specified namespace

func (*Session) ReadVmOsImage added in v0.5.1

func (s *Session) ReadVmOsImage(nsId, vmOsImageId string) (tbmodel.ImageInfo, error)

ReadVmOsImage retrieves information about a specific VM OS Image in the specified namespace

func (*Session) ReadVmSpec added in v0.5.1

func (s *Session) ReadVmSpec(nsId, vmSpecId string) (tbmodel.SpecInfo, error)

ReadVmSpec retrieves information about a specific VM Spec in the specified namespace

func (*Session) ReviewSpecImagePair added in v0.5.1

ReviewSpecImagePair calls POST /specImagePairReview to validate a spec-image pair and resolve the latest CSP image name (e.g., Alibaba ImageFamily resolution).

func (*Session) SearchVmOsImage added in v0.5.1

func (s *Session) SearchVmOsImage(nsId string, searchImageReq tbmodel.SearchImageRequest) (tbmodel.SearchImageResponse, error)

SearchVmOsImage searches VM OS images

func (*Session) SetBody added in v0.5.1

func (s *Session) SetBody(body any) *Session

SetBody sets the request body.

func (*Session) SetCacheDuration added in v0.5.1

func (s *Session) SetCacheDuration(d time.Duration) *Session

SetCacheDuration sets the cache duration for the request.

func (*Session) SetContext added in v0.5.1

func (s *Session) SetContext(ctx context.Context) *Session

SetContext sets the context for the request.

func (*Session) SetHeader added in v0.5.1

func (s *Session) SetHeader(key, value string) *Session

SetHeader sets a single header.

func (*Session) SetHeaders added in v0.5.1

func (s *Session) SetHeaders(headers map[string]string) *Session

SetHeaders sets multiple headers.

func (*Session) SetObjectStorageCORS added in v0.5.1

func (s *Session) SetObjectStorageCORS(nsId string, osId string, req tbmodel.ObjectStorageSetCorsRequest) error

SetObjectStorageCORS sets the CORS configuration of an object storage (bucket)

func (*Session) SetObjectStorageVersioning added in v0.5.1

func (s *Session) SetObjectStorageVersioning(nsId string, osId string, req tbmodel.ObjectStorageSetVersioningRequest) error

SetObjectStorageVersioning sets the versioning configuration of an object storage (bucket)

func (*Session) SetQueryParam added in v0.5.1

func (s *Session) SetQueryParam(key, value string) *Session

SetQueryParam sets a single query parameter.

func (*Session) SetQueryParams added in v0.5.1

func (s *Session) SetQueryParams(params map[string]string) *Session

SetQueryParams sets multiple query parameters.

func (*Session) SetResult added in v0.5.1

func (s *Session) SetResult(res any) *Session

SetResult sets the result object to unmarshal the response into.

func (*Session) SetTraceInfo added in v0.5.1

func (s *Session) SetTraceInfo(ctx context.Context) *Session

SetTraceInfo injects the OpenTelemetry trace context into the request headers. This enables distributed tracing by propagating the trace ID and span ID to the Tumblebug API. It uses the global TextMapPropagator to ensure compatibility with the configured tracing backend.

Note: This method modifies the request headers in-place (merging with existing headers). It does not affect the request context or other headers, so it is safe to call regardless of the order of SetHeader or SetContext.

type TbInfraInfoList added in v0.5.1

type TbInfraInfoList struct {
	Infra []tbmodel.InfraInfo `json:"infra"`
}

type TumblebugClient

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

TumblebugClient is the factory for creating request sessions. It holds the shared configuration and connection pool.

func NewClient

func NewClient(cfg ApiConfig) *TumblebugClient

NewClient creates a new TumblebugClient instance.

func NewDefaultClient

func NewDefaultClient() *TumblebugClient

NewDefaultClient creates a new default client.

func (*TumblebugClient) NewSession added in v0.5.1

func (c *TumblebugClient) NewSession() *Session

NewSession creates a new Session for making requests.

type TumblebugTransport added in v0.5.1

type TumblebugTransport struct {
	Transport     http.RoundTripper
	CacheDuration time.Duration
}

TumblebugTransport is a custom http.RoundTripper that adds caching and circuit breaker logic.

func (*TumblebugTransport) RoundTrip added in v0.5.1

func (t *TumblebugTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, returning a Response for the provided Request.

Jump to

Keyboard shortcuts

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