Class: Ancor::CLI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ancor/cli/client.rb

Constant Summary collapse

CONTENT_TYPE_JSON =
'application/json'
CONTENT_TYPE_YAML =
'application/yaml'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ancor/cli/client.rb', line 7

def initialize(options)
  host = options.fetch(:host)
  port = options.fetch(:port)

  url = "http://#{host}:#{port}/v1/"

  @connection = Faraday.new(url: url) do |faraday|
    faraday.response :logger if options[:debug]
    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#add_env(slug) ⇒ Object



71
72
73
74
# File 'lib/ancor/cli/client.rb', line 71

def add_env(slug)
  request_body = { slug: slug }
  post 'environments', CONTENT_TYPE_JSON, request_body.to_json
end

#add_instance(role_slug) ⇒ Object



52
53
54
55
# File 'lib/ancor/cli/client.rb', line 52

def add_instance(role_slug)
  request_body = { role: role_slug }
  post 'instances', CONTENT_TYPE_JSON, request_body.to_json
end

#commit(slug) ⇒ Object



23
24
25
26
# File 'lib/ancor/cli/client.rb', line 23

def commit(slug)
  request_body = { commit: true }
  put "environments/#{slug}", CONTENT_TYPE_JSON, request_body.to_json
end

#list_envsObject



36
37
38
# File 'lib/ancor/cli/client.rb', line 36

def list_envs
  get 'environments'
end

#list_goalsObject



32
33
34
# File 'lib/ancor/cli/client.rb', line 32

def list_goals
  get 'goals'
end

#list_instancesObject



48
49
50
# File 'lib/ancor/cli/client.rb', line 48

def list_instances
  get 'instances'
end

#list_rolesObject



40
41
42
# File 'lib/ancor/cli/client.rb', line 40

def list_roles
  get 'roles'
end

#list_tasksObject



44
45
46
# File 'lib/ancor/cli/client.rb', line 44

def list_tasks
  get 'tasks'
end

#plan(slug, arml_spec) ⇒ Object



28
29
30
# File 'lib/ancor/cli/client.rb', line 28

def plan(slug, arml_spec)
  post "environments/#{slug}/plan", CONTENT_TYPE_YAML, arml_spec
end

#remove_env(slug) ⇒ Object



76
77
78
# File 'lib/ancor/cli/client.rb', line 76

def remove_env(slug)
  @connection.delete "environments/#{slug}"
end

#remove_instance(old_id) ⇒ Object



57
58
59
# File 'lib/ancor/cli/client.rb', line 57

def remove_instance(old_id)
  @connection.delete "instances/#{old_id}"
end

#replace_all_instances(role_slug) ⇒ Object



66
67
68
69
# File 'lib/ancor/cli/client.rb', line 66

def replace_all_instances(role_slug)
  request_body = { role: role_slug }
  post "instances/#{role_slug}/replace_all", CONTENT_TYPE_JSON, request_body.to_json
end

#replace_instance(old_id) ⇒ Object



61
62
63
64
# File 'lib/ancor/cli/client.rb', line 61

def replace_instance(old_id)
  request_body = { replace: true }
  put "instances/#{old_id}", CONTENT_TYPE_JSON, request_body.to_json
end

#versionObject



19
20
21
# File 'lib/ancor/cli/client.rb', line 19

def version
  get ''
end