pi 0.1.33 → 0.1.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module PI
2
2
  module Cli
3
- VERSION = '0.1.33'
3
+ VERSION = '0.1.34'
4
4
  end
5
5
  end
@@ -27,15 +27,6 @@ class PI::Client
27
27
 
28
28
 
29
29
  def initialize(target_url=PI::DEFAULT_TARGET, auth_token=nil)
30
- if target_url =~ /(https?:\/\/)?staging.samsungcloud.org/
31
- if /^https?/ =~ target_url
32
- target_url = target_url.split("//", 2)
33
- target_url = target_url[1]
34
- end
35
- target_url = "http://api.#{target_url}"
36
- else
37
- target_url = "http://#{target_url}" unless /^https?/ =~ target_url
38
- end
39
30
  target_url = target_url.gsub(/\/+$/, '')
40
31
  @target = target_url
41
32
  @auth_token = auth_token
@@ -55,15 +46,15 @@ class PI::Client
55
46
  rescue
56
47
  false
57
48
  end
58
-
49
+
59
50
  def raw_info
60
51
  http_get(PI::INFO_PATH)
61
52
  end
62
-
53
+
63
54
  def check_login_status
64
55
  raise AuthError unless @auth_token
65
56
  end
66
-
57
+
67
58
  def login(user, password)
68
59
  status, body, headers = json_post("#{PI::TOKEN_PATH}", {:password => password,:userName => user})
69
60
  response_info = json_parse(body)
@@ -75,15 +66,15 @@ class PI::Client
75
66
  def info
76
67
  json_get(PI::INFO_PATH)
77
68
  end
78
-
69
+
79
70
  def user_info
80
71
  json_get(PI::USER_PATH)
81
72
  end
82
-
73
+
83
74
  def github_info
84
75
  json_get("#{PI::USER_PATH}/repository/bind?type=github")
85
76
  end
86
-
77
+
87
78
  def targets
88
79
  json_get("#{PI::USER_PATH}/targets")
89
80
  end
@@ -91,93 +82,93 @@ class PI::Client
91
82
  def password(manifest={})
92
83
  status, body, headers = json_post("#{PI::USER_PATH}/password", manifest)
93
84
  end
94
-
85
+
95
86
  def github(manifest={})
96
87
  json_post("#{PI::USER_PATH}/repository/bind?type=github",manifest)
97
88
  end
98
-
89
+
99
90
  def runtimes
100
91
  json_get("#{PI::INFO_PATH}/runtimes")
101
- end
102
-
92
+ end
93
+
103
94
  def frameworks(runtime)
104
95
  json_get("#{PI::INFO_PATH}/frameworks?runtime=#{runtime}")
105
96
  end
106
-
97
+
107
98
  #####################################################
108
99
  # projects
109
100
  #####################################################
110
-
101
+
111
102
  def project_search(projectname=nil)
112
103
  json_get("#{PI::PROJECT_PATH}/search/#{projectname}")
113
104
  end
114
-
105
+
115
106
  def projects(pageNum=-1, numPerPage=-1)
116
107
  json_get("#{PI::PROJECTS_PATH}?pageNum=#{pageNum}&numPerPage=#{numPerPage}")
117
108
  end
118
-
109
+
119
110
  def project_sum
120
111
  http_get("#{PI::PROJECTS_PATH}/sum")
121
112
  end
122
-
113
+
123
114
  def create_project(name, manifest={})
124
115
  status, body, headers = json_post("#{PI::PROJECT_PATH}/", manifest)
125
116
  end
126
-
117
+
127
118
  def delete_project(projectid)
128
119
  projectid = uri_encode(projectid)
129
120
  http_delete("#{PI::PROJECT_PATH}/#{projectid}",'application/json')
130
121
  end
131
-
122
+
132
123
  def upload(manifest={})
133
124
  status, body, headers = http_post("#{PI::PROJECT_PATH}/upload", manifest)
134
125
  response_info = json_parse(body)
135
126
  end
136
-
127
+
137
128
  def delete_binary(binaryid)
138
129
  binaryid = uri_encode(binaryid)
139
130
  http_delete("#{PI::PROJECT_PATH}/binary/#{binaryid}",'application/json')
140
131
  end
141
-
132
+
142
133
  def project_events(projectid)
143
134
  projectid = uri_encode(projectid)
144
135
  json_get("#{PI::PROJECT_PATH}/events/#{projectid}")
145
136
  end
