Community

Create more Servers at one with one REST Request

Hello,

I want to create more Servers and Disks at one with one Request. I have allready done one server by request. But the downside of doing it per one request the requests are getting processed sequential. Creation takes therefore much more time, as if done in the DCD at once.

Can you help me to crate the right REST request for more than one server at time (If possible)?

Following a Sample:

!/bin/bash

User=firstname.lastname@example:passwort

User=firstname.lastname@example:passwort VDC=DataCenterUID

curl -s --include --request POST --user $User --header 'Content-Type: application/vnd.profitbricks.resource+json' --data-binary ' { "properties": { "name": "SAMPLESERVER1", "ram": 8192, "cores": 2 }, "entities": { "volumes": { "items": [ { "properties": { "name" : "SAMPLESERVER1 System", "type" : "HDD", "size" : 30, "image" : "ImageUID1", "type": "HDD" } }, { "properties": { "name" : "SAMPLESERVER1 DATA", "type" : "HDD", "size" : 70, "image" : "ImageUID2", "type": "HDD" } } ] }, "nics" : { "items": [ { "properties" : { "name" : null, "ips" : [ "10.10.10.100" ], "dhcp" : true, "lan" : 3, "firewallActive" : false, "nat" : false } }, { "properties" : { "name" : null, "ips" : [ "xxx.xxx.xxx.xxx" ], "dhcp" : true, "lan" : 2, "firewallActive" : false, "nat" : false } } ] } <br/> } }' https://api.profitbricks.com/cloudapi/v3/datacenters/$VDC/servers

Thanks for your help!

 
  • **bold**
  • _italics_
  • `code`
  • ```code block```
  • # Heading 1
  • ## Heading 2
  • > Quote
 

Hello - I suspect there are a couple of ways you could approach this. There are modules or plugins available (on this site) for a number of configuration management tools such as Terraform, Puppet, and Ansible. One of those may be a superior solution.

The Cloud API also allows you to provision a virtual data center with a number of resources at once. Here is an example of provisioning a VDC with two servers, each with a single volume and nic. It should be possible to expand it to provision multiple volumes per server, should you so desire.

#!/usr/bin/bash

CREDS="username@domain.tld:password"

/usr/bin/curl --include --request POST --user $CREDS --header 'Content-Type: application/json' --data-binary '
{"properties": {
"name": "Test_Two_Servers",
"description": "Test Two Servers",
"location": "us/las"
},
"entities": {
"servers": {
 "items": [ {
   "properties": {
      "name": "NewServer001",
      "ram": 1024,
      "cores": 1,
      "availabilityZone": "ZONE_1"
      },
    "entities": {
       "nics": {
          "items": [ {
             "properties": {
                "name": "NIC001",
                "nat": false,
                "lan": 1,
                "dhcp": true }
       } ] },
       "volumes": {
          "items": [ {
             "properties": {
                "size": 20,
                "name": "Volume001",
                "image": "eedb14c9-fe2c-11e6-afc5-525400f64d8d",
                "imagePassword": "x62Ssm8V7mhtLgoGsKbv",
                "bus": "VIRTIO",
                "type": "HDD",
                "availabilityZone": "ZONE_1" }
       } ] }
    }
    },{
   "properties": {
      "name": "NewServer002",
      "ram": 1024,
      "cores": 1,
      "availabilityZone": "ZONE_2"
      },
    "entities": {
       "nics": {
          "items": [ {
             "properties": {
                "name": "NIC002",
                "nat": false,
                "lan": 1,
                "dhcp": true }
       } ] },
       "volumes": {
          "items": [ {
             "properties": {
                "size": 20,
                "name": "Volume002",
                "image": "eedb14c9-fe2c-11e6-afc5-525400f64d8d",
                "imagePassword": "FCPxQhoToLqEp9q7SDb8",
                "bus": "VIRTIO",
                "type": "HDD",
                "availabilityZone": "ZONE_2" }
       } ] }
  }
}
]
}}}}' https://api.profitbricks.com/cloudapi/v3/datacenters

My apologies for the formatting, I was trying to keep it concise, but still make it easy to read.

I'm not personally aware of a direct Cloud API call that you can make to provision a group of servers inside an existing data center. You could loop to make multiple API requests, though there are some rate-limits that could come into play.

Hopefully that helps out a bit!

Eric