magellan-cli 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c33e40274842ea373e0c3cbbcdbdc4afd66c8c6
4
- data.tar.gz: 4960b996af7200302e22ded5a71d7c4fb28832f8
3
+ metadata.gz: afa7a868a64b02328acb0a38a2bfb053de87e49b
4
+ data.tar.gz: bcabb60c11b143ea38770f29c8067c99e52b56eb
5
5
  SHA512:
6
- metadata.gz: caa4369a0ce38eee04acea442b4d543f10f660519598c4da4a45fc6bdccf5befded5d34c5462935060fde7ab8a94424f147dd6febd063b97cc89acf7cd550c75
7
- data.tar.gz: fbff5926ef59ee089720da957de03989ca5f4415bddd27748c58e1b740c49a66e0d5d2ff3f3bdb529c0303344a66c735f1d70e7829749a9ac7c2aeffb710b186
6
+ metadata.gz: 9f0d1be5fc876158a71a669a6bb216f0ff349c55d9e5617037087b3a21c3bc6addd26fb468081a82073be2cdf88189af2d1def64d0f8c075fab4930902a19bb2
7
+ data.tar.gz: eebc2f8eb73895bee74cb42746b983e4f13efbc75dde1fe3a132a354426390bdb11bd8dde8c93d4126823e2b5d1fce9a86017e4662c50945adf867cdd709e0c3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magellan-cli (0.2.1)
4
+ magellan-cli (0.2.2)
5
5
  activesupport (~> 4.1.4)
6
6
  httpclient
7
7
  nokogiri
@@ -40,6 +40,7 @@ module Magellan
40
40
  end
41
41
 
42
42
  def error(msg)
43
+ verbose(caller.join("\n "))
43
44
  raise Cli::Error, msg
44
45
  end
45
46
  end
@@ -16,10 +16,9 @@ module Magellan
16
16
  "client_version" => "ClientVersion",
17
17
  "tr" => "TransactionRouter",
18
18
  "worker" => "WorkerVersion",
19
- "instance" => "VmInstance",
20
19
  "image" => "ContainerImage",
21
20
  "container" => "ContainerInstance",
22
- "assignment" => "ContainerAssignment",
21
+ "cloudsql" => "Cloudsql",
23
22
  }.each do |name, classname|
24
23
  desc "#{name} SUBCOMMAND ...ARGS", "manage #{name}"
25
24
  subcommand name, ::Magellan::Cli::Resources.const_get(classname)
@@ -97,8 +97,13 @@ module Magellan
97
97
  when 200...300 then
98
98
  r = JSON.parse(res.body)
99
99
  verbose(JSON.pretty_generate(r))
100
+ unless r["success"]
101
+ error(r["message"])
102
+ end
103
+ return r
100
104
  else
101
105
  info("\e[31m[#{res.status}]\e[0m\ #{res.body}")
106
+ return nil
102
107
  end
103
108
  end
104
109
 
@@ -86,6 +86,10 @@ module Magellan
86
86
 
87
87
  def list
88
88
  res1 = query_list
89
+ show_list(res1)
90
+ end
91
+
92
+ def show_list(res1)
89
93
  return $stdout.puts("Total: 0") if res1.empty?
90
94
 
91
95
  t = Text::Table.new
@@ -151,7 +155,7 @@ module Magellan
151
155
 
152
156
  def deselect
153
157
  update_selections do |s|
154
- s.delete(self.class.resource_name)
158
+ s.delete(self.class.parameter_name)
155
159
  end
156
160
  end
157
161
 
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "magellan/cli/resources"
3
+
4
+ module Magellan
5
+ module Cli
6
+ module Resources
7
+
8
+ class Cloudsql < Base
9
+ self.resource_name = "cloudsql~database"
10
+ self.resource_dependency = {"stage" => "stage"}
11
+ self.hidden_fields = %w[cloudsql_instance_id].map(&:freeze).freeze
12
+
13
+ desc "create NAME", "create new CloudSQL Database with NAME"
14
+ def create(name)
15
+ o = load_selection("stage")
16
+ params = {
17
+ parameter_name => {
18
+ "stage_title_id" => o["id"],
19
+ "name" => name,
20
+ }
21
+ }
22
+ post_json("/admin/#{resource_name}/new.js", params)
23
+ end
24
+
25
+ desc "delete ID", "delete CloudSQL Database"
26
+ def delete(id)
27
+ super("/admin/#{resource_name}/#{id}/delete.js")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -44,6 +44,14 @@ module Magellan
44
44
  update_first_result("stage-version", "/admin/stage~version.json", q, %w[id])
45
45
  end
46
46
 
47
+ desc "deselect", "deselect Stage"
48
+ def deselect
49
+ update_selections do |s|
50
+ s.delete("stage")
51
+ s.delete("stage-version")
52
+ end
53
+ end
54
+
47
55
  desc "planning", "switch to planning to build next released version"
48
56
  def planning
49
57
  switch_version(1)
@@ -66,7 +74,8 @@ module Magellan
66
74
  def prepare
67
75
  s = load_selection("stage")
68
76
  id = s["id"]
69
- post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "prepare_containers"})
77
+ r = post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "prepare_containers"})
78
+ ContainerInstance.new.show_list(r["result"])
70
79
  end
71
80
 
72
81
  desc "update ATTRIBUTES", "update stage with ATTRIBUTES"
@@ -77,10 +86,51 @@ module Magellan
77
86
  end
78
87
 
79
88
  desc "release_now", "release changes now"
89
+ option :A, type: :boolean, default: false, desc: "-A async mode. release_now returns soon"
90
+ option :i, type: :numeric, default: 10, desc: "-i polling interval(seconds)"
91
+ option :t, type: :numeric, default: 600, desc: "-t timeout(seconds)"
80
92
  def release_now
93
+ spacer = "\r" << (" " * 20)
94
+ print "\rrelease starting"
81
95
  s = load_selection("stage")
82
96
  id = s["id"]
83
- post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "release_now"})
97
+ res0 = post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "release_now"})
98
+ res1 = res0["result"]
99
+ if res1
100
+ print spacer
101
+ print "\rnow #{res1['status']}"
102
+ else
103
+ print spacer
104
+ puts "\e[31m#{res0.inspect}\e[0m"
105
+ raise res0["message"]
106
+ end
107
+
108
+ return res1 if options["A"]
109
+ res2 = get_json("/admin/release~operation.json", build_query("release_job" => res1["id"]))
110
+ ope = res2.first
111
+ ope_id = ope["id"]
112
+ i = options["i"]
113
+ Timeout.timeout(options["t"]) do
114
+ loop do
115
+ sleep(i)
116
+ res3 = get_json("/admin/release~job/#{ope_id}.json", default_query)
117
+ st = res3["status"]
118
+ unless res1["status"] == st
119
+ case st
120
+ when "executing" then
121
+ res4 = get_json("/admin/release~transaction.json", build_query("release_operation" => ope_id))
122
+ total = res4.length
123
+ complete = res4.select{ |r| r["status"] == "completed" }.length
124
+ print spacer
125
+ print "\rProgress: %2d /%2d" % [complete, total]
126
+ when "completed", "aborted" then
127
+ print spacer
128
+ puts "\r#{st}"
129
+ return
130
+ end
131
+ end
132
+ end
133
+ end
84
134
  end
85
135
 
86
136
  desc "logs", "fetch worker logs"
@@ -94,6 +144,14 @@ module Magellan
94
144
  end
95
145
  end
96
146
  end
147
+
148
+ desc "set_container_num NUM", "set container numbers for selected stage and image"
149
+ def set_container_num(num)
150
+ s = load_selection("stage")
151
+ v = load_selection("stage-version")
152
+ i = load_selection("container_image")
153
+ post_json("/admin/stage~version/#{v["id"]}/set_container_num.json", { container_num: num, container_image_id: i["id"] })
154
+ end
97
155
  end
98
156
 
99
157
  end
@@ -25,6 +25,7 @@ module Magellan
25
25
  autoload :ContainerInstance, "magellan/cli/resources/container_instance"
26
26
  autoload :ContainerAssignment, "magellan/cli/resources/container_assignment"
27
27
 
28
+ autoload :Cloudsql, "magellan/cli/resources/cloudsql"
28
29
  end
29
30
  end
