Documentation
¶
Index ¶
- func ExecuteAction(ctx context.Context, cfg cloud.RetryConfig, opName string, ...) error
- type Client
- func (c *Client) CreateManagedSnapshot(ctx context.Context, volumeID string, name string, metadata map[string]string) (CreatedSnapshot snapshots.Snapshot, RequestID string, Error error)
- func (c *Client) CreateVolumeSubscription(ctx context.Context, volumeID string, metadata map[string]string) (SubscribedVolume volumes.Volume, RequestID string, Error error)
- func (c *Client) DeleteSnapshot(ctx context.Context, snapshotID string) (RequestID string, Error error)
- func (c *Client) GetCloudProviderName() string
- func (c *Client) GroupVolumeByVMAttachment(volumeList []volumes.Volume) VMGroupedVolumeList
- func (c *Client) ListManagedSnapshots(ctx context.Context) (ManagedSnapshots []snapshots.Snapshot, Error error)
- func (c *Client) ListManagedVolumeSnapshots(ctx context.Context, volumeID string, policyType string, lastSnapshotOnly bool) (ManagedSnapshots []snapshots.Snapshot, Error error)
- func (c *Client) ListSubscribedVolumes(ctx context.Context) (SubscribedVolumes []volumes.Volume, Error error)
- func (c *Client) NewClient() error
- type VMGroupedVolumeList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecuteAction ¶
func ExecuteAction(ctx context.Context, cfg cloud.RetryConfig, opName string, operation func(ctx context.Context) error) error
ExecuteAction wraps a function with robust retry logic, including exponential backoff, jitter, and context timeouts.
opName is used for logging and debugging purposes. operation is the function to execute; it must accept a context to support cancellation.
Types ¶
type Client ¶
type Client struct {
// ProfileName corresponds to the entry in clouds.yaml
ProfileName string
// RetryConfig defines the behavior for transient error handling
RetryConfig cloud.RetryConfig
// Internal service clients
ComputeClient *gophercloud.ServiceClient
BlockStorageClient *gophercloud.ServiceClient
}
Client manages the connection and service clients for OpenStack interactions. It wraps standard gophercloud clients with retry logic and profile management.
func (*Client) CreateManagedSnapshot ¶
func (c *Client) CreateManagedSnapshot( ctx context.Context, volumeID string, name string, metadata map[string]string, ) ( CreatedSnapshot snapshots.Snapshot, RequestID string, Error error, )
CreateManagedSnapshot triggers the creation of a new snapshot and waits for it to become available.
Behavior:
- Force Creation: Uses the `Force: true` flag, allowing snapshots to be taken even if the volume is currently attached ("in-use") by an instance.
- Synchronous Wait: This method blocks until the snapshot reaches the "available" state in OpenStack (or until the context times out). This ensures the snapshot is fully persisted before the function returns.
- Metadata: Applies the provided policy tags (e.g., Expiry Date, Policy Type) at creation time.
Returns:
- CreatedSnapshot: The struct containing details of the finished snapshot.
- RequestID: The OpenStack tracing ID.
- Error: Returns an error if the API call fails or if the snapshot ends up in an "error" state.
func (*Client) CreateVolumeSubscription ¶
func (c *Client) CreateVolumeSubscription( ctx context.Context, volumeID string, metadata map[string]string, ) (SubscribedVolume volumes.Volume, RequestID string, Error error)
CreateVolumeSubscription applies the provided metadata tags to a specific volume. It serves as the mechanism to "subscribe" a volume to a snapshot policy by writing the specific policy configuration (e.g., Schedule, Retention) into the volume's metadata.
Concurrency & Safety: This method implements a "Read-Modify-Write" strategy to ensure safety:
- GET: Fetches the current volume details to retrieve existing metadata.
- MERGE: Combines existing tags (e.g., External metadata, Existing policies) with the new policy tags. Incoming keys overwrite existing keys, but unrelated keys are preserved.
- UPDATE: Pushes the merged map back to OpenStack.
Returns:
- SubscribedVolume: The updated volume object from OpenStack.
- RequestID: The X-Openstack-Request-Id header for tracing.
- Error: Any error encountered during the process (after retries).
func (*Client) DeleteSnapshot ¶
func (c *Client) DeleteSnapshot(ctx context.Context, snapshotID string) (RequestID string, Error error)
DeleteSnapshot removes a snapshot from the backend storage.
Behavior:
- Force Delete: This method explicitly triggers a "Force Delete" operation. This ensures the snapshot is removed even if the storage backend indicates it is busy or in a stuck state, preventing "zombie" snapshots from accumulating.
- Asynchronous: Unlike creation, deletion is often asynchronous. This method returns success once the delete request is accepted by the API, but does not wait for the resource to disappear completely.
Returns:
- RequestID: The OpenStack tracing ID for the delete operation.
- Error: Returns an error if the delete request fails (e.g., 404 Not Found or 403 Forbidden).
func (*Client) GetCloudProviderName ¶
GetCloudProviderName returns the identifier for this provider.
func (*Client) GroupVolumeByVMAttachment ¶
func (c *Client) GroupVolumeByVMAttachment(volumeList []volumes.Volume) VMGroupedVolumeList
func (*Client) ListManagedSnapshots ¶
func (c *Client) ListManagedSnapshots(ctx context.Context) ( ManagedSnapshots []snapshots.Snapshot, Error error, )
ListManagedSnapshots retrieves every snapshot in the project that is managed by SnapSentry. This is primarily used by the Expiry/Cleanup workflow to find candidates for deletion.
Filtering: Since OpenStack API filtering is limited for custom metadata keys, this method performs "Client-Side Filtering": it fetches all 'available' snapshots and iterates through them, parsing the metadata to find those with the 'x-snapsentry-managed' tag set to true.
func (*Client) ListManagedVolumeSnapshots ¶
func (c *Client) ListManagedVolumeSnapshots(ctx context.Context, volumeID string, policyType string, lastSnapshotOnly bool) ( ManagedSnapshots []snapshots.Snapshot, Error error, )
ListManagedVolumeSnapshots fetches the snapshot history for a specific volume, filtered by policy type.
Parameters:
- volumeID: The UUID of the volume to inspect.
- policyType: The policy identifier to filter by (e.g., "daily", "weekly").
- lastSnapshotOnly: Optimization flag. If true, the function stops after finding the first match. This is used during the "Evaluate" phase to quickly find the most recent snapshot for idempotency checks.
Note: This relies on the OpenStack API returning snapshots sorted by creation date (Newest First), which is the default behavior for Cinder.
func (*Client) ListSubscribedVolumes ¶
func (c *Client) ListSubscribedVolumes(ctx context.Context) (SubscribedVolumes []volumes.Volume, Error error)
ListSubscribedVolumes discovers all volumes that are currently managed by SnapSentry. It filters the OpenStack volume list by checking for the presence of the generic management tag (defined in policy.ManagedTag).
Features:
- Pagination: Automatically traverses all pages of results from the OpenStack API to ensure a complete dataset is returned, even for large environments.
Returns:
- SubscribedVolumes: A slice containing every volume with the managed tag.
- Error: Detailed error if the operation fails after max retries.