如何使用SoftLayer REST API创建自动缩放组

时间:2016-08-15 20:44:15

标签: rest ibm-cloud-infrastructure

我正在使用此URL来获取我想要修改的现有Auto Scale Group。它似乎有关于我需要的服务端口,策略,资源触发器,手表,操作的所有信息。

https://api.softlayer.com/rest/v3/SoftLayer_Scale_Group/1120061/getObject.json?objectMask=mask[policies[resourceUseTriggers[watches],actions],loadBalancers]

结果回复包含在下面的“回应1”中。

然后我将响应修改为“删除ID”,然后修改它以用作模板来创建新的Auto Scale组,新请求JSON显示在下面的“REQUEST 1”中。

当我使用POST将

https://api.softlayer.com/rest/v3/SoftLayer_Scale_Group/createObject.json

我收到标准错误 - “远程服务器返回错误:(500)内部服务器错误。”

那么我在这里做错了什么?

==请求1 ==

{ "parameters": [

{
  "virtualGuestMemberTemplate": {
    "accountId": 940999,
    "domain": "partpic.com",
    "hostname": "CaffeServer-test-001",
    "maxMemory": 1024,
    "postInstallScriptUri": "https://webdev.partpic.com/ppsvc/CaffeStartup.aspx?model=Sample.tar.gz",
    "startCpus": 1,
    "blockDeviceTemplateGroup": {
      "globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
    },
    "datacenter": {
      "name": "dal06"
    },
    "hourlyBillingFlag": true
  },
  "loadBalancers": [{
    "healthCheckId": 609283,
    "id": 101503,
    "port": 32400,
    "virtualServerId": 275643
  }],
  "policies": [{
    "name": "ScaleDown",
    "resourceUseTriggers": [{
      "typeId": 3,
      "watches": [{
        "algorithm": "EWMA",
        "metric": "host.cpu.percent",
        "operator": "<",
        "period": 1500,
        "value": "20"
      }]
    }],
    "actions": [{
      "typeId": 1,
      "amount": 80,
      "scaleType": "PERCENT"
    }]
  },
  {
    "name": "ScaleUp",
    "resourceUseTriggers": [{
      "typeId": 3,
      "watches": [{
        "algorithm": "EWMA",
        "metric": "host.cpu.percent",
        "operator": ">",
        "period": 600,
        "value": "80"
      }]
    }],
    "actions": [{
      "typeId": 1,
      "amount": 150,
      "scaleType": "PERCENT"
    }]
  }],
  "status": {
    "id": 1,
    "keyName": "ACTIVE",
    "name": "Active"
  },
  "virtualGuestAssets": [],
  "virtualGuestMembers": [],
  "accountId": 940999,
  "cooldown": 60,
  "name": "scale_test-001",
  "regionalGroupId": 22,
  "terminationPolicyId": 1
}

]}

== RESPONSE 1 ==

