Class: StatsCloud::ClusterClient

Inherits:
Object
  • Object
show all
Includes:
LoggerHelper
Defined in:
lib/statscloud/cluster_client.rb

Overview

statscloud.io cluster-api service client.

Instance Method Summary collapse

Methods included from LoggerHelper

#logger

Constructor Details

#initialize(env, host = "https://cluster-api-v1.statscloud.statscloud.io") ⇒ ClusterClient

Constructs cluster-api service client instance.

Parameters:

  • env (+String+)

    cluster api environment

  • host (+String+) (defaults to: "https://cluster-api-v1.statscloud.statscloud.io")

    cluster api host.



21
22
23
24
# File 'lib/statscloud/cluster_client.rb', line 21

def initialize(env, host = "https://cluster-api-v1.statscloud.statscloud.io")
  @environment = env
  @host = host
end

Instance Method Details

#deploy_cluster(token, app, configuration) ⇒ Object

Schedules cluster to be (re)deployed.

Parameters:

  • token (+String+)

    authorization token.

  • app (+String+)

    cluster name.

  • configuration (+String+)

    cluster configuration



52
53
54
55
56
57
58
59
# File 'lib/statscloud/cluster_client.rb', line 52

def deploy_cluster(token, app, configuration)
  url = "#{host}/users/current/clusters/#{app}/#{environment}"
  body = body_hash_parameters(configuration)
  response = http_client.put(url, body.to_json, headers(token))
  get_parsed_response(response)
rescue StandardError => error
  logger.error error
end

#get_cluster(token, app) ⇒ Object

Schedules cluster instance to be retrieved.

Parameters:

  • token (+String+)

    authorization token.

  • app (+String+)

    cluster name.



34
35
36
37
38
39
40
# File 'lib/statscloud/cluster_client.rb', line 34

def get_cluster(token, app)
  url = "#{host}/users/current/clusters/#{app}/#{environment}"
  response = http_client.get(url, headers(token))
  get_parsed_response(response)
rescue StandardError => error
  logger.error error
end

#undeploy_cluster(token, app) ⇒ Object

Schedules cluster to be undeployed.

Parameters:

  • token (+String+)

    authorization token.

  • app (+String+)

    cluster name.



68
69
70
71
72
73
74
# File 'lib/statscloud/cluster_client.rb', line 68

def undeploy_cluster(token, app)
  url = "#{host}/users/current/clusters/#{app}/#{environment}/undeploy"
  response = http_client.post(url, nil, headers(token))
  get_parsed_response(response)
rescue StandardError => error
  logger.error error
end