146
-
137
+
147
138
  def project_tags(projectid)
148
139
  projectid = uri_encode(projectid)
149
140
  json_get("#{PI::PROJECT_PATH}/tags/#{projectid}")
150
141
  end
151
-
142
+
152
143
  def project_commits_bytag(projectid,tag)
153
144
  projectid = uri_encode(projectid)
154
145
  tag = uri_encode(tag)
155
146
  json_get("#{PI::PROJECT_PATH}/commitinfo/#{projectid}/#{tag}")
156
147
  end
157
-
148
+
158
149
  def project_commits_bybranch(projectid,branch="master")
159
150
  projectid = uri_encode(projectid)
160
151
  branch = uri_encode(branch)
161
152
  json_get("#{PI::PROJECT_PATH}/commitinfo/branch/#{projectid}/#{branch}")
162
153
  end
163
-
154
+
164
155
  def project_binary(projectid)
165
156
  projectid = uri_encode(projectid)
166
157
  json_get("#{PI::PROJECT_PATH}/binary/list/#{projectid}")
167
158
  end
168
-
159
+
169
160
  def project_binary_existed(projectid,versionname)
170
161
  versionname = uri_encode(versionname)
171
162
  projectid = uri_encode(projectid)
172
163
  http_get("#{PI::PROJECT_PATH}/binary/existed/#{projectid}/#{versionname}")
173
164
  end
174
-
175
- def apps(projectid=0, targetname=nil, pageNum=-1, numPerPage=-1)
165
+
166
+ def apps(projectid=0, targetname=nil, pageNum=-1, numPerPage=-1)
176
167
  projectid = uri_encode(projectid)
177
168
  targetname = uri_encode(targetname)
178
169
  json_get("#{PI::PROJECT_PATH}/apps?projectId=#{projectid}&targetName=#{targetname}&pageNum=#{pageNum}&numPerPage=#{numPerPage}")
179
170
  end
180
-
171
+
181
172
  def app_sum(projectid=0, targetname=nil)
182
173
  projectid = uri_encode(projectid)
183
174
  targetname = uri_encode(targetname)
@@ -187,170 +178,170 @@ class PI::Client
187
178
  #####################################################
188
179
  # applications
189
180
  #####################################################
190
-
181
+
191
182
  def app_get_byid(appid)
192
183
  appid = uri_encode(appid)
193
184
  json_get("#{PI::APP_PATH}/#{appid}")
194
185
  end
195
-
186
+
196
187
  def app_search(targetname, appname)
197
188
  targetname = uri_encode(targetname)
198
189
  appname = uri_encode(appname)
199
190
  json_get("#{PI::APP_PATH}/search/#{targetname}/#{appname}")
200
191
  end
201
-
202
- def app_search_target_is_all(appname)
192
+
193
+ def app_search_target_is_all(appname)
203
194
  appname = uri_encode(appname)
204
195
  json_get("#{PI::PROJECT_PATH}/apps?appName=#{appname}")
205
196
  end
206
-
197
+
207
198
  def create_app(manifest={})
208
199
  status, body, headers = json_post("#{PI::APP_PATH}/", manifest)
209
200
  end
210
-
201
+
211
202
  def target_memory(targetname)
212
203
  targetname = uri_encode(targetname)
213
204
  http_get("#{PI::APP_PATH}/target/#{targetname}/memory")
214
205
  end
215
-
206
+
216
207
  def app_message(uuid)
217
208
  json_get("#{PI::APP_PATH}/message/#{uuid}")
218
209
  end
219
-
210
+
220
211
  def delete_app(appid)
221
212
  appid = uri_encode(appid)
222
213
  http_delete("#{PI::APP_PATH}/#{appid}",'application/json')
223
214
  end
224
-
215
+
225
216
  def start_app(appid)
226
217
  appid = uri_encode(appid)
227
218
  json_post("#{PI::APP_PATH}/#{appid}/start",manifest={})
228
219
  end
229
-
220
+
230
221
  def stop_app(appid, graceful)
231
222
  appid = uri_encode(appid)
232
223
  json_post("#{PI::APP_PATH}/#{appid}/stop?graceful=#{graceful}",manifest={})
233
224
  end
234
-
225
+
235
226
  def restart_app(appid, graceful)
236
227
  appid = uri_encode(appid)
237
228
  json_post("#{PI::APP_PATH}/#{appid}/restart?graceful=#{graceful}",manifest={})
238
229
  end
