pi 0.1.33 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  module PI::Cli::Command
2
2
  class Services < Base
3
- include PI::Cli::ChooseHelper
4
- include PI::Cli::InteractHelper
5
-
3
+ include PI::Cli::ChooseHelper
4
+ include PI::Cli::InteractHelper
5
+
6
6
  def app_service(appid_or_appname=nil)
7
7
  all_opts = total_opts
8
8
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
@@ -23,8 +23,8 @@ module PI::Cli::Command
23
23
  end
24
24
  end
25
25
  display services_table
26
- end
27
-
26
+ end
27
+
28
28
  def bind_service(appid_or_appname=nil)
29
29
  all_opts = total_opts
30
30
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|service)/i}
@@ -37,7 +37,7 @@ module PI::Cli::Command
37
37
  appid = (appid == nil ? app[:id] : appid)
38
38
  services = client.usable_services(appid)
39
39
  err "No usable services!" if services.nil? || services.empty?
40
-
40
+
41
41
  if service
42
42
  servicenames = services.collect { |s| s[:name] }
43
43
  err "Invalid service name" unless servicenames.include?(service)
@@ -49,24 +49,24 @@ module PI::Cli::Command
49
49
  else
50
50
  manifest = asks "Select services, indexed list?", :choices => services.collect { |s| s[:name] }, :indexed => true
51
51
  end
52
- # graceful = get_graceful(app)
53
- # lazy = get_lazy(app)
52
+ # graceful = get_graceful(app)
53
+ # lazy = get_lazy(app)
54
54
  display "Binding service: ",false
55
-
56
- t = Thread.new do
55
+
56
+ t = Thread.new do
57
57
  loop do
58
- display '.', false
58
+ display '.', false
59
59
  sleep (1)
60
60
  break unless t.alive?
61
61
  end
62
62
  end
63
-
63
+
64
64
  tmp = client.bind_service(appid, manifest)
65
65
  uuid = tmp[1]
66
66
  result = check_status(uuid)
67
67
  Thread.kill(t)
68
- end
69
-
68
+ end
69
+
70
70
  def unbind_service(appid_or_appname=nil)
71
71
  all_opts = total_opts
72
72
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|service)/i}
@@ -78,19 +78,19 @@ module PI::Cli::Command
78
78
  app, appid = choose_app_help_target_not_all(appid_or_appname)
79
79
  appid = (appid == nil ? app[:id] : appid)
80
80
  services = client.app_service(appid)
81
- err "No binded services!" if services.nil? || services.empty?
82
- if service
81
+ err "No binded services!" if services.nil? || services.empty?
82
+ if service
83
83
  services = service.split(",")
84
84
  else
85
85
  services = asks "Select Service", :choices => services.collect { |s| s[:name] }, :indexed => true
86
86
  end
87
- # graceful = get_graceful(app)
88
- # lazy = get_lazy(app)
87
+ # graceful = get_graceful(app)
88
+ # lazy = get_lazy(app)
89
89
  services.each do |service|
90
90
  do_unbind_service(app, service)
91
- end
91
+ end
92
92
  end
93
-
93
+
94
94
  def services
95
95
  all_opts = total_opts
96
96
  all_opts.each_value do |value|
@@ -98,7 +98,7 @@ module PI::Cli::Command
98
98
  end
99
99
  client.check_login_status
100
100
  services = client.services
101
- return display "No Services" if services.nil? || services.empty?
101
+ return display "No Services" if services.nil? || services.empty?
102
102
  return display JSON.pretty_generate(services) if @options[:json]
103
103
  services.sort! {|a, b| a[:name] <=> b[:name] }
104
104
  services_table = table do |t|
@@ -109,30 +109,30 @@ module PI::Cli::Command
109
109
  end
110
110
  display services_table
111
111
  end
112
-
113
- def service(serviceid=nil)
112
+
113
+ def service(serviceid=nil)
114
114
  all_opts = total_opts
115
115
  all_opts.each_value do |value|
116
116
  err "Invalid options" if value != nil
117
- end
117
+ end
118
118
  client.check_login_status
119
119
  if serviceid
120
120
  services = client.services
121
- err "No services" if services.nil? || services.empty?
121
+ err "No services" if services.nil? || services.empty?
122
122
  serviceid_flag = false
123
123
  services.each do |s|
124
124
  serviceid_flag = true if s[:id].to_s == serviceid
125
125
  end
126
126
  err"The service is not exist!" if serviceid_flag != true
127
- else
127
+ else
128
128
  serviceid = choose_serviceid
129
129
  end
130
130
  service = client.service(serviceid)
