|
4 | 4 | package alicloud |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "strings" |
| 8 | + |
| 9 | + util "github.com/alibabacloud-go/tea-utils/service" |
7 | 10 | "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" |
8 | 11 |
|
9 | 12 | "encoding/json" |
@@ -38,6 +41,8 @@ type DiskManager interface { |
38 | 41 |
|
39 | 42 | WaitForDiskStatus(diskCid string, toStatus DiskStatus) (string, error) |
40 | 43 | ChangeDiskStatus(cid string, toStatus DiskStatus, checkFunc func(*ecs.Disk) (bool, error)) error |
| 44 | + |
| 45 | + GetDiskPath(path, diskId, instanceType string, category DiskCategory) string |
41 | 46 | } |
42 | 47 |
|
43 | 48 | type DiskManagerImpl struct { |
@@ -362,6 +367,53 @@ func AmendDiskPath(path string, category DiskCategory) string { |
362 | 367 | return path |
363 | 368 | } |
364 | 369 |
|
| 370 | +func (a DiskManagerImpl) GetDiskPath(path, diskId, instanceType string, category DiskCategory) string { |
| 371 | + amendPath := AmendDiskPath(path, category) |
| 372 | + |
| 373 | + if instanceType == "" || diskId == "" { |
| 374 | + return amendPath |
| 375 | + } |
| 376 | + |
| 377 | + conn, err := a.config.EcsTeaClient("") |
| 378 | + if err != nil { |
| 379 | + a.log("EcsTeaClient", err, nil, "") |
| 380 | + return amendPath |
| 381 | + } |
| 382 | + |
| 383 | + invoker := NewInvoker() |
| 384 | + invoker.AddCatcher(CreateInstanceCatcher_IdempotentProcessing) |
| 385 | + invoker.AddCatcher(CreateInstanceCatcher_TokenProcessing) |
| 386 | + invoker.AddCatcher(CreateInstanceCatcher_IpUsed) |
| 387 | + invoker.AddCatcher(CreateInstanceCatcher_IpUsed2) |
| 388 | + |
| 389 | + action := "DescribeInstanceTypes" |
| 390 | + request := map[string]interface{}{ |
| 391 | + "InstanceTypes.1": instanceType, |
| 392 | + "NvmeSupport": "required", |
| 393 | + } |
| 394 | + runtime := util.RuntimeOptions{} |
| 395 | + runtime.SetAutoretry(true) |
| 396 | + err = invoker.Run(func() error { |
| 397 | + resp, e := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2014-05-26"), StringPointer("AK"), nil, request, &runtime) |
| 398 | + if e != nil { |
| 399 | + return e |
| 400 | + } |
| 401 | + if resp["InstanceTypes"] != nil && |
| 402 | + resp["InstanceTypes"].(map[string]interface{})["InstanceType"] != nil && |
| 403 | + len(resp["InstanceTypes"].(map[string]interface{})["InstanceType"].([]interface{})) > 0 { |
| 404 | + amendPath = "/dev/disk/by-id/nvme-Alibaba_Cloud_Elastic_Block_Storage_" + strings.Split(diskId, "-")[1] |
| 405 | + } else { |
| 406 | + amendPath = "/dev/disk/by-id/virtio-" + strings.Split(diskId, "-")[1] |
| 407 | + } |
| 408 | + return e |
| 409 | + }) |
| 410 | + if err != nil { |
| 411 | + a.log(action, err, request, "") |
| 412 | + } |
| 413 | + |
| 414 | + return amendPath |
| 415 | +} |
| 416 | + |
365 | 417 | func DescribeDisks(client *ecs.Client, diskId string) (disk *ecs.Disk, err error) { |
366 | 418 | args := ecs.CreateDescribeDisksRequest() |
367 | 419 | bytes, _ := json.Marshal([]string{diskId}) |
|
0 commit comments