239
-
230
+
240
231
  def scale_app(appid, instance)
241
232
  appid = uri_encode(appid)
242
233
  instance = uri_encode(instance)
243
234
  json_post("#{PI::APP_PATH}/#{appid}/scale?instance=#{instance}", manifest={})
244
235
  end
245
-
236
+
246
237
  def update_app(appid, tag, graceful)
247
238
  tag = uri_encode(tag)
248
239
  appid = uri_encode(appid)
249
240
  json_post("#{PI::APP_PATH}/#{appid}/rollback/#{tag}?graceful=#{graceful}", manifest={})
250
241
  end
251
-
242
+
252
243
  def status(appid)
253
244
  appid = uri_encode(appid)
254
245
  json_get("#{PI::APP_PATH}/#{appid}/monitor")
255
246
  end
256
-
247
+
257
248
  def app_log(appid, filepath, instanceindex)
258
249
  filepath = uri_encode(filepath)
259
250
  appid = uri_encode(appid)
260
251
  instanceindex = uri_encode(instanceindex)
261
252
  http_get("#{PI::APP_PATH}/#{appid}/logs?filePath=#{filepath}&instanceIndex=#{instanceindex}")
262
253
  end
263
-
254
+
264
255
  def app_env(appid)
265
256
  appid = uri_encode(appid)
266
257
  json_get("#{PI::APP_PATH}/#{appid}/env/list")
267
- end
268
-
258
+ end
259
+
269
260
  def create_env(appid, manifest={})
270
261
  appid = uri_encode(appid)
271
262
  json_post("#{PI::APP_PATH}/#{appid}/env", manifest)
272
263
  end
273
-
264
+
274
265
  def delete_env(appid, env)
275
266
  env = uri_encode(env)
276
267
  appid = uri_encode(appid)
277
268
  http_delete("#{PI::APP_PATH}/#{appid}/env/#{env}",'application/json')
278
269
  end
279
-
270
+
280
271
  def env_verify(appid, name)
281
272
  name = uri_encode(name)
282
273
  appid = uri_encode(appid)
283
274
  http_get("#{PI::APP_PATH}/#{appid}/env/verify?name=#{name}")
284
275
  end
285
-
276
+
286
277
  def app_debug_info(appid)
287
278
  appid = uri_encode(appid)
288
279
  json_get("#{PI::APP_PATH}/#{appid}/instances")
289
280
  end
290
-
281
+
291
282
  #####################################################
292
283
  # services
293
284
  #####################################################
294
-
285
+
295
286
  def usable_services(appid)
296
287
  appid = uri_encode(appid)
297
288
  json_get("#{PI::APP_PATH}/#{appid}/service/usable")
298
289
  end
299
-
290
+
300
291
  def app_service(appid)
301
292
  appid = uri_encode(appid)
302
293
  json_get("#{PI::APP_PATH}/#{appid}/service/bind")
303
294
  end
304
-
295
+
305
296
  def bind_service(appid, manifest={})
306
297
  appid = uri_encode(appid)
307
298
  json_post("#{PI::APP_PATH}/#{appid}/service/bind",manifest)
308
299
  end
309
-
300
+
310
301
  def unbind_service(appid, servicename)
311
302
  appid = uri_encode(appid)
312
303
  servicename = uri_encode(servicename)
313
304
  http_delete("#{PI::APP_PATH}/#{appid}/service/unbind/#{servicename}",'application/json')
314
305
  end
315
-
306
+
316
307
  def services
317
308
  json_get("#{PI::SERVICE_PATH}/search")
318
309
  end
319
-
310
+
320
311
  def service(serviceid)
321
312
  serviceid = uri_encode(serviceid)
322
313
  json_get("#{PI::SERVICE_PATH}/#{serviceid}")
323
314
  end
324
-
315
+
325
316
  def import_service(manifest={})
326
317
  http_post("#{PI::SERVICE_PATH}/import",manifest)
327
318
  end
328
-
319
+
329
320
  def export_service(serviceid)
330
321
  serviceid = uri_encode(serviceid)
331
322
  http_get("#{PI::SERVICE_PATH}/exporturl/#{serviceid}")
332
323
  end
333
-
324
+
334
325
  def check_service(serviceid)
335
326
  serviceid = uri_encode(serviceid)
336
327
  http_get("#{PI::SERVICE_PATH}/check/#{serviceid}")
337
328
  end
338
-
329
+
339
330
  def delete_service(serviceid)