30
31
  end
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Cli
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm2000
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -151,7 +151,7 @@ files:
151
151
  - lib/magellan/cli/resources.rb
152
152
  - lib/magellan/cli/resources/base.rb
153
153
  - lib/magellan/cli/resources/client_version.rb
154
- - lib/magellan/cli/resources/container_assignment.rb
154
+ - lib/magellan/cli/resources/cloudsql.rb
155
155
  - lib/magellan/cli/resources/container_image.rb
156
156
  - lib/magellan/cli/resources/container_instance.rb
157
157
  - lib/magellan/cli/resources/organization.rb
@@ -159,7 +159,6 @@ files:
159
159
  - lib/magellan/cli/resources/stage.rb
160
160
  - lib/magellan/cli/resources/team.rb
161
161
  - lib/magellan/cli/resources/transaction_router.rb
162
- - lib/magellan/cli/resources/vm_instance.rb
163
162
  - lib/magellan/cli/resources/worker_version.rb
164
163
  - lib/magellan/cli/sample_launch_options.json
165
164
  - lib/magellan/cli/ssl.rb
@@ -1,43 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "magellan/cli/resources"
3
-
4
- module Magellan
5
- module Cli
6
- module Resources
7
-
8
- class ContainerAssignment < Base
9
- self.resource_name = "container~assignment"
10
- self.resource_dependency = {"stage" => "stage-version"}
11
-
12
- self.field_associations = {
13
- "stage_version_id" => {name: "stage", resource: "stage~version"},
14
- "vm_instance_id" => {name: "instance", class: "VmInstance"},
15
- "container_image_id" => {name: "image", class: "ContainerImage"},
16
- }
17
-
18
- desc "create AMOUNT", "create assignment"
19
- def create(amount)
20
- img = load_selection("container_image")
21
- instance = load_selection("vm_instance")
22
- stage_version = load_selection("stage-version")
23
- params = {
24
- "container_assignment" => {
25
- "stage_version_id" => stage_version["id"],
26
- "vm_instance_id" => instance["id"],
27
- "container_image_id" => img["id"],
28
- "amount" => amount.to_i,
29
- }
30
- }
31
- post_json("/admin/#{self.resource_name}/new.js", params)
32
- end
33
-
34
- desc "delete ID", "delete assignment"
35
- def delete(id)
36
- super "/admin/#{self.resource_name}/#{id}/delete"
37
- end
38
-
39
- end
40
-
41
- end
42
- end
43
- end
@@ -1,55 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "magellan/cli/resources"
3
-
4
- module Magellan
5
- module Cli
6
- module Resources
7
-
8
- class VmInstance < Base
9
- self.resource_name = "vm~instance"
10
- self.resource_dependency = {"stage" => "stage"}
11
-
12
- self.multiline_fields = %w[additional_disks_yaml].map(&:freeze).freeze
13
-
14
- no_commands do
15
- def query_list
16
- stage_id = load_selection("stage")["id"] rescue nil
17
- if stage_id
18
- get_json("/admin/stage~title/#{stage_id}/instance_list.json", {})
19
- else
20
- get_json("/admin/vm~instance.json")
21
- end
22
- end
23
- private :query_list
24
- end
25
-
26
- def select(name)
27
- q = build_query("name" => name)
28
- update_first_result(self.class.parameter_name, "/admin/#{self.class.resource_name}.json", q)
29
- end
30
-
31
- desc "sample_launch_options", "dump sample launch_options for create"
32
- def sample_launch_options
33
- $stdout.puts File.read(File.expand_path("../sample_launch_options.json", __FILE__))
34
- end
35
-
36
- desc "create NAME [LAUNCH_OPTIONS]", "create Instance"
37
- def create(name, launch_options = nil)
38
- stage_id = load_selection("stage-version")
39
- launch_options = JSON.parse(File.readable?(launch_options) ? File.read(launch_options) : launch_options)
40
-
41
- params = {
42
- "host_instance" => {
43
- "stage_id" => stage_id,
44
- "name" => name,
45
- "launch_options_yaml" => YAML.dump(launch_options),
46
- }
47
- }
48
- post_json("/admin/vm~instance/new.js", params)
49
- end
50
-
51
- end
52
-
53
- end
54
- end
55
- end