Skip to content

Commit

Permalink
Implement ExtendVolume, CreateSnapshot, PullSnapshot, DeleteSnapshot …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
jackhaibo committed Mar 14, 2019
1 parent 7f7d6c4 commit f7ab4d3
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
87 changes: 87 additions & 0 deletions contrib/drivers/huawei/fusionstorage/dsware.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,90 @@ func (d *Driver) TerminateConnection(opt *pb.DeleteAttachmentOpts) error {

return nil
}

func (d *Driver) PullVolume(volIdentifier string) (*VolumeSpec, error) {
// Not used , do nothing
return nil, nil
}

func (d *Driver) ExtendVolume(opt *pb.ExtendVolumeOpts) (*VolumeSpec, error) {
err := d.cli.extendVolume(EncodeName(opt.GetId()), opt.GetSize()<<UnitGiShiftBit)
if err != nil {
log.Errorf("Extend volume %s (%s) failed: %v", opt.GetName(), opt.GetId(), err)
return nil, err
}
log.Infof("Extend volume %s (%s) success.", opt.GetName(), opt.GetId())
return &VolumeSpec{
BaseModel: &BaseModel{
Id: opt.GetId(),
},
Name: opt.GetName(),
Size: opt.GetSize(),
Description: opt.GetDescription(),
AvailabilityZone: opt.GetAvailabilityZone(),
}, nil
}

func (d *Driver) CreateSnapshot(opt *pb.CreateVolumeSnapshotOpts) (*VolumeSnapshotSpec, error) {
snapName := EncodeName(opt.GetId())
volName := EncodeName(opt.GetVolumeId())

if err := d.cli.createSnapshot(snapName, volName); err != nil {
log.Errorf("Create snapshot %s (%s) failed: %s", opt.GetName(), opt.GetId(), err)
return nil, err
}

log.Errorf("Create snapshot %s (%s) success.", opt.GetName(), opt.GetId())
return &VolumeSnapshotSpec{
BaseModel: &BaseModel{
Id: opt.GetId(),
},
Name: opt.GetName(),
Description: opt.GetDescription(),
VolumeId: opt.GetVolumeId(),
Size: opt.GetSize(),
}, nil
}

func (d *Driver) PullSnapshot(snapIdentifier string) (*VolumeSnapshotSpec, error) {
return nil, nil
}

func (d *Driver) DeleteSnapshot(opt *pb.DeleteVolumeSnapshotOpts) error {
err := d.cli.deleteSnapshot(EncodeName(opt.GetId()))
if err != nil {
log.Errorf("Delete volume snapshot (%s) failed: %v", opt.GetId(), err)
return err
}
log.Infof("Remove volume snapshot (%s) success", opt.GetId())
return nil
}

func (d *Driver) InitializeSnapshotConnection(opt *pb.CreateSnapshotAttachmentOpts) (*ConnectionInfo, error) {
return nil, &NotImplementError{S: "Method InitializeSnapshotConnection has not been implemented yet."}
}

func (d *Driver) TerminateSnapshotConnection(opt *pb.DeleteSnapshotAttachmentOpts) error {
return &NotImplementError{S: "Method TerminateSnapshotConnection has not been implemented yet."}
}

func (d *Driver) CreateVolumeGroup(
opt *pb.CreateVolumeGroupOpts,
vg *VolumeGroupSpec) (*VolumeGroupSpec, error) {
return nil, &NotImplementError{S: "Method CreateVolumeGroup has not been implemented yet."}
}

func (d *Driver) UpdateVolumeGroup(
opt *pb.UpdateVolumeGroupOpts,
vg *VolumeGroupSpec,
addVolumesRef []*VolumeSpec,
removeVolumesRef []*VolumeSpec) (*VolumeGroupSpec, []*VolumeSpec, []*VolumeSpec, error) {
return nil, nil, nil, &NotImplementError{"Method UpdateVolumeGroup has not been implemented yet"}
}

func (d *Driver) DeleteVolumeGroup(
opt *pb.DeleteVolumeGroupOpts,
vg *VolumeGroupSpec,
volumes []*VolumeSpec) (*VolumeGroupSpec, []*VolumeSpec, error) {
return nil, nil, &NotImplementError{S: "Method DeleteVolumeGroup has not been implemented yet."}
}
32 changes: 31 additions & 1 deletion contrib/drivers/huawei/fusionstorage/fsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (c *Cli) request(url, method string, isGetVersion bool, reqParams interface
}

if respResult.RespCode != 0 {
return nil, fmt.Errorf(strconv.Itoa(respResult.GetErrorCode()))
return nil, fmt.Errorf(string(respContent))
}

if resp.Header != nil && len(resp.Header["X-Auth-Token"]) > 0 {
Expand Down Expand Up @@ -476,3 +476,33 @@ func (c *Cli) RunCmd(args ...string) ([]string, error) {

return nil, NewCliError(result)
}

func (c *Cli) extendVolume(name string, newSize int64) error {
url := "/volume/expand"
params := map[string]interface{}{"volName": name, "newVolSize": newSize}
_, err := c.request(url, "POST", false, params)
if err != nil {
return err
}
return nil
}

func (c *Cli) createSnapshot(snapName, volName string) error {
url := "/snapshot/create"
params := map[string]interface{}{"volName": volName, "snapshotName": snapName}
_, err := c.request(url, "POST", false, params)
if err != nil {
return err
}
return nil
}

func (c *Cli) deleteSnapshot(snapName string) error {
url := "/snapshot/delete"
params := map[string]interface{}{"snapshotName": snapName}
_, err := c.request(url, "POST", false, params)
if err != nil {
return err
}
return nil
}

0 comments on commit f7ab4d3

Please sign in to comment.