131
- return display "No Services" if service.nil? || service.empty?
131
+ return display "No Services" if service.nil? || service.empty?
132
132
  return display JSON.pretty_generate(service) if @options[:json]
133
133
  display service[:new_data]
134
134
  end
135
-
135
+
136
136
  def import_service(importurl=nil)
137
137
  all_opts = total_opts
138
138
  all_opts.each_value do |value|
@@ -140,10 +140,10 @@ module PI::Cli::Command
140
140
  end
141
141
  client.check_login_status
142
142
  importurl = ask"Input the url to import" unless importurl
143
- client.import_service(importurl)
144
- display"OK".green
143
+ client.import_service(importurl)
144
+ display"OK".green
145
145
  end
146
-
146
+
147
147
  def export_service(serviceid=nil)
148
148
  all_opts = total_opts
149
149
  all_opts.each_value do |value|
@@ -153,11 +153,11 @@ module PI::Cli::Command
153
153
  unless serviceid
154
154
  serviceid = choose_serviceid
155
155
  end
156
- serviceurl = client.export_service(serviceid)
157
- display "The exported URL of service:"
158
- display "#{serviceurl[1]}"
156
+ serviceurl = client.export_service(serviceid)
157
+ display "The exported URL of service:"
158
+ display "#{serviceurl[1]}"
159
159
  end
160
-
160
+
161
161
  def check_service(serviceid=nil)
162
162
  all_opts = total_opts
163
163
  all_opts.each_value do |value|
@@ -167,14 +167,14 @@ module PI::Cli::Command
167
167
  unless serviceid
168
168
  serviceid = choose_serviceid
169
169
  end
170
- check = client.check_service(serviceid)
171
- if check[1] == "true"
172
- display "Service is available."
170
+ check = client.check_service(serviceid)
171
+ if check[1] == "true"
172
+ display "Service is available."
173
173
  else
174
174
  display "Service is unavailable."
175
- end
175
+ end
176
176
  end
177
-
177
+
178
178
  def delete_service(serviceid=nil)
179
179
  all_opts = total_opts
180
180
  all_opts.each_value do |value|
@@ -185,9 +185,9 @@ module PI::Cli::Command
185
185
  serviceid = choose_serviceid
186
186
  end
187
187
  client.delete_service(serviceid)
188
- display"OK".green
188
+ display"OK".green
189
189
  end
190
-
190
+
191
191
  def register_service(serviceid=nil)
192
192
  all_opts = total_opts
193
193
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|type)/i}
@@ -202,15 +202,15 @@ module PI::Cli::Command
202
202
  # end
203
203
  if serviceid
204
204
  services = client.services
205
- err "No services" if services.nil? || services.empty?
205
+ err "No services" if services.nil? || services.empty?
206
206
  serviceid_flag = false
207
207
  services.each do |s|
208
208
  serviceid_flag = true if s[:id].to_s == serviceid
209
209
  end
210
210
  err"The service is not exist!" if serviceid_flag != true
211
- else
211
+ else
212
212
  serviceid = choose_serviceid
213
- end
213
+ end
214
214
  targets = client.usable_service_target(serviceid)
215
215
  err "No targets" if targets.nil? || targets.empty?
216
216
  if target
@@ -221,11 +221,11 @@ module PI::Cli::Command
221
221
  err"Invalid target name" if target_flag != true
222
222
  else
223
223
  target = ask"Select target", :choices => targets.collect { |t| t[:name] }, :indexed => true
224
- end
224
+ end
225
225
  # unless servicetype
226
226
  # choices = ["App Service", "Session Service"]
227
227
  # servicetype = ask"Select service type", :choices => choices, :indexed => true
228
- # if servicetype == "App Service"
228
+ # if servicetype == "App Service"
229
229
  # servicetype = 1
230
230
  # else
231
231
  # servicetype = 2
@@ -235,7 +235,7 @@ module PI::Cli::Command
235
235
  client.register_service(serviceid, target)
236
236
  display "OK".green
237
237
  end
238
-
238
+
239
239
  def deregister_service(serviceid=nil)
240
240
  all_opts = total_opts
241
241
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
@@ -247,7 +247,7 @@ module PI::Cli::Command
247
247
  unless serviceid
248
248
  serviceid = choose_serviceid
249
249
  end
250
- service_target = client.service_target(serviceid)
250
+ service_target = client.service_target(serviceid)
251
251
  err"No target available to deregister" if service_target.nil? || service_target.empty?
252
252
  unless servicetargetname
253
253
  servicetargetname = ask"Select target", :choices => service_target.collect { |t| t[:targetName] }, :indexed => true
