Skip to content

Instantly share code, notes, and snippets.

@coolpalani
Forked from tsailiming/add_aws_provider.rb
Created September 11, 2017 18:00
Show Gist options
  • Save coolpalani/39c02fa2e2e818d2a89e3fe9ffac66d2 to your computer and use it in GitHub Desktop.
Save coolpalani/39c02fa2e2e818d2a89e3fe9ffac66d2 to your computer and use it in GitHub Desktop.
Sample code to add AWS provider in a service catalog in CloudForms
require 'rest-client'
require 'json'
servername = 'cf'
username = 'admin'
password = 'smartvm'
url = "https://#{servername}/api/providers"
post_params = {
:name => $evm.root['dialog_name'],
:type => "ManageIQ::Providers::Amazon::CloudManager",
#:zone => { :id => "1000000000001" },
:provider_region => "ap-southeast-1",
:credentials => {
:userid => $evm.root['dialog_aws_access_key_id'],
:password => $evm.root['dialog_aws_secret_access_key']
}
}.to_json
begin
rest_return = RestClient::Request.execute(
method: :post,
url: url,
:user => username,
:password => password,
:headers => {:accept => :json},
:payload => post_params,
verify_ssl: false)
result = JSON.parse(rest_return)
$evn.log(:info, result)
rescue => e
$evm.log(:error, "Error: #{e}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment