Creating Clouds

Creating Clouds

You can create clouds by POSTing to /api/clouds

headers = {"X-Scalarium-Token" => "XXXXX",
  "Accept" => "application/vnd.scalarium-v1+json",
  "Content-Type"=>"application/json"}

RestClient.post('https://manage.scalarium.com/api/clouds',
                        JSON.dump(:name => 'A nice Cloud',
                           :region => 'eu-west-1',
                           :credential_id => 'XXXXX'),
                        headers)

Accepted attributes in the POST body (encoded as JSON hash) are:

  • name: Name of the cloud
  • region: Must be one of the AWS regions, e.g. eu-west-1 or us-east-1.
  • credential_id: The ID of AWS credential to use for this cloud. You can also create a new credential instead of specifying an existing one. See credential_aws_access_key_id below.

Optional attributes are:

  • nickname_theme: The nickname theme to use, where spaces are replaced by underscores, e.g. Bud_Spencer. Defaults to the role based naming theme.
  • ssh_key_id: The ID of a SSH key in the region and belonging to the chosen credential. This is the default SSH usable by the ubuntu user. Defaults to no key.
  • ssh_key_name: The name of a new SSH key to create in the chosen region for the chosen credential. The key will then be made the default SSH key of the cloud.
  • credential_aws_access_key_id: The AWS access key id of a new credential to be used by this cloud. Will create a new credential. Must be set together with credential_aws_secret_access_key.
  • credential_aws_secret_access_key: The AWS secret access key of the new credential to be created and used. Must be used together with the credential_aws_access_key_id.

If validation fails, the API will return HTTP status code 412 with the errors included in the body, like so:

{
  "errors": ["Name can't be blank"]
}

If you are using RestClient, you get an exception in case of a 412 HTTP response. To evaluate the response body, you need to catch the exception, e.g.:

headers = {"X-Scalarium-Token" => "XXXXX",
    "Accept" => "application/vnd.scalarium-v1+json",
    "Content-Type"=>"application/json"}
begin
  RestClient.post('https://manage.scalarium.com/api/clouds',
                        JSON.dump(:name => 'A nice Cloud',
                           :region => 'eu-west-1',
                           :credential_id => 'XXXXX'),
                        headers)
rescue => e
  e.response
end

If the instance was successfully created, the response will include the HTTP location of the new cloud and its ID in the response body:

{
  "id":"afcea12f14cbcffe1ec61cf12cd543e4"
}