{
  "accountId": 940999,
  "balancedTerminationFlag": false,
  "cooldown": 60,
  "createDate": "2016-08-08T13:19:51-05:00",
  "desiredMemberCount": null,
  "id": 1120061,
  "lastActionDate": "2016-08-12T14:22:51-05:00",
  "maximumMemberCount": 0,
  "minimumMemberCount": 0,
  "modifyDate": "2016-08-12T14:22:57-05:00",
  "name": "scale_CaffeServerSample",
  "regionalGroupId": 22,
  "suspendedFlag": false,
  "terminationPolicyId": 1,
  "virtualGuestMemberTemplate": {
    "accountId": 940999,
    "createDate": null,
    "dedicatedAccountHostOnlyFlag": null,
    "domain": "partpic.com",
    "hostname": "CaffeServerSample",
    "id": null,
    "lastPowerStateId": null,
    "lastVerifiedDate": null,
    "maxCpu": null,
    "maxMemory": 1024,
    "metricPollDate": null,
    "modifyDate": null,
    "postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
    "provisionDate": null,
    "startCpus": 1,
    "statusId": null,
    "blockDeviceTemplateGroup": {
      "accountId": null,
      "createDate": null,
      "id": null,
      "parentId": null,
      "publicFlag": null,
      "statusId": null,
      "transactionId": null,
      "userRecordId": null,
      "globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
    },
    "datacenter": {
      "id": null,
      "name": "dal06",
      "statusId": null
    },
    "hourlyBillingFlag": true,
    "localDiskFlag": false,
    "privateNetworkOnlyFlag": false
  },
  "loadBalancers": [{
    "createDate": "2016-08-12T14:06:07-05:00",
    "deleteFlag": null,
    "healthCheckId": 609283,
    "id": 101503,
    "modifyDate": "2016-08-12T14:19:33-05:00",
    "port": 32400,
    "scaleGroupId": 1120061,
    "virtualServerId": 274353,
    "scaleGroup": {
      "accountId": 940999,
      "balancedTerminationFlag": false,
      "cooldown": 60,
      "createDate": "2016-08-08T13:19:51-05:00",
      "desiredMemberCount": null,
      "id": 1120061,
      "lastActionDate": "2016-08-12T14:22:51-05:00",
      "maximumMemberCount": 0,
      "minimumMemberCount": 0,
      "modifyDate": "2016-08-12T14:22:57-05:00",
      "name": "scale_CaffeServerSample",
      "regionalGroupId": 22,
      "suspendedFlag": false,
      "terminationPolicyId": 1,
      "virtualGuestMemberTemplate": {
        "accountId": 940999,
        "createDate": null,
        "dedicatedAccountHostOnlyFlag": null,
        "domain": "partpic.com",
        "hostname": "CaffeServerSample",
        "id": null,
        "lastPowerStateId": null,
        "lastVerifiedDate": null,
        "maxCpu": null,
        "maxMemory": 1024,
        "metricPollDate": null,
        "modifyDate": null,
        "postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
        "provisionDate": null,
        "startCpus": 1,
        "statusId": null,
        "blockDeviceTemplateGroup": {
          "accountId": null,
          "createDate": null,
          "id": null,
          "parentId": null,
          "publicFlag": null,
          "statusId": null,
          "transactionId": null,
          "userRecordId": null,
          "globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
        },
        "datacenter": {
          "id": null,
          "name": "dal06",
          "statusId": null
        },
        "hourlyBillingFlag": true,
        "localDiskFlag": false,
        "privateNetworkOnlyFlag": false
      },
      "loadBalancers": null,
      "policies": [{
        "cooldown": null,
        "createDate": "2016-08-12T14:23:01-05:00",
        "deleteFlag": null,
        "id": 174557,
        "modifyDate": null,
        "name": "ScaleDown",
        "scaleGroupId": 1120061,
        "actions": [{
          "createDate": "2016-08-12T14:23:01-05:00",
          "deleteFlag": null,
          "id": 166457,
          "modifyDate": null,
          "scalePolicyId": 174557,
          "typeId": 1,
          "scalePolicy": null,
          "amount": 80,
          "scaleType": "PERCENT"
        }],
        "resourceUseTriggers": [{
          "createDate": "2016-08-12T14:23:01-05:00",
          "deleteFlag": null,
          "id": 173005,
          "modifyDate": null,
          "scalePolicyId": 174557,
          "typeId": 3,
          "scalePolicy": null,
          "watches": [{
            "algorithm": "EWMA",
            "createDate": "2016-08-12T14:23:01-05:00",
            "deleteFlag": null,
            "id": 143505,
            "metric": "host.cpu.percent",
            "modifyDate": null,
            "operator": "<",
            "period": 1500,
            "scalePolicyTriggerId": 173005,
            "value": "20",
            "scalePolicyTrigger": null
          }]
        }],
        "scaleGroup": null
      },
      {
        "cooldown": null,
        "createDate": "2016-08-12T14:22:51-05:00",
        "deleteFlag": null,
        "id": 174555,
        "modifyDate": null,
        "name": "ScaleUp",
        "scaleGroupId": 1120061,
        "actions": [{
          "createDate": "2016-08-12T14:23:01-05:00",
          "deleteFlag": null,
          "id": 166455,
          "modifyDate": null,
          "scalePolicyId": 174555,
          "typeId": 1,
          "scalePolicy": null,
          "amount": 150,
          "scaleType": "PERCENT"
        }],
        "resourceUseTriggers": [{
          "createDate": "2016-08-12T14:22:51-05:00",
          "deleteFlag": null,
          "id": 173003,
          "modifyDate": null,
          "scalePolicyId": 174555,
          "typeId": 3,
          "scalePolicy": null,
          "watches": [{
            "algorithm": "EWMA",
            "createDate": "2016-08-12T14:22:51-05:00",
            "deleteFlag": null,
            "id": 143503,
            "metric": "host.cpu.percent",
            "modifyDate": null,
            "operator": ">",
            "period": 600,
            "scalePolicyTriggerId": 173003,
            "value": "80",
            "scalePolicyTrigger": null
          }]
        }],
        "scaleGroup": null
      }],
      "status": {
        "id": 1,
        "keyName": "ACTIVE",
        "name": "Active"
      },
      "virtualGuestAssets": [],
      "virtualGuestMembers": []
    }
  }],
  "policies": [{
    "cooldown": null,
    "createDate": "2016-08-12T14:23:01-05:00",
    "deleteFlag": null,
    "id": 174557,
    "modifyDate": null,
    "name": "ScaleDown",
    "scaleGroupId": 1120061,
    "actions": [{
      "createDate": "2016-08-12T14:23:01-05:00",
      "deleteFlag": null,
      "id": 166457,
      "modifyDate": null,
      "scalePolicyId": 174557,
      "typeId": 1,
      "scalePolicy": null,
      "amount": 80,
      "scaleType": "PERCENT"
    }],
    "resourceUseTriggers": [{
      "createDate": "2016-08-12T14:23:01-05:00",
      "deleteFlag": null,
      "id": 173005,
      "modifyDate": null,
      "scalePolicyId": 174557,
      "typeId": 3,
      "scalePolicy": null,
      "watches": [{
        "algorithm": "EWMA",
        "createDate": "2016-08-12T14:23:01-05:00",
        "deleteFlag": null,
        "id": 143505,
        "metric": "host.cpu.percent",
        "modifyDate": null,
        "operator": "<",
        "period": 1500,
        "scalePolicyTriggerId": 173005,
        "value": "20",
        "scalePolicyTrigger": null
      }]
    }],
    "scaleGroup": {
      "accountId": 940999,
      "balancedTerminationFlag": false,
      "cooldown": 60,
      "createDate": "2016-08-08T13:19:51-05:00",
      "desiredMemberCount": null,
      "id": 1120061,
      "lastActionDate": "2016-08-12T14:22:51-05:00",
      "maximumMemberCount": 0,
      "minimumMemberCount": 0,
      "modifyDate": "2016-08-12T14:22:57-05:00",
      "name": "scale_CaffeServerSample",
      "regionalGroupId": 22,
      "suspendedFlag": false,
      "terminationPolicyId": 1,
      "virtualGuestMemberTemplate": {
        "accountId": 940999,
        "createDate": null,
        "dedicatedAccountHostOnlyFlag": null,
        "domain": "partpic.com",
        "hostname": "CaffeServerSample",
        "id": null,
        "lastPowerStateId": null,
        "lastVerifiedDate": null,
        "maxCpu": null,
        "maxMemory": 1024,
        "metricPollDate": null,
        "modifyDate": null,
        "postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
        "provisionDate": null,
        "startCpus": 1,
        "statusId": null,
        "blockDeviceTemplateGroup": {
          "accountId": null,
          "createDate": null,
          "id": null,
          "parentId": null,
          "publicFlag": null,
          "statusId": null,
          "transactionId": null,
          "userRecordId": null,
          "globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
        },
        "datacenter": {
          "id": null,
          "name": "dal06",
          "statusId": null
        },
        "hourlyBillingFlag": true,
        "localDiskFlag": false,
        "privateNetworkOnlyFlag": false
      },
      "loadBalancers": [{
        "createDate": "2016-08-12T14:06:07-05:00",
        "deleteFlag": null,
        "healthCheckId": 609283,
        "id": 101503,
        "modifyDate": "2016-08-12T14:19:33-05:00",
        "port": 32400,
        "scaleGroupId": 1120061,
        "virtualServerId": 274353,
        "scaleGroup": null
      }],
      "policies": null,
      "status": {
        "id": 1,
        "keyName": "ACTIVE",
        "name": "Active"
      },
      "virtualGuestAssets": [],
      "virtualGuestMembers": []
    }
  },
  {
    "cooldown": null,
    "createDate": "2016-08-12T14:22:51-05:00",
    "deleteFlag": null,
    "id": 174555,
    "modifyDate": null,
    "name": "ScaleUp",
    "scaleGroupId": 1120061,
    "actions": [{
      "createDate": "2016-08-12T14:23:01-05:00",
      "deleteFlag": null,
      "id": 166455,
      "modifyDate": null,
      "scalePolicyId": 174555,
      "typeId": 1,
      "scalePolicy": null,
      "amount": 150,
      "scaleType": "PERCENT"
    }],
    "resourceUseTriggers": [{
      "createDate": "2016-08-12T14:22:51-05:00",
      "deleteFlag": null,
      "id": 173003,
      "modifyDate": null,
      "scalePolicyId": 174555,
      "typeId": 3,
      "scalePolicy": null,
      "watches": [{
        "algorithm": "EWMA",
        "createDate": "2016-08-12T14:22:51-05:00",
        "deleteFlag": null,
        "id": 143503,
        "metric": "host.cpu.percent",
        "modifyDate": null,
        "operator": ">",
        "period": 600,
        "scalePolicyTriggerId": 173003,
        "value": "80",
        "scalePolicyTrigger": null
      }]
    }],
    "scaleGroup": {
      "accountId": 940999,
      "balancedTerminationFlag": false,
      "cooldown": 60,
      "createDate": "2016-08-08T13:19:51-05:00",
      "desiredMemberCount": null,
      "id": 1120061,
      "lastActionDate": "2016-08-12T14:22:51-05:00",
      "maximumMemberCount": 0,
      "minimumMemberCount": 0,
      "modifyDate": "2016-08-12T14:22:57-05:00",
      "name": "scale_CaffeServerSample",
      "regionalGroupId": 22,
      "suspendedFlag": false,
      "terminationPolicyId": 1,
      "virtualGuestMemberTemplate": {
        "accountId": 940999,
        "createDate": null,
        "dedicatedAccountHostOnlyFlag": null,
        "domain": "partpic.com",
        "hostname": "CaffeServerSample",
        "id": null,
        "lastPowerStateId": null,
        "lastVerifiedDate": null,
        "maxCpu": null,
        "maxMemory": 1024,
        "metricPollDate": null,
        "modifyDate": null,
        "postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
        "provisionDate": null,
        "startCpus": 1,
        "statusId": null,
        "blockDeviceTemplateGroup": {
          "accountId": null,
          "createDate": null,
          "id": null,
          "parentId": null,
          "publicFlag": null,
          "statusId": null,
          "transactionId": null,
          "userRecordId": null,
          "globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
        },
        "datacenter": {
          "id": null,
          "name": "dal06",
          "statusId": null
        },
        "hourlyBillingFlag": true,
        "localDiskFlag": false,
        "privateNetworkOnlyFlag": false
      },
      "loadBalancers": [{
        "createDate": "2016-08-12T14:06:07-05:00",
        "deleteFlag": null,
        "healthCheckId": 609283,
        "id": 101503,
        "modifyDate": "2016-08-12T14:19:33-05:00",
        "port": 32400,
        "scaleGroupId": 1120061,
        "virtualServerId": 274353,
        "scaleGroup": null
      }],
      "policies": null,
      "status": {
        "id": 1,
        "keyName": "ACTIVE",
        "name": "Active"
      },
      "virtualGuestAssets": [],
      "virtualGuestMembers": []
    }
  }],
  "status": {
    "id": 1,
    "keyName": "ACTIVE",
    "name": "Active"
  },
  "virtualGuestAssets": [],
  "virtualGuestMembers": []
}

