pi 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,26 +3,21 @@ require 'set'
3
3
  module PI::Cli::Command
4
4
 
5
5
  class User < Base
6
-
7
- YES_SET = Set.new(["y", "Y", "yes", "YES"])
8
6
 
9
7
  def login(url=nil)
10
8
  unless url
11
- url = ask("URL: '#{target_url}'? ")
12
- if YES_SET.member?(url)
9
+ url = ask "Attempting login to '#{target_url}'?", :default => true
10
+ if url == true
13
11
  url = "#{target_url}"
14
- else if url.empty?
15
- url =target_url
16
- else
17
- url = ask("URL: ")
18
- end
12
+ else
13
+ url = ask "Please input URL"
19
14
  end
20
- end
15
+ end
21
16
  url = "#{target_url}" if url.nil? || url.empty?
22
- eval("PI::Cli::Command::Misc").new().send("set_target", url)
17
+ eval("PI::Cli::Command::Misc").new().send("set_target", url)
23
18
  tries ||= 0
24
- user = ask("User: ")
25
- password = ask("Password: ") {|q| q.echo = '*'}
19
+ user = ask "User"
20
+ password = ask "Password", :echo => '*'
26
21
  err "Need a valid user" unless user
27
22
  err "Need a password" unless password
28
23
  login_and_save_token(user, password)
@@ -41,7 +36,7 @@ module PI::Cli::Command
41
36
  say "Successfully logged out of [#{target_url}]".green
42
37
  end
43
38
 
44
- def info
39
+ def info
45
40
  info = client.info
46
41
  return display JSON.pretty_generate(info) if @options[:json]
47
42
  display "\nName: #{info[:name]}"
@@ -83,8 +78,8 @@ module PI::Cli::Command
83
78
  def password(newpassword=nil)
84
79
  unless newpassword
