Class: Mamiya::CLI::Client

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

Instance Method Summary collapse

Instance Method Details

#deploy(package) ⇒ Object



180
181
182
# File 'lib/mamiya/cli/client.rb', line 180

def deploy(package)
  deploy_or_rollback(:deploy, package)
end

#distribute(package) ⇒ Object



146
147
148
149
150
151
# File 'lib/mamiya/cli/client.rb', line 146

def distribute(package)
  params = options[:labels] ?
    {labels: Mamiya::Util::LabelMatcher.parse_string_expr(options[:labels])} : {}

  p master_post("/packages/#{application}/#{package}/distribute", params.merge(type: :json))
end

#join(host) ⇒ Object



202
203
204
# File 'lib/mamiya/cli/client.rb', line 202

def join(host)
  master_post('/join', host: host)
end

#list_agentsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mamiya/cli/client.rb', line 48

def list_agents
  params = options[:labels] ? {labels: options[:labels]} : {}
  payload = master_get("/agents", params)

  agents = payload["agents"].keys

  agents.each do |agent|
    puts "#{agent}\talive"
  end
  payload["failed_agents"].each do |agent|
    puts "#{agent}\tfailed"
  end
end

#list_applicationsObject



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

def list_applications
  puts master_get('/packages')["applications"]
end

#list_packagesObject



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

def list_packages
  puts master_get("/packages/#{application}")["packages"]
end

#prepare(package) ⇒ Object



155
156
157
158
159
160
# File 'lib/mamiya/cli/client.rb', line 155

def prepare(package)
  params = options[:labels] ?
    {labels: Mamiya::Util::LabelMatcher.parse_string_expr(options[:labels])} : {}

  p master_post("/packages/#{application}/#{package}/prepare", params.merge(type: :json))
end

#refreshObject



170
171
172
# File 'lib/mamiya/cli/client.rb', line 170

def refresh
  p master_post('/agents/refresh')
end

#rollbackObject



190
191
192
193
194
195
196
197
198
199
# File 'lib/mamiya/cli/client.rb', line 190

def rollback
  appstatus = master_get("/applications/#{application}/status", options[:labels] ? {labels: options[:labels]} : {})
  package = appstatus['common_previous_release']

  unless package
    raise 'there is no common_previous_release for specified application'
  end

  deploy_or_rollback(:rollback, package)
end

#show_agent(agent) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mamiya/cli/client.rb', line 64

def show_agent(agent)
  agent = master_get("/agents/#{agent}")

  case options[:format]
  when 'pp'
    require 'pp'
    pp agent
  when 'json'
    require 'json'
    puts agent.to_json
  when 'yaml'
    require 'yaml'
    puts agent.to_yaml
  end
end

#show_distribution(package) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/mamiya/cli/client.rb', line 85

def show_distribution(package)
  params = options[:labels] ? {labels: options[:labels]} : {}
  dist = master_get("/packages/#{application}/#{package}/distribution", params)

  case options[:format]
  when 'json'
    require 'json'
    puts dist.to_json
    return

  when 'yaml'
    require 'yaml'
    puts dist.to_yaml
    return
  end

  total = dist['distributed_count'] + dist['fetching_count'] +
    dist['queued_count'] + dist['not_distributed_count'] 

  progress = "%.1f" % ((dist['distributed_count']/total.to_f)*100)
  puts "package:         \#{application}/\#{package}\nstatus:          \#{dist['status']}\nprogress:        \#{progress}\n\ndistributed:     \#{dist['distributed_count']} agents\nfetching:        \#{dist['fetching_count']} agents\nqueued:          \#{dist['queued_count']} agents\nnot distributed: \#{dist['not_distributed_count']} agents\n  EOF\n\n  if options[:verbose]\n    puts \"\"\n    dist['distributed'].each do |name|\n      puts \"\#{name}\\tdistributed\"\n    end\n    dist['queued'].each do |name|\n      puts \"\#{name}\\tqueued\"\n    end\n    dist['not_distributed'].each do |name|\n      puts \"\#{name}\\tnot_distributed\"\n    end\n\n  end\nend\n"

#show_package(package) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mamiya/cli/client.rb', line 30

def show_package(package)
  meta = @meta =  master_get("/packages/#{application}/#{package}")

  case options[:format]
  when 'pp'
    require 'pp'
    pp meta
  when 'json'
    require 'json'
    puts meta.to_json
  when 'yaml'
    require 'yaml'
    puts meta.to_yaml
  end
end

#status(package = nil) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/mamiya/cli/client.rb', line 135

def status(package=nil)
  if package
    pkg_status package
  else
    app_status
  end
end

#switch(package) ⇒ Object



165
166
167
# File 'lib/mamiya/cli/client.rb', line 165

def switch(package)
  switch_(package, no_release: options[:no_release])
end