Orchestrating OpenShift Enterprise with ManageIQ

As with any provider in CloudForms, we can easily extend functionality through integration with the provider's API, when the necessary functionality exists.

Here is an example use case which came up recently.

Scaling an OpenShift Application

To scale an existing application, we need to replace-the-specified-deploymentconfig by changing the number of replicas.

URL

This is the API URI needed:

url = "https://#{ose_host}:#{ose_port}"
query = "/oapi/v1/namespaces/#{project}/deploymentconfigs/#{deployment_config}/scale"

Payload

And the necessary payload:

post_params = {
  :kind => "Scale",
  :apiVersion => "extensions/v1beta1",
  :metadata => {
    :name => deployment_config,
    :namespace => project
  },
  :spec => {
    :replicas => replicas.to_i
  }
}

Rest Call

The token is the management service account token used by CloudForms and requires permission to scale the given application.

rest_return = RestClient::Request.execute(
  method: :put,
  url: url + query,
  :headers => {
    :accept        => 'application/json',
    :content_type  => 'application/json',
    :authorization => "Bearer #{token}"
  },
  :payload => post_params.to_json,
  verify_ssl: false)

Here is the full method.

Calling the automation

Calling the automation can be done in a number of ways, for example using a button, service or CloudForms API.

Right now, buttons aren't available for OpenShift resources in CloudForms but they will be soon. In the meantime, we can use a service.

We can variablise project, deploymentconfig and replicas and expose them through a dialogue.

ose_dialogue

The project (namespace) and deploymentconfig (application) can be queried from the OpenShift API and added to a dynamic drop down element. Here are the methods.

Create a catalogue item pointing to the statemachine.

service_cat_item

Our service is ready to order and we can scale up or down easily.

service_catalogue

And in the OpenShift Console, we can see our scaled application.
ose_console-1