class DimensionShell::CloudControl

Public Class Methods

new(args) click to toggle source
# File lib/dimension_shell/cloud_control.rb, line 7
def initialize(args)
  @region = args[:region]
  @organization = args[:organization]
  @username = args[:username]
  @password = args[:password]
end

Public Instance Methods

get_server(servername) click to toggle source
# File lib/dimension_shell/cloud_control.rb, line 14
def get_server(servername)
  _invoke_get path: 'server/server', query: { name: servername }
end
get_server_list() click to toggle source
# File lib/dimension_shell/cloud_control.rb, line 18
def get_server_list
  _invoke_get path: 'server/server'
end

Private Instance Methods

_api_base_uri() click to toggle source
# File lib/dimension_shell/cloud_control.rb, line 27
def _api_base_uri
  "https://api-#{@region}.dimensiondata.com"
end
_api_domain(*args) click to toggle source
# File lib/dimension_shell/cloud_control.rb, line 31
def _api_domain(*args)
  ([_api_base_uri, 'caas', '2.1', @organization] + args.flatten).join('/')
end
_api_header() click to toggle source
# File lib/dimension_shell/cloud_control.rb, line 23
def _api_header
  {'Accept' => 'application/json'}
end
_invoke_get(options) click to toggle source

Invokes a GET request against the dimensiondata-API

@param [Hash] options The options hash. @option options [Hash] :header HTTP-header-elements @option options [Array/String] :path path-appendix of URL @option options [Hash] :query HTTP-query-elements

# File lib/dimension_shell/cloud_control.rb, line 41
def _invoke_get(options)
  header = options[:header] || {}
  header.merge!(_api_header)

  client = HTTPClient.new(default_header: header, force_basic_auth: true)
  client.set_auth _api_base_uri, @username, @password
  #puts "Fetching url \"#{_api_domain(options[:path])}\""
  response = client.get(_api_domain(options[:path]), :query => options[:query])

  if response.ok? then
    JSON.parse(response.body)
  else
    { failure: "#{response.status.to_s} - #{response.reason.to_s}" }
  end
end