Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type Volume struct {

VirtualMachineID string
DeviceID string

// State is the CloudStack volume state, e.g. Allocated, Ready, Destroy.
State string
}

// Snapshot represents a CloudStack snapshot.
Expand All @@ -83,6 +86,9 @@ type Snapshot struct {

VolumeID string
CreatedAt string

// State is the CloudStack snapshot state, e.g. Creating, BackingUp, BackedUp.
State string
}

// VM represents a CloudStack Virtual Machine.
Expand Down
15 changes: 10 additions & 5 deletions pkg/cloud/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package cloud

import (
"context"
"strings"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -46,10 +45,13 @@ func (c *client) GetSnapshotByID(ctx context.Context, snapshotID string) (*Snaps
return &Snapshot{
ID: snapshot.Id,
Name: snapshot.Name,
State: snapshot.State,
Size: snapshot.Virtualsize,
DomainID: snapshot.Domainid,
ProjectID: snapshot.Projectid,
ZoneID: snapshot.Zoneid,
VolumeID: snapshot.Volumeid,
CreatedAt: snapshot.Created,
}, nil
}

Expand All @@ -70,6 +72,7 @@ func (c *client) CreateSnapshot(ctx context.Context, volumeID, name string) (*Sn
return &Snapshot{
ID: snapshot.Id,
Name: snapshot.Name,
State: snapshot.State,
Size: snapshot.Virtualsize,
DomainID: snapshot.Domainid,
ProjectID: snapshot.Projectid,
Expand All @@ -82,11 +85,10 @@ func (c *client) CreateSnapshot(ctx context.Context, volumeID, name string) (*Sn
func (c *client) DeleteSnapshot(_ context.Context, snapshotID string) error {
p := c.Snapshot.NewDeleteSnapshotParams(snapshotID)
_, err := c.Snapshot.DeleteSnapshot(p)
if err != nil && strings.Contains(err.Error(), "4350") {
// CloudStack error InvalidParameterValueException
return ErrNotFound
}

// Errors are returned as they are. CloudStack reports an already deleted
// snapshot with several different messages, so the caller checks whether
// the snapshot still exists instead of matching error text.
return err
}

Expand All @@ -107,6 +109,8 @@ func (c *client) GetSnapshotByName(ctx context.Context, name string) (*Snapshot,
return &Snapshot{
ID: snapshot.Id,
Name: snapshot.Name,
State: snapshot.State,
Size: snapshot.Virtualsize,
DomainID: snapshot.Domainid,
ProjectID: snapshot.Projectid,
ZoneID: snapshot.Zoneid,
Expand Down Expand Up @@ -148,6 +152,7 @@ func (c *client) ListSnapshots(ctx context.Context, volumeID, snapshotID string)
s := &Snapshot{
ID: snapshot.Id,
Name: snapshot.Name,
State: snapshot.State,
Size: snapshot.Virtualsize,
DomainID: snapshot.Domainid,
ProjectID: snapshot.Projectid,
Expand Down
10 changes: 5 additions & 5 deletions pkg/cloud/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"context"
"fmt"
"strconv"
"strings"

"github.com/apache/cloudstack-go/v2/cloudstack"
"k8s.io/klog/v2"
Expand All @@ -42,6 +41,7 @@ func mapVolume(vol *cloudstack.Volume) *Volume {
ZoneID: vol.Zoneid,
VirtualMachineID: vol.Virtualmachineid,
DeviceID: strconv.FormatInt(vol.Deviceid, 10),
State: vol.State,
}
}

Expand Down Expand Up @@ -113,11 +113,11 @@ func (c *client) DeleteVolume(ctx context.Context, id string) error {
"id": id,
})
_, err := c.Volume.DeleteVolume(p)
if err != nil && strings.Contains(err.Error(), "4350") {
// CloudStack error InvalidParameterValueException
return ErrNotFound
}

// Errors are returned as they are. CloudStack uses the same error code for
// "no such volume" and for refusals such as "volume is attached", so the
// caller checks whether the volume still exists before treating a failed
// delete as done.
return err
}

Expand Down
Loading