Creating Roles

You can create roles on an existing cloud by POSTing to /api/clouds/XXXXX/roles

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

RestClient.post("https://manage.scalarium.com/api/clouds/XXXXX/roles",
  JSON.dump(:role_type => 'nodejs-app',
                       :custom_recipes_setup => ['my::setup', 'my::cronjob'],
                       :custom_recipes_configure => ['my::configure'],
                       :custom_recipes_deploy => ['my::deploy'],
                       :custom_recipes_undeploy => ['my::undeploy']),
  headers)

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

Role Basics

  • role_type: Must be one of the following:
    • 'lb' for 'Load Balancer',
    • 'rails-app' for 'Rails Application Server',
    • 'php-app' for 'PHP Application Server',
    • 'nodejs-app' for 'node.js Application Server',
    • 'db-master' for 'MySQL Master',
    • 'web' for 'Web Server',
    • 'mq' for 'Queue Server',
    • 'custom' for 'Custom Role',
    • 'memcached' for 'Memcached Server',
    • 'monitoring-master' for 'Ganglia Monitoring Master'

    if you choose the 'custom' role you have to specify

    • name: The name that is show in the UI for this role.
    • shortname: The name that is used by Chef recipes and internally.

Custom recipes

  • custom_recipes_setup: Chef recipes that get executed during the setup - e.g. ['my::setup', 'my::cronjob']
  • custom_recipes_configure: Recipes that get executed if a configure event is triggered.
  • custom_recipes_deploy: Recipes that get executed during a deployment.
  • custom_recipes_undeploy: Recipes that get executed during an undeploy of an application.

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" => "12345", "Accept" => "application/vnd.scalarium-v1+json", "Content-Type"=>"application/json"}

begin
  RestClient.post("https://manage.scalarium.com/api/clouds/XXXXX/roles",
                JSON.dump(:role_type => 'nodejs-app',
                          :custom_recipes_setup => ['my::setup', 'my::cronjob'],
                          :custom_recipes_configure => ['my::configure'],
                          :custom_recipes_deploy => ['my::deploy'],
                          :custom_recipes_undeploy => ['my::undeploy']),
                headers)
rescue => e
  e.response
end

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

{
  "id":"jd75dfgh23s4hjbgsdf6598rhg8wat4ecg83h4fv"
}