【问题标题】:CreateObject Network ComponentsCreateObject 网络组件
【发布时间】:2017-01-31 02:54:26
【问题描述】:

一直在参考createObject API,作为我订购虚拟机请求的一部分,我想为机器配置公共和私有接口。以下是有效的 JSON 的相关部分 -

{
 "parameters":[{
         "hostname": "hostname-test",
         "domain": "domain-test",
         "startCpus": 8,
         "maxMemory": 16384,
         "hourlyBillingFlag": true,
         "operatingSystemReferenceCode": "ubuntu_14_64",
         "localDiskFlag": true,
         "privateNetworkOnlyFlag": false,
         "networkComponents": [
           {
             "maxSpeed": 1000
           }
         ]
     }]
}

但是,我还想设置一个有限的公共带宽,类似于 Web 界面上显示的选项。阅读network component structure 以及上面引用的创建对象调用,我无法解读用于选择特定带宽的字段。

我也发现在 getCreateObjectOptions 中没有提到带宽选项。任何帮助都会很棒。

【问题讨论】:

    标签: json rest virtual-machine ibm-cloud-infrastructure createobject


    【解决方案1】:

    createObject 方法的所有可用选项都使用此方法显示:

    https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getCreateObjectOptions

    关于网络配置,上述方法将返回如下值:

    "networkComponents": [
            {
                "itemPrice": {
                    "hourlyRecurringFee": "0",
                    "recurringFee": "0",
                    "item": {
                        "description": "10 Mbps Public & Private Network Uplinks"
                    }
                },
                "template": {
                    "id": null,
                    "networkComponents": [
                        {
                            "maxSpeed": 10
                        }
                    ],
                    "privateNetworkOnlyFlag": false
                }
            }
    

    在上面的 JSON 中,您可以看到“10 Mbps Public & Private Network Uplinks”项,如果您想在您的订单中配置该项目,您需要遵循“模板”配置,在这种情况下,它表示您需要添加如下配置:

    "networkComponents": [
                        {
                            "maxSpeed": 10
                        }
                    ],
                    "privateNetworkOnlyFlag": false
    

    就是这样,但是 createObject 方法有一个缺点,您只能配置方法 getCreateObjectOptions 显示的选项,但是门户网站提供了许多其他使用 createObject 方法不可用的选项。如果您目前需要高级选项来订购您需要使用 placeOrder 方法,本文可以帮助您理解 placeOrder 方法:

    https://sldn.softlayer.com/blog/bpotter/going-further-softlayer-api-python-client-part-3

    问候

    【讨论】:

    • 我尝试关注softlayer.github.io/rest/place_order,但“id”这个整个概念仍然非常令人困惑。这是我想出的一个json,但我得到了一个状态400。显然我错过了一些东西,这也引发了所有必需的“id”的问题? { "parameters": [{ "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest", "packageId": 46, "location": 449494, "quantity": 1, "hardware": [{ "hostname": "hostname-test", "domain": "domain.name" }], "prices": [ {"id": 37174} # OS ] }] }
    • 我会审查它,但是是的,它很难下订单,是的,如果您需要更多选项(如磁盘等),id 至少需要订单的基本选项也添加这些 id
    • 好人订购服务器有最少的必需项目你的json没有所有这些必需的价格,我建议你调用方法:sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/…你需要发送到方法相同值作为 createObject 方法,但 generateOrderTemplate 将返回一个可用于 placeOrder 方法的订单,您可以根据需要更改一些价格或添加其他价格,基本上该方法将帮助您为 palceOrder 方法提供一个有效的 json 跨度>
    • 嗯,这就是我关于缺少什么的问题。我确实尝试生成已确认可以工作的模板,但是在使用生成的模板下订单时,我现在得到了 500 状态。 {"error":"An internal system error has occurred.","code":"SoftLayer_Exception_InternalError"}
    • 可以发布json的payload吗?
    【解决方案2】:

    在此处添加以供后代使用。

    这是一个 JSON 模板,可用作构建其他配置的基础:

    { "parameters": [{ "imageTemplateId": null, "location": "449500", "packageId": 46, "prices": [{ "hourlyRecurringFee": ".131", "id": 30823, "recurringFee": "87", "item": { "description": "8 x 2.0 GHz Cores" } }, { "hourlyRecurringFee": ".153", "id": 29663, "recurringFee": "101.5", "item": { "description": "16 GB " } }, { "hourlyRecurringFee": "0", "id": 37204, "recurringFee": "0", "item": { "description": "Ubuntu Linux 14.04 LTS Trusty Tahr - Minimal Install (64 bit)" } }, { "hourlyRecurringFee": ".004", "id": 26466, "recurringFee": "2.9", "item": { "description": "100 GB (LOCAL)" } }, { "hourlyRecurringFee": "0", "id": 23070, "recurringFee": "0", "item": { "description": "Reboot / Remote Console" } }, { "hourlyRecurringFee": ".014", "id": 23777, "recurringFee": "5", "item": { "description": "1 Gbps Private Network Uplink" } }, { "hourlyRecurringFee": "0", "id": 34183, "item": { "description": "0 GB Bandwidth" } }, { "hourlyRecurringFee": "0", "id": 34807, "recurringFee": "0", "item": { "description": "1 IP Address" } }, { "hourlyRecurringFee": "0", "id": 27023, "recurringFee": "0", "item": { "description": "Host Ping" } }, { "hourlyRecurringFee": "0", "id": 32500, "recurringFee": "0", "item": { "description": "Email and Ticket" } }, { "hourlyRecurringFee": "0", "id": 32627, "recurringFee": "0", "item": { "description": "Automated Notification" } }, { "hourlyRecurringFee": "0", "id": 33483, "recurringFee": "0", "item": { "description": "Unlimited SSL VPN Users & 1 PPTP VPN User per account" } }, { "hourlyRecurringFee": "0", "id": 35310, "recurringFee": "0", "item": { "description": "Nessus Vulnerability Assessment & Reporting" } }], "quantity": 1, "sourceVirtualGuestId": null, "sshKeys": [{ "sshKeyIds": [ 12345 ] }], "useHourlyPricing": true, "virtualGuests": [{ "domain": "domain.test", "hostname": "hostname.test" }], "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest" }] }

    所需的 ID:

    1. 包 id - 从SoftLayer_Product_Package->getAllObjects 获得 - 它是字段“id”

    2. price id - 从SoftLayer_Product_Package->getItemPrices 获得 - 再次是字段 id(注意有几个地方使用了相同的字段名称)。这列出了可以进入虚拟机的所有可能配置。上面的 JSON 选择了几个选项。

    终于有了JSON模板,就可以验证下单了。

    (PS:仅用虚拟机订单对此进行了测试。SSH Key ID 是一个示例,应替换为有效 ID。)

    【讨论】:

      猜你喜欢
      • 2021-08-01
      • 2023-02-24
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      相关资源
      最近更新 更多