85
80
  loop{
86
- newpassword = ask("New Password: ") {|q| q.echo = '*'}
87
- newpassword2 = ask("Verify Password: ") {|q| q.echo = '*'}
81
+ newpassword = ask "New Password", :echo => '*'
82
+ newpassword2 = ask "Verify Password", :echo => '*'
88
83
  if newpassword != newpassword2
89
84
  display "Passwords did not match, try again"
90
85
  newpassword =nil
@@ -99,9 +94,9 @@ module PI::Cli::Command
99
94
  end
100
95
 
101
96
  def github(name=nil)
102
- name = ask("Please input your name: ") unless name
103
- email = ask("Please input your email: ")
104
- password = ask("Please input your password: ") {|q| q.echo = '*'}
97
+ name = ask "Please input your name" unless name
98
+ email = ask "Please input your email"
99
+ password = ask "Please input your password", :echo => '*'
105
100
  manifest = {
106
101
  :name => "#{name}",
107
102
  :password => "#{password}",
data/lib/cli/runner.rb CHANGED
@@ -74,7 +74,9 @@ class PI::Cli::Runner
74
74
  def parse_command!
75
75
  # just return if already set, happends with -v, -h
76
76
  return if @namespace && @action
77
-
77
+
78
+ # @help_only = false
79
+
78
80
  verb = @args.shift
79
81
  case verb
80
82
 
@@ -123,9 +125,17 @@ class PI::Cli::Runner
123
125
  set_cmd(:misc, :version)
124
126
 
125
127
  when 'help'
126
- display_help if @args.size == 0
127
- @help_only = true
128
- parse_command!
128
+ if @args.size == 0
129
+ display_help
130
+ break
131
+ else if @args == ["help"] && @args.size == 1
132
+ usage('pi help [command]')
133
+ else
134
+ @help_only = true
135
+ parse_command!
136
+ end
137
+ end
138
+
129
139
 
130
140
  when 'options'
131
141
  @args = @args.unshift('--options')
@@ -167,6 +177,104 @@ class PI::Cli::Runner
167
177
  usage('pi project-apps [projectname]')
168
178
  set_cmd(:projects, :project_apps, @args.size == 1 ? 1 : 0)
169
179
 
180
+ ###############################################################################
181
+ # Applications
182
+ ###############################################################################
183
+
184
+ when 'apps'
185
+ usage('pi apps [projectid]')
186
+ set_cmd(:apps, :apps, @args.size == 1 ? 1 : 0)
187
+
188
+ when 'create-app'
189
+ usage('pi create-app [appname]')
190
+ set_cmd(:apps, :create_app, @args.size == 1 ? 1 : 0)
191
+
192
+ when 'delete-app'
193
+ usage('pi delete-app [appid]')
194
+ set_cmd(:apps, :delete_app, @args.size == 1 ? 1 : 0)
195
+
196
+ when 'start-app'
197
+ usage('pi start-app [appid]')
198
+ set_cmd(:apps, :start_app, @args.size == 1 ? 1 : 0)
199
+
200
+ when 'stop-app'
201
+ usage('pi stop-app [appid]')
202
+ set_cmd(:apps, :stop_app, @args.size == 1 ? 1 : 0)
203
+
204
+ when 'restart-app'
205
+ usage('pi restart-app [appid]')
206
+ set_cmd(:apps, :restart_app, @args.size == 1 ? 1 : 0)
207
+
208
+ when 'scale-app'
209
+ usage('pi scale-app [appid]')
210
+ set_cmd(:apps, :scale_app, @args.size == 1 ? 1 : 0)
211
+
212
+ when 'update-app'
213
+ usage('pi update-app [appid]')
214
+ set_cmd(:apps, :update_app, @args.size == 1 ? 1 : 0)
215
+
216
+ when 'status'
217
+ usage('pi status [appname]')
218
+ set_cmd(:apps, :status, @args.size == 1 ? 1 : 0)
219
+
220
+ when 'app-env'
221
+ usage('pi app-env [appname]')
222
+ set_cmd(:apps, :app_env, @args.size == 1 ? 1 : 0)
223
+
224
+ when 'create-env'
225
+ usage('pi create-env [appname]')
226
+ set_cmd(:apps, :create_env, @args.size == 1 ? 1 : 0)
227
+
228
+ when 'delete-env'
229
+ usage('pi delete-env [appname]')
230
+ set_cmd(:apps, :delete_env, @args.size == 1 ? 1 : 0)
231
+
232
+ when 'app-log'
233
+ usage('pi app-log [appid]')
234
+ set_cmd(:apps, :app_log, @args.size == 1 ? 1 : 0)
235
+
236
+ ###############################################################################
237
+ # Services
238
+ ###############################################################################
239
+
240
+ when 'app-service'
241
+ usage('pi app-service [appname]')
242
+ set_cmd(:services, :app_service, @args.size == 1 ? 1 : 0)
243
+
244
+ when 'bind-service'
245
+ usage('pi bind-service [appname]')
246
+ set_cmd(:services, :bind_service, @args.size == 1 ? 1 : 0)
247
+
248
+ when 'unbind-service'
249
+ usage('pi unbind-service [appname]')
250
+ set_cmd(:services, :unbind_service, @args.size == 1 ? 1 : 0)
251
+
252
+ ###############################################################################
253
+ # Dns
254
+ ###############################################################################
255
+
256
+ when 'app-dns'
257
+ usage('pi app-dns [appname]')
258
+ set_cmd(:dns, :app_dns, @args.size == 1 ? 1 : 0)
259
+
260
+ when 'map-dns'
261
+ usage('pi map-dns [appname]')
262
+ set_cmd(:dns, :map_dns, @args.size == 1 ? 1 : 0)
263
+
264
+ when 'unmap-dns'
265
+ usage('pi unmap-dns [appname]')
266
+ set_cmd(:dns, :unmap_dns, @args.size == 1 ? 1 : 0)
267
+
268
+ ###############################################################################
269
+ # Admin
270
+ ###############################################################################
271
+
272
+ when 'users'
273
+ usage('pi users')
274
+ set_cmd(:admin, :users)
275
+
276
+ ###############################################################################
277
+
170
278
  when 'usage'
171
279
  display basic_usage
172
280
  exit(true)
data/lib/cli/usage.rb CHANGED
@@ -47,6 +47,30 @@ Currently available pi commands are:
47
47
  project-commits [projectname] List the commit log for the project
48
48
  project-apps [projectname] List the applications for the project
49
49
  upload [projectname] Upload the war package for java project
50
+
51
+ Application
52
+ apps List deployed applications for the project
53
+ create-app [appname] Create a new application
54
+ delete-app [appid] Delete the application
55
+ start-app [appid] Start the application
56
+ stop-app [appid] Stop the application
57
+ restart-app [appid] Restart the application
58
+ scale-app [appid] Scale the application instances up or down
59
+ update-app [appid] Update the application
60
+ status [appname] Display resource usage for the application
61
+ app-env [appid] Display the environments for the application
62
+ create-env [appid] Create the environment for the application
63
+ delete-env [appid] Delete the environment for the application
64
+ app-log [appid] List the logs for the application
65
+
66
+ Service
67
+ app-service [appname] Display the bind services for the application
68
+ bind-service [appname] Bind a service to an application
69
+ unbind-service [appname] Unbind a service to an application
70
+ DNS
71
+ app-dns [appname] Display the mapped urls for the application
72
+ map-dns [appname] Map the url for the application
73
+ unmap-dns [appname] Unmap the url for the application
50
74
  USAGE
51
75
 
52
76
  end
data/lib/cli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module PI
2
2
  module Cli
3
- VERSION = '0.1.19'
3
+ VERSION = '0.1.20'
4
4
  end
5
5
  end
data/lib/pi/client.rb CHANGED
@@ -37,6 +37,10 @@ class PI::Client
37
37
  # Users
38
38
  #####################################################
39
39
 
40
+ def check_url
41
+ http_get
42
+ end
43
+
40
44
  def login(user, password)
41
45
  status, body, headers = json_post("#{PI::TOKEN_PATH}", {:password => password,:userName => user})
42
46
  response_info = json_parse(body)
@@ -74,7 +78,7 @@ class PI::Client
74
78
  end
75
79
 
76
80
  def frameworks(runtime)
77
- json_get("#{PI::INFO_PATH}/frameworks/#{runtime}")
81
+ json_get("#{PI::INFO_PATH}/frameworks?runtime=#{runtime}")
78
82
  end
79
83
 
80
84
  #####################################################
@@ -85,6 +89,10 @@ class PI::Client
85
89
  json_get("#{PI::PROJECT_PATH}/list")
86
90
  end
87
91
 
92
+ def project_get(projectname)
93
+ json_get("#{PI::PROJECT_PATH}/get?projectName=#{projectname}")
94
+ end
95
+
88
96
  def create_project(name, manifest={})
89
97
  status, body, headers = json_post("#{PI::PROJECT_PATH}/create", manifest)
90
98
  end
@@ -113,7 +121,144 @@ class PI::Client
113
121
  def project_apps(projectname)
114
122
  json_get("#{PI::PROJECT_PATH}/apps/#{projectname}")
115
123
  end
124
+
125
+ def project_binary(projectid)
126
+ json_get("#{PI::PROJECT_PATH}/binary/list?query=project_id%3D#{projectid}")
127
+ end
128
+
129
+ def project_branchs(projectname)
130
+ json_get("#{PI::PROJECT_PATH}/branchs/#{projectname}")
131
+ end
116
132
 
133
+ #####################################################
134
+ # applications
135
+ #####################################################
136
+
137
+ def apps(projectid, queryParam = nil)
138
+ queryParam = { :pageNum => -1, :NumPerPage => -1} unless queryParam
139
+ json_get("#{PI::APP_PATH}/list?projectId=#{projectid}&pageNum=#{queryParam[:pageNum]}&numPerPage=#{queryParam[:NumPerPage]}")
140
+ end
141
+
142
+ def app_sum(projectid)
143
+ http_get("#{PI::APP_PATH}/sum?projectId=#{projectid}")
144
+ end
145
+
146
+ def app_get_byname(appname)
147
+ json_get("#{PI::APP_PATH}/get?appName=#{appname}")
148
+ end
149
+
150
+ def app_get_byid(appid)
151
+ json_get("#{PI::APP_PATH}/get?appId=#{appid}")
152
+ end
153
+
154
+ def create_app(projectid,manifest={})
155
+ status, body, headers = json_post("#{PI::APP_PATH}/create?projectId=#{projectid}", manifest)
156
+ end
157
+
158
+ def target_memory(targetname)
159
+ http_get("#{PI::APP_PATH}/target/memory?targetName=#{targetname}")
160
+ end
161
+
162
+ def app_message(appname,message)
163
+ json_get("#{PI::APP_PATH}/message?appName=#{appname}&eventName=#{message}")
164
+ end
165
+
166
+ def delete_app(appid)
167
+ http_delete("#{PI::APP_PATH}/delete?appId=#{appid}",'application/json')
168
+ end
169
+
170
+ def start_app(appid)
171
+ json_get("#{PI::APP_PATH}/start?appId=#{appid}")
172
+ end
173
+
174
+ def stop_app(appid)
175
+ json_get("#{PI::APP_PATH}/stop?appId=#{appid}")
176
+ end
177
+
178
+ def scale_app(appid,instance)
179
+ json_get("#{PI::APP_PATH}/scale?appId=#{appid}&instance=#{instance}")
180
+ end
181
+
182
+ def update_app(appid,tag)
183
+ json_get("#{PI::APP_PATH}/rollback?appId=#{appid}&tag=#{tag}")
184
+ end
185
+
186
+ def status(appname)
187
+ json_get("#{PI::APP_PATH}/monitor?appName=#{appname}")
188
+ end
189
+
190
+ def app_env(appname)
191
+ json_get("#{PI::APP_PATH}/env/list?appName=#{appname}")
192
+ end
193
+
194
+ def create_env(appname,manifest=nil)
195
+ json_post("#{PI::APP_PATH}/env/save?appName=#{appname}",manifest)
196
+ end
197
+
198
+ def delete_env(appname,manifest=nil)
199
+ json_post("#{PI::APP_PATH}/env/delete?appName=#{appname}",manifest)
200
+ end
201
+
202
+ def env_verify(appname,name)
203
+ http_get("#{PI::APP_PATH}/env/verify?appName=#{appname}&name=#{name}")
204
+ end
205
+
206
+ def app_log(appid,filepath,instanceindex)
207
+ http_get("#{PI::APP_PATH}/logs?appId=#{appid}&filePath=#{filepath}&instanceIndex=#{instanceindex}")
208
+ end
209
+
210
+ #####################################################
211
+ # services
212
+ #####################################################
213
+
214
+ def usable_services(appname)
215
+ json_get("#{PI::APP_PATH}/service/usable?appName=#{appname}")
216
+ end
217
+
218
+ def app_service(appname)
219
+ json_get("#{PI::APP_PATH}/service/binded?appName=#{appname}")
220
+ end
221
+
222
+ def bind_service(appname, manifest=nil)
223
+ json_post("#{PI::APP_PATH}/service/bind?appName=#{appname}",manifest)
224
+ end
225
+
226
+ def unbind_service(appname, manifest=nil)
227
+ json_post("#{PI::APP_PATH}/service/unbind?appName=#{appname}",manifest)
228
+ end
229
+
230
+ #####################################################
231
+ # dns
232
+ #####################################################
233
+
234
+ def usable_dns(appname)
235
+ json_get("#{PI::APP_PATH}/url/usable?appName=#{appname}")
236
+ end
237
+
238
+ def app_dns(appname)
239
+ json_get("#{PI::APP_PATH}/url/mapped?appName=#{appname}")
240
+ end
241
+
242
+ def map_dns(appname, manifest=nil)
243
+ json_post("#{PI::APP_PATH}/url/map?appName=#{appname}",manifest)
244
+ end
245
+
246
+ def unmap_dns(appname, manifest=nil)
247
+ json_post("#{PI::APP_PATH}/url/unmap?appName=#{appname}",manifest)
248
+ end
249
+
250
+ #####################################################
251
+ # administration
252
+ #####################################################
253
+
254
+ def admin_domains
255
+ json_get("#{PI::ADMIN_PATH}/domains")
256
+ end
257
+
258
+ def admin_users(domainid)
259
+ json_get("#{PI::ADMIN_PATH}/users?query=domain_id%3D#{domainid}")
260
+ end
261
+
117
262
  ######################################################
118
263
 
119
264
  private
@@ -162,7 +307,7 @@ class PI::Client
162
307
  request(:delete, path,content_type)
163
308
  end
164
309
 
165
- def request(method, path, content_type = nil, payload = nil, headers = {})
310
+ def request(method, path, content_type = nil, payload = nil, headers = {})
166
311
  headers = headers.dup
167
312
  headers['Authentication'] = @auth_token if @auth_token
168
313
  if content_type
@@ -232,11 +377,11 @@ class PI::Client
232
377
 
233
378
  def parse_error_message(status, body)
234
379
  parsed_body = json_parse(body.to_s)
235
- if parsed_body && parsed_body[:code] && parsed_body[:description]
236
- desc = parsed_body[:description].gsub("\"","'")
237
- "Error #{parsed_body[:code]}: #{desc}"
380
+ if parsed_body && parsed_body[:errorCode] && parsed_body[:errorDescription]
381
+ desc = parsed_body[:errorDescription].gsub("\"","'")
382
+ "\nError (#{parsed_body[:errorCode]}): #{desc}"
238
383
  else
239
- "Error (HTTP #{status}): #{body}"
384
+ "\nError (HTTP #{status}): #{body}"
240
385
  end
241
386
  rescue JSON::ParserError
242
387
  if body.nil? || body.empty?
data/lib/pi/const.rb CHANGED
@@ -11,5 +11,7 @@ module PI
11
11
  TOKEN_PATH = '/token'
12
12
  PROJECT_PATH = '/project'
13
13
  USER_PATH = '/user'
14
+ APP_PATH = '/app'
15
+ ADMIN_PATH = '/admin'
14
16
 
15
17
  end