340
331
  serviceid = uri_encode(serviceid)
341
332
  http_delete("#{PI::SERVICE_PATH}/#{serviceid}", 'application/json')
342
333
  end
343
-
334
+
344
335
  def usable_service_target(serviceid)
345
336
  serviceid = uri_encode(serviceid)
346
337
  json_get("#{PI::SERVICE_PATH}/target/usable/#{serviceid}")
347
338
  end
348
-
339
+
349
340
  def service_target(serviceid)
350
341
  serviceid = uri_encode(serviceid)
351
342
  json_get("#{PI::SERVICE_PATH}/servicetarget/#{serviceid}")
352
343
  end
353
-
344
+
354
345
  def register_service(serviceid, targetname, manifest={})
355
346
  serviceid = uri_encode(serviceid)
356
347
  targetname = uri_encode(targetname)
@@ -362,82 +353,82 @@ class PI::Client
362
353
  servicetargetid = uri_encode(servicetargetid)
363
354
  http_delete("#{PI::SERVICE_PATH}/unregister/#{servicetargetid}",'application/json')
364
355
  end
365
-
356
+
366
357
  #####################################################
367
358
  # dns
368
359
  #####################################################
369
-
360
+
370
361
  def usable_dns(appid)
371
362
  appid = uri_encode(appid)
372
363
  json_get("#{PI::APP_PATH}/#{appid}/url/usable")
373
364
  end
374
-
365
+
375
366
  def app_dns(appid)
376
367
  appid = uri_encode(appid)
377
368
  json_get("#{PI::APP_PATH}/#{appid}/url/map")
378
369
  end
379
-
370
+
380
371
  def map_dns(appid, manifest={})
381
372
  appid = uri_encode(appid)
382
373
  json_post("#{PI::APP_PATH}/#{appid}/url/map", manifest)
383
374
  end
384
-
375
+
385
376
  def unmap_dns(appid, url)
386
377
  appid = uri_encode(appid)
387
378
  url = uri_encode(url)
388
379
  http_delete("#{PI::APP_PATH}/#{appid}/url/unmap/#{url}", 'application/json')
389
380
  end
390
-
381
+
391
382
  def dns
392
383
  json_get("#{PI::DNS_PATH}/search")
393
384
  end
394
-
385
+
395
386
  def create_dns(manifest={})
396
387
  json_post("#{PI::DNS_PATH}/", manifest)
397
388
  end
398
-
389
+
399
390
  def dns_zone_list
400
391
  json_get("#{PI::DNS_PATH}/dnszones")
401
392
  end
402
-
393
+
403
394
  def verify_dns(dnsname, zoneid)
404
395
  dnsname = uri_encode(dnsname)
405
396
  zoneid = uri_encode(zoneid)
406
397
  http_get("#{PI::DNS_PATH}/verify?dnsName=#{dnsname}&zoneId=#{zoneid}")
407
- end
408
-
398
+ end
399
+
409
400
  def delete_dns(dnsid)
410
401
  dnsid = uri_encode(dnsid)
411
402
  http_delete("#{PI::DNS_PATH}/#{dnsid}",'application/json')
412
403
  end
413
-
404
+
414
405
  def usable_dns_target(dnsid)
415
406
  dnsid = uri_encode(dnsid)
416
407
  json_get("#{PI::DNS_PATH}/dnstarget/#{dnsid}")
417
408
  end
418
-
409
+
419
410
  def dns_continents
420
411
  json_get("#{PI::DNS_PATH}/continents")
421
412
  end
422
-
413
+
423
414
  def dns_country(continents)
424
415
  continents = uri_encode(continents)
425
416
  json_get("#{PI::DNS_PATH}/country/#{continents}")
426
417
  end
427
-
418
+
428
419
  def register_dns(dnsid, target, manifest={})
429
420
  dnsid = uri_encode(dnsid)
430
421
  target = uri_encode(target)
431
422
  json_post("#{PI::DNS_PATH}/view/#{dnsid}/#{target}", manifest)
432
423
  end
433
-
424
+
434
425
  def deregister_dns(recordid)
435
426
  recordid = uri_encode(recordid)
436
427
  http_delete("#{PI::DNS_PATH}/record/#{recordid}",'application/json')
437
428
  end
438
-
429
+
439
430
  ######################################################
440
-
431
+
441
432
  def uri_encode(name)
442
433
  URI.encode name.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
443
434
  end