dongluo3962 2018-05-01 20:47
浏览 54
已采纳

尝试验证虚拟机订单时收到错误

When I run the below code I get the error SoftLayer_Exception_InvalidValue: Invalid value provided for 'blockDevices.device'. A device number must be provided for all block devices. (HTTP 200)

What is wrong with the way I initialize the block devices?

I see the fields, Id and Uuid for type Virtual_Disk_Image, but no number. From the descriptions it sounds like these values are set post-creation. https://github.com/softlayer/softlayer-go/blob/master/datatypes/virtual.go#L91

func verifyOrderTest(c Creds) (string, error) {
    sess := session.New(*c.user, *c.key)
    service := services.GetVirtualGuestService(sess)
    guestTpl := getGuestTplTest()
    guest, err := service.GenerateOrderTemplate(&guestTpl)
    if err != nil {
        return "", err
    }
    productOrderInstance := services.GetProductOrderService(sess)
    _, err = productOrderInstance.VerifyOrder(guest)
    if err != nil {
        return "", err
    }
    return "success", nil
}

func getGuestTplTest() (datatypes.Virtual_Guest) {
    blockDevices := make([]datatypes.Virtual_Guest_Block_Device, 2)
    blockDevices[0] = datatypes.Virtual_Guest_Block_Device{
        DiskImage: &datatypes.Virtual_Disk_Image{
            Capacity: sl.Int(100),
            LocalDiskFlag: sl.Bool(true),
        },
    }
    blockDevices[1] = datatypes.Virtual_Guest_Block_Device{
        DiskImage: &datatypes.Virtual_Disk_Image{
            Capacity: sl.Int(100),
            LocalDiskFlag: sl.Bool(true),
        },
    }

    guestTpl := datatypes.Virtual_Guest{
        BandwidthAllocation: sl.Float(10),
        BlockDevices: blockDevices,
        Datacenter: &datatypes.Location{Name: sl.String("dal13")},
        DedicatedAccountHostOnlyFlag: sl.Bool(true),
        Domain: sl.String("website.com"),
        Hostname: sl.String("hostname"),
        OperatingSystemReferenceCode: sl.String("UBUNTU_16_64"),
        LocalDiskFlag: sl.Bool(true),
        MaxMemory: sl.Int(32768),
        StartCpus: sl.Int(16),
    }
    return guestTpl
}
  • 写回答

1条回答 默认 最新

  • douyi6168 2018-05-02 19:39
    关注

    You just need to add the attribute ¨Device¨ for each Virtual_Guest_Block_Device object and the ¨ LocalDiskFlag ¨ attribute must be added once and not for each Virtual_Guest_Block_Device.

    The same that this example:

    blockDevices := make([]datatypes.Virtual_Guest_Block_Device, 2)
           blockDevices[0] = datatypes.Virtual_Guest_Block_Device{
                  Device: sl.String("0"),
                  DiskImage: &datatypes.Virtual_Disk_Image{
                         Capacity: sl.Int(100),
                  },
           }
           blockDevices[1] = datatypes.Virtual_Guest_Block_Device{
                  Device: sl.String("2"),
                  DiskImage: &datatypes.Virtual_Disk_Image{
                         Capacity: sl.Int(100),
                  },
           }
    

    After that you have to add the symbol ¨&¨ to the parameter ¨ guest ¨ in the method VerifyOrder without this the code will not run.

    result, err := productOrderInstance.VerifyOrder(&guest)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?