-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
) | ||
|
||
func init(){ | ||
flag.Set("logtostderr", "true") | ||
} | ||
|
||
var ( | ||
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint") | ||
driverName = flag.String("drivername", "csi-qingcloud-performance", "name of the driver") | ||
nodeID = flag.String("nodeid", "", "node id") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
handle() | ||
os.Exit(0) | ||
} | ||
|
||
func handle(){ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package block | ||
|
||
import ( | ||
// qcclient "github.com/yunify/qingcloud-sdk-go/client" | ||
qcconfig "github.com/yunify/qingcloud-sdk-go/config" | ||
qcservice "github.com/yunify/qingcloud-sdk-go/service" | ||
"github.com/golang/glog" | ||
) | ||
|
||
const ( | ||
VolumeTypePerformance = 0 | ||
VolumeTypeHighPerformance = 3 // Only support BJ2 | ||
VolumeTypeCapacity = 1 // BJ1, AS1: 1; BJ2, GD1: 2 | ||
) | ||
|
||
type persistentVolume struct{ | ||
VolName string `json:"volName"` | ||
VolID string `json:"volID"` | ||
VolType string `json:"volType"` | ||
VolSize int64 `json:"volSize"` | ||
} | ||
|
||
type volumeManager struct { | ||
volumeService *qcservice.VolumeService | ||
persistentVolume *persistentVolume | ||
} | ||
|
||
func newVolumeManager(config *qcconfig.Config)(*volumeManager, error){ | ||
qcService, err := qcservice.Init(config) | ||
if err != nil{ | ||
return nil,err | ||
} | ||
// create volume service | ||
volumeService, err := qcService.Volume(config.Zone) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
qc := volumeManager{ | ||
volumeService: volumeService, | ||
persistentVolume: &persistentVolume{}, | ||
} | ||
glog.Infof("newVolumeManager init finish, zone: %v", config.Zone) | ||
return &qc, nil | ||
} | ||
|
||
// check existence volume by volume ID | ||
// Return: true: volume exist, false: volume not exist | ||
func (vm *volumeManager)IsVolumeIdExist()(bool,error){ | ||
input := qcservice.DescribeVolumesInput{} | ||
id := vm.persistentVolume.VolID | ||
input.Volumes = append(input.Volumes, &id) | ||
// consult volume info | ||
output, err := vm.volumeService.DescribeVolumes(&input) | ||
if err != nil{ | ||
return false, err | ||
} | ||
// IaaS response return code not equal to 0 | ||
if *output.RetCode != 0{ | ||
glog.Errorf("call DescribeVolumes() return %d, volume ID: %s, volume.zone: %s", | ||
*output.RetCode, id, vm.volumeService.Properties.Zone) | ||
} | ||
// IaaS response total count more than 1 | ||
if *output.TotalCount == 0 { | ||
|
||
} | ||
if *output.TotalCount > 1 { | ||
glog.Errorf("has duplicated volume ID %s in zone %s", | ||
id, vm.volumeService.Properties.Zone) | ||
} | ||
if *output.TotalCount == 1 && | ||
*output.VolumeSet[0].VolumeID == id{ | ||
return true, nil | ||
}else{ | ||
return false, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package block | ||
|
||
import( | ||
qcconfig "github.com/yunify/qingcloud-sdk-go/config" | ||
"testing" | ||
"github.com/golang/glog" | ||
) | ||
|
||
func createConfig()(config *qcconfig.Config, err error){ | ||
accessKeyId := "" | ||
accessKeySecret := "" | ||
config,err = qcconfig.New(accessKeyId,accessKeySecret) | ||
config.Zone = "sh1a" | ||
if err != nil{ | ||
return nil, err | ||
}else{ | ||
return config,nil | ||
} | ||
} | ||
|
||
func TestVolumeIdExist(t *testing.T){ | ||
// create volume manager | ||
config, err := createConfig() | ||
if err != nil{ | ||
glog.Error(err) | ||
} | ||
vm, err := newVolumeManager(config) | ||
if err != nil{ | ||
glog.Error(err) | ||
} | ||
|
||
testcase := []struct{ | ||
id string | ||
ret bool | ||
}{ | ||
{"vol-57sm6cas", true}, | ||
{"vol-aseereww", false}, | ||
} | ||
for _, v:=range testcase{ | ||
vm.persistentVolume.VolID = v.id | ||
flag, err := vm.IsVolumeIdExist() | ||
if err != nil{ | ||
t.Errorf("test in %s: error: %v", v.id, err) | ||
} | ||
if flag != v.ret{ | ||
t.Errorf("testcase failed in %s, expected %t, actually %t", | ||
v.id, v.ret, flag) | ||
} | ||
} | ||
|
||
|
||
} |