1 个答案:

答案 0 :(得分:0)

我不认为创建一个新的自动缩放组就像复制粘贴和删除一些ID一样容易。

尝试此请求:

{
    "parameters": [

        {
            "balancedTerminationFlag": false,
            "maximumMemberCount": 0,
            "minimumMemberCount": 0,
            "cooldown": 60,
            "name": "scale_test-0012a",
            "regionalGroupId": 22,
            "suspendedFlag": false,
            "terminationPolicyId": 1,
            "virtualGuestMemberTemplate": {
                "domain": "partpic.com",
                "hostname": "CaffeServer-test-001",
                "maxMemory": 1024,
                "postInstallScriptUri": "https://webdev.partpic.com/ppsvc/CaffeStartup.aspx?model=Sample.tar.gz",
                "startCpus": 1,
                "blockDeviceTemplateGroup": {
                    "globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
                },
                "datacenter": {
                    "name": "dal06"
                },
                "hourlyBillingFlag": true,
                "localDiskFlag": false,
                "privateNetworkOnlyFlag": false
            },
            "loadBalancers": [{
                "deleteFlag" : false,
                "port": 32400,
                "virtualServerId": 275643,
                "healthCheck": {
                    "type": {
                        "keyname": "DEFAULT"
                    }
                }
            }],
            "policies": [{
                "name": "ScaleDown",
                "resourceUseTriggers": [{
                    "watches": [{
                        "algorithm": "EWMA",
                        "metric": "host.cpu.percent",
                        "operator": "<",
                        "period": 1500,
                        "value": "20"
                    }]
                }],
                "scaleActions": [{
                    "amount": 80,
                    "scaleType": "PERCENT"
                }]
            }, {
                "name": "ScaleUp",
                "resourceUseTriggers": [{
                    "typeId": 3,
                    "watches": [{
                        "algorithm": "EWMA",
                        "metric": "host.cpu.percent",
                        "operator": ">",
                        "period": 600,
                        "value": "80"
                    }]
                }],
                "scaleActions": [{
                    "amount": 150,
                    "scaleType": "PERCENT"
                }]
            }]
        }

    ]
}