@@ -260,23 +260,23 @@ module PI::Cli::Command
260
260
  client.deregister_service(servicetargetid)
261
261
  display "OK".green
262
262
  end
263
-
263
+
264
264
  private
265
-
265
+
266
266
  def do_unbind_service(app, service)
267
- display "Unbinding service '#{service}': ",false
268
- t = Thread.new do
267
+ display "Unbinding service '#{service}': ",false
268
+ t = Thread.new do
269
269
  loop do
270
- display '.', false
270
+ display '.', false
271
271
  sleep (1)
272
272
  break unless t.alive?
273
273
  end
274
- end
274
+ end
275
275
  tmp = client.unbind_service(app[:id], service)
276
276
  uuid = tmp[1]
277
277
  result = check_status(uuid)
278
278
  Thread.kill(t)
279
279
  end
280
-
280
+
281
281
  end
282
282
  end
@@ -4,9 +4,9 @@ module PI::Cli::Command
4
4
 
5
5
  class User < Base
6
6
  include PI::Cli::ChooseHelper
7
- YES_SET = Set.new(["y", "Y", "yes", "YES"])
7
+ YES_SET = Set.new(["y", "Y", "yes", "YES"])
8
8
  NO_SET = Set.new(["n", "N", "no", "NO"])
9
-
9
+
10
10
  def login(url=nil)
11
11
  user = @options[:user]
12
12
  password = @options[:password]
@@ -16,24 +16,20 @@ module PI::Cli::Command
16
16
  err "Invalid options" if value != nil
17
17
  end
18
18
  unless url
19
- url = ask "Attempting login to '#{target_url}'?", :default => true
20
- if url == true
21
- url = "#{target_url}"
22
- else
23
- url = ask "Please input URL"
24
- end
25
- end
19
+ env_choices = ["www", "staging", "qa"]
20
+ url = ask "Select CloudPi Environment", :choices => env_choices, :indexed => true, :default => "www"
21
+ end
26
22
  url = "#{target_url}" if url.nil? || url.empty?
27
23
  eval("PI::Cli::Command::Misc").new().send("set_target", url)
28
- unless client.target_valid?
24
+ unless client.target_valid?
29
25
  display "Host is not available or is not valid: '#{url}'".red
30
- display "\n<<<\n#{client.raw_info}\n>>>\n"
31
- exit(false)
26
+ display "\n<<<\n#{client.raw_info}\n>>>\n"
27
+ exit(false)
32
28
  end
33
-
29
+
34
30
  tries ||= 0
35
31
  user = ask "User" unless user
36
- password = ask "Password", :echo => '*' unless password
32
+ password = ask "Password", :echo => '*' unless password
37
33
  login_and_save_token(user, password)
38
34
  say "Successfully logged into [#{target_url}]".green
39
35
  rescue PI::Client::TargetError
@@ -44,7 +40,7 @@ module PI::Cli::Command
44
40
  display "Problem with login, #{e}, try again.".red
45
41
  exit 1
46
42
  end
47
-
43
+
48
44
  def logout
49
45
  all_opts = total_opts
50
46
  all_opts.each_value do |value|
@@ -54,7 +50,7 @@ module PI::Cli::Command
54
50
  say "Successfully logged out of [#{target_url}]".green
55
51
  end
56
52
 
57
- def info
53
+ def info
58
54
  all_opts = total_opts
59
55
  all_opts.each_value do |value|
60
56
  err "Invalid options" if value != nil
@@ -64,9 +60,9 @@ module PI::Cli::Command
64
60
  display "\nName: #{info[:name]}"
65
61
  display "Description: #{info[:description]}"
66
62
  display "Build: #{info[:build]}"
67
- display "Version: #{info[:version]}"
63
+ display "Version: #{info[:version]}"
68
64
  end
69
-
65
+
70
66
  def user
71
67
  all_opts = total_opts
72
68
  all_opts.each_value do |value|
@@ -80,9 +76,9 @@ module PI::Cli::Command
80
76
  github_info[:name] = "null"
81
77
  github_info[:email] = "null"
82
78
  end
83
- user_merge =user.merge(github_info)
79
+ user_merge =user.merge(github_info)
84
80
  return display JSON.pretty_generate(user_merge) if @options[:json]
85
- return display 'No user info' if user.empty?
81
+ return display 'No user info' if user.empty?
86
82
  display "\nUserName: #{user[:userName]}"
87
83
  display "DomainName: #{user[:domainName]}"
88
84
  display "RoleName: #{user[:roleName]}"
@@ -90,7 +86,7 @@ module PI::Cli::Command
90
86
  display "Github Account Name: #{github_info[:name]}"
