Class: Scalarium::API

Inherits:
AbstractAPI show all
Defined in:
lib/scalarium-api-wrapper/api.rb

Instance Method Summary collapse

Instance Method Details

#deploy_application(app_id, options = {:comment => nil, :migrate => false}) ⇒ Hash

Method allows to deploy application in scalarium

Parameters:

  • app_id (String)
    • The ID of application we want to deploy.

  • options (Hash) (defaults to: {:comment => nil, :migrate => false})

    a customizable set of options

Options Hash (options):

  • :comment (String)
    • comment to be displayed on the deployment

  • :migrate (Boolean)
    • boolean indicating if we should run the migrations too (false by default)

Returns:

  • (Hash)

    response of the progress and details



105
106
107
108
109
110
# File 'lib/scalarium-api-wrapper/api.rb', line 105

def deploy_application(app_id, options = {:comment => nil, :migrate => false})
  json_command = JSON.dump(:command => 'deploy', 
                           :comment => options[:comment], 
                           :migrate => options[:migrate])
  http_post_request(Scalarium.applications_url+"/#{app_id}/deploy", json_command)                         
end

#fetch_all_deployments(app_id) ⇒ Array

Method allows to fetch all the deployments for the specified application

Parameters:

  • app_id (String)
    • String app_id of application that deployments we want to see

Returns:

  • (Array)
    • Delivers array of all the deployments for the application

See Also:



91
92
93
94
# File 'lib/scalarium-api-wrapper/api.rb', line 91

def fetch_all_deployments(app_id)
  warn "[WARRNING!] This functionality might not be yet supported by Scalarium!"
  http_get_request(Scalarium.applications_url+"/#{app_id}/deployments/#{deployment_id}")
end

#fetch_deployment_details(app_id, deployment_id) ⇒ Hash

Method pings scalarium to check the details of the deploy (i.e. progress)

Parameters:

  • app_id (String)
    • String app_id of application we want to see

  • deployment_id (String)
    • String id of the deployment we want to see

Returns:

  • (Hash)
    • Hash contains all the deployment details

See Also:



82
83
84
# File 'lib/scalarium-api-wrapper/api.rb', line 82

def fetch_deployment_details(app_id, deployment_id)
  http_get_request(Scalarium.applications_url+"/#{app_id}/deployments/#{deployment_id}")
end

#get_applicationsArray

Method fetches all applications on the server

Returns:

  • (Array)
    • array containing all the applications



71
72
73
# File 'lib/scalarium-api-wrapper/api.rb', line 71

def get_applications
  http_get_request(Scalarium.applications_url)
end

#get_cloud(cloud_id) ⇒ Hash

Method gets single could details

Parameters:

  • cloud_id (String)
    • id of the cloud we want to see

Returns:

  • (Hash)
    • hash containing details for particular cloud



22
23
24
# File 'lib/scalarium-api-wrapper/api.rb', line 22

def get_cloud(cloud_id)
  http_get_request(Scalarium.clouds_url+"/#{cloud_id}")      
end

#get_cloud_instances(cloud_id) ⇒ Array

Method obtains instances of the cloud

Parameters:

  • cloud_id (String)
    • id of the cloud of which instances we want to see

Returns:

  • (Array)
    • list of the instances



40
41
42
# File 'lib/scalarium-api-wrapper/api.rb', line 40

def get_cloud_instances(cloud_id)
  http_get_request(Scalarium.clouds_url+"/#{cloud_id}/instances")      
end

#get_cloud_roles(cloud_id) ⇒ Array

Method obtains roles per cloud

Parameters:

  • cloud_id (String)
    • id of the cloud of which roles we want to see

Returns:

  • (Array)
    • list of the roles



31
32
33
# File 'lib/scalarium-api-wrapper/api.rb', line 31

def get_cloud_roles(cloud_id)
  http_get_request(Scalarium.clouds_url+"/#{cloud_id}/roles")      
end

#get_clouds(cloud_id = nil) ⇒ Array, Hash

Method fetches all clouds on the server

or when param is passed it gets the particular cloud and

Parameters:

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Array)
    • array containing all the clouds

  • (Hash)
    • @see API#get_cloud



12
13
14
15
# File 'lib/scalarium-api-wrapper/api.rb', line 12

def get_clouds(cloud_id=nil)
  return get_cloud(cloud_id) unless cloud_id.nil?
  http_get_request(Scalarium.clouds_url)      
end

#get_instance_of_cloud(cloud_id, instance_of_cloud_id) ⇒ Hash

Method obtains details of specified instance for a given cloud

Parameters:

  • cloud_id (String)
    • id of the cloud instance detail we want to obtain

  • instance_id (String)
    • id of the instance for specified cloud we want to see

Returns:

  • (Hash)
    • hash with details about the passed instance of the cloud



50
51
52
# File 'lib/scalarium-api-wrapper/api.rb', line 50

def get_instance_of_cloud(cloud_id, instance_of_cloud_id)
  http_get_request(Scalarium.clouds_url+"/#{cloud_id}/instances/#{instance_of_cloud_id}")      
end

#send_instance_command(cloud_id, instance_id, command) ⇒ Object

Method allows to send command to the instance of specified cloud

Parameters:

  • cloud_id (String)
  • instance_id (String)
  • command (Symbol)
    • it can be one of :start, :stop, :reboot

Raises:

  • (ArgumentError)


60
61
62
63
64
65
# File 'lib/scalarium-api-wrapper/api.rb', line 60

def send_instance_command(cloud_id, instance_id, command)
  commands = [:start, :reboot, :stop]
  raise ArgumentError, "You have passed wrong command allowed ones are: #{commands}" if !commands.include?(command) 

  http_post_request(Scalarium.clouds_url+"/#{cloud_id}/instances/#{instance_id}/#{command.to_s}")  
end