Class: DeisWorkflow::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/deis-workflow.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, api_key) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/deis-workflow.rb', line 9

def initialize(uri, api_key)
  @api_key = api_key
  @controller_uri = uri
  @headers = { 'Authorization' => 'token %s' % @api_key, 'Content-Type' => 'application/json' }
end

Class Method Details

.login(username, password, uri) ⇒ Object

returns an api_key for that user



16
17
18
19
20
21
22
23
24
25
# File 'lib/deis-workflow.rb', line 16

def self.(username, password, uri)
  HTTParty.post(
    "#{uri}/v2/auth/login/",
    :body => JSON.dump({
      :username => username,
      :password => password
    }),
    :headers => { 'Content-Type' => 'application/json' }
  ).parsed_response['token']
end

Instance Method Details

#app_create(app_name) ⇒ Object



60
61
62
63
64
# File 'lib/deis-workflow.rb', line 60

def app_create(app_name)
  post("/v2/apps", {
    :id => app_name
  }).success?
end

#app_exists?(app_name) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/deis-workflow.rb', line 56

def app_exists?(app_name)
  get("#{app_path(app_name)}").success?
end

#app_limit_set(app_name, limit_type, pod_type, limit) ⇒ Object



120
121
122
123
124
125
# File 'lib/deis-workflow.rb', line 120

def app_limit_set(app_name, limit_type, pod_type, limit)
  return false unless %w(memory cpu).include?(limit_type)
  post("#{app_path(app_name)}/config/", {
    limit_type => { pod_type => limit }
  }).success?
end

#app_limit_unset(app_name, limit_type, pod_type) ⇒ Object



127
128
129
130
131
132
# File 'lib/deis-workflow.rb', line 127

def app_limit_unset(app_name, limit_type, pod_type)
  return false unless %w(memory cpu).include?(limit_type)
  post("#{app_path(app_name)}/config/", {
    limit_type => { pod_type => nil }
  }).success?
end

#app_list_pods(app_name) ⇒ Object



82
83
84
# File 'lib/deis-workflow.rb', line 82

def app_list_pods(app_name)
  get("#{app_path(app_name)}/pods/").parsed_response
end

#app_logs(app_name) ⇒ Object



66
67
68
# File 'lib/deis-workflow.rb', line 66

def app_logs(app_name)
  get("#{app_path(app_name)}/logs/").parsed_response
end

#app_releases(app_name) ⇒ Object



70
71
72
# File 'lib/deis-workflow.rb', line 70

def app_releases(app_name)
  get("#{app_path(app_name)}/releases").parsed_response
end

#app_restart(app_name) ⇒ Object



86
87
88
# File 'lib/deis-workflow.rb', line 86

def app_restart(app_name)
  post("#{app_path(app_name)}/pods/restart/").success?
end

#app_scale(app_name, pod_type, desired_pod_count) ⇒ Object

App pod related methods



76
77
78
79
80
# File 'lib/deis-workflow.rb', line 76

def app_scale(app_name, pod_type, desired_pod_count)
  post("#{app_path(app_name)}/scale/", {
    pod_type.to_sym => desired_pod_count
  }).success?
end

#apps_list_allObject

App level methods



52
53
54
# File 'lib/deis-workflow.rb', line 52

def apps_list_all
  get("/v2/apps").parsed_response
end

#config_list(app_name) ⇒ Object

App config methods



108
109
110
# File 'lib/deis-workflow.rb', line 108

def config_list(app_name)
  get("#{app_path(app_name)}/config/").parsed_response['values']
end

#config_set(app_name, values) ⇒ Object

values should be a hash unset by assigning values to nil



114
115
116
117
118
# File 'lib/deis-workflow.rb', line 114

def config_set(app_name, values)
  post("#{app_path(app_name)}/config/", {
    :values => values
  }).success?
end

#perms_create(app_name, username) ⇒ Object

App permissions methods



92
93
94
95
96
# File 'lib/deis-workflow.rb', line 92

def perms_create(app_name, username)
  post("#{app_path(app_name)}/perms/", {
    :username => username
  }).success?
end

#perms_delete(app_name, username) ⇒ Object



98
99
100
# File 'lib/deis-workflow.rb', line 98

def perms_delete(app_name, username)
  delete("#{app_path(app_name)}/perms/#{username}/").success?
end

#perms_list(app_name) ⇒ Object



102
103
104
# File 'lib/deis-workflow.rb', line 102

def perms_list(app_name)
  get("#{app_path(app_name)}/perms/").parsed_response['users']
end

#register(username, email) ⇒ Object

registers a new user to the cluster returns a generated password



39
40
41
42
43
44
45
46
47
48
# File 'lib/deis-workflow.rb', line 39

def register(username, email)
  password = SecureRandom.urlsafe_base64
  post('/v2/auth/register/', {
    :username => username,
    :password => password,
    :email    => email
  })
  # TODO handle the same user registering twice
  password
end

#users_listObject



33
34
35
# File 'lib/deis-workflow.rb', line 33

def users_list
  get('/v2/users').parsed_response['results']
end

#whoamiObject

Cluster level methods



29
30
31
# File 'lib/deis-workflow.rb', line 29

def whoami
  get('/v2/auth/whoami').parsed_response['username']
end