91
87
  display "Github Account Email: #{github_info[:email]}"
92
88
  end
93
-
89
+
94
90
  def targets
95
91
  all_opts = total_opts
96
92
  all_opts.each_value do |value|
@@ -102,7 +98,7 @@ module PI::Cli::Command
102
98
  return display 'No Targets' if targets.empty?
103
99
  targets_table = table do |t|
104
100
  t.headings = 'Name', 'URL'
105
- targets.each do |target|
101
+ targets.each do |target|
106
102
  t << [target[:name], target[:targetUrl]]
107
103
  end
108
104
  end
@@ -110,13 +106,13 @@ module PI::Cli::Command
110
106
  display targets_table
111
107
  end
112
108
 
113
- def password(oldpassword=nil)
109
+ def password(oldpassword=nil)
114
110
  all_opts = total_opts
115
111
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(password)/i}
116
112
  all_opts_except_valid_opts.each_value do |value|
117
113
  err "Invalid options" if value != nil
118
- end
119
- client.check_login_status
114
+ end
115
+ client.check_login_status
120
116
  newpassword = @options[:password]
121
117
  oldpassword = ask "Old Password", :echo => '*' unless oldpassword
122
118
  unless newpassword
@@ -124,13 +120,13 @@ module PI::Cli::Command
124
120
  newpassword = ask "New Password", :echo => '*'
125
121
  newpassword2 = ask "Verify Password", :echo => '*'
126
122
  if newpassword != newpassword2
127
- display "Passwords did not match, try again"
128
- newpassword =nil
123
+ display "Passwords did not match, try again"
124
+ newpassword =nil
129
125
  next
130
- else
126
+ else
131
127
  break
132
128
  end
133
- }
129
+ }
134
130
  end
135
131
  err "New password is same with old one. Don't need to change password." if oldpassword == newpassword
136
132
  manifest = {
@@ -140,16 +136,16 @@ module PI::Cli::Command
140
136
  client.password(manifest)
141
137
  display "ok".green
142
138
  end
143
-
139
+
144
140
  def github(name=nil)
145
141
  all_opts = total_opts
146
142
  all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(email|password)/i}
147
143
  all_opts_except_valid_opts.each_value do |value|
148
144
  err "Invalid options" if value != nil
149
- end
145
+ end
150
146
  client.check_login_status
151
147
  email = @options[:email]
152
- password = @options[:password]
148
+ password = @options[:password]
153
149
  name = ask "Please input your name" unless name
154
150
  email = ask "Please input your email" unless email
155
151
  password = ask "Please input your password", :echo => '*' unless password
@@ -162,7 +158,7 @@ module PI::Cli::Command
162
158
  github = client.github(manifest)
163
159
  display "ok".green
164
160
  end
165
-
161
+
166
162
  def runtimes
167
163
  all_opts = total_opts
168
164
  all_opts.each_value do |value|
@@ -211,13 +211,13 @@ module PI::Cli
211
211
  #add
212
212
  # elsif choices and ans =~ /^\s*(\d+,)*\d+\s*$/ and \
213
213
  elsif choices and ans =~ /^\s*(\d+,)+\d+\s*$/ and \
214
- ans.to_i - 1 >= 0
215
- ans = ans.split(",")
214
+ ans.to_i - 1 >= 0
215
+ ans = ans.split(",")
216
216
  ans_uniq = ans.uniq
217
217
  unless ans_uniq == ans
218
- puts "Numbers repeat, please try again!"
218
+ puts "Numbers repeat, please try again!"
219
219
  return [false, nil]
220
- end
220
+ end
221
221
  res = Array.new
222
222
  ans.each do |a|
223
223
  if a.to_i - 1 < choices.to_a.size
@@ -226,10 +226,10 @@ module PI::Cli
226
226
  puts "Unknown answer, please try again!"
227
227
  return [false, nil]
228
228
  end
229
- end
229
+ end
230
230
  # res = ["rails.samsungpaas.comrailstest.samsungpaas.com"]
231
- [true, res]
232
- #add
231
+ [true, res]
232
+ #add
233
233
  elsif matches.size == 1
234
234
  [true, matches.first]
235
235
  elsif matches.size > 1
@@ -245,7 +245,7 @@ module PI::Cli
245
245
  puts "Please disambiguate: #{matches_list}?"
246
246
  [false, nil]
247
247
  end
248
-
248
+
249
249
  else
250
250
  puts "Unknown answer, please try again!"
251
251
  [false, nil]
@@ -550,6 +550,6 @@ module PI::Cli
550
550
  end
551
551
  end
552
552
  end
553
-
553
+
554
554
  end
555
555
  end