magellan-cli 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -7
- data/README.md +1 -1
- data/lib/magellan/cli/command.rb +3 -1
- data/lib/magellan/cli/http.rb +14 -8
- data/lib/magellan/cli/resources/base.rb +85 -3
- data/lib/magellan/cli/resources/client_version.rb +6 -1
- data/lib/magellan/cli/resources/container_assignment.rb +43 -0
- data/lib/magellan/cli/resources/container_image.rb +2 -0
- data/lib/magellan/cli/resources/container_instance.rb +8 -0
- data/lib/magellan/cli/resources/organization.rb +1 -0
- data/lib/magellan/cli/resources/project.rb +2 -0
- data/lib/magellan/cli/resources/stage.rb +2 -0
- data/lib/magellan/cli/resources/team.rb +1 -0
- data/lib/magellan/cli/resources/vm_instance.rb +55 -0
- data/lib/magellan/cli/resources/worker_version.rb +3 -0
- data/lib/magellan/cli/resources.rb +2 -1
- data/lib/magellan/cli/version.rb +1 -1
- data/magellan-cli.gemspec +1 -0
- data/spec/magellan/cli/resources/client_version_spec.rb +2 -2
- metadata +18 -3
- data/lib/magellan/cli/resources/host_instance.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c33e40274842ea373e0c3cbbcdbdc4afd66c8c6
|
4
|
+
data.tar.gz: 4960b996af7200302e22ded5a71d7c4fb28832f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa4369a0ce38eee04acea442b4d543f10f660519598c4da4a45fc6bdccf5befded5d34c5462935060fde7ab8a94424f147dd6febd063b97cc89acf7cd550c75
|
7
|
+
data.tar.gz: fbff5926ef59ee089720da957de03989ca5f4415bddd27748c58e1b740c49a66e0d5d2ff3f3bdb529c0303344a66c735f1d70e7829749a9ac7c2aeffb710b186
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
magellan-cli (0.2.
|
4
|
+
magellan-cli (0.2.1)
|
5
5
|
activesupport (~> 4.1.4)
|
6
6
|
httpclient
|
7
7
|
nokogiri
|
8
|
+
text-table (~> 1.2.3)
|
8
9
|
thor
|
9
10
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
13
|
-
activesupport (4.1.
|
14
|
+
activesupport (4.1.8)
|
14
15
|
i18n (~> 0.6, >= 0.6.9)
|
15
16
|
json (~> 1.7, >= 1.7.7)
|
16
17
|
minitest (~> 5.1)
|
@@ -18,14 +19,14 @@ GEM
|
|
18
19
|
tzinfo (~> 1.1)
|
19
20
|
coderay (1.1.0)
|
20
21
|
diff-lcs (1.2.5)
|
21
|
-
httpclient (2.
|
22
|
+
httpclient (2.5.3.3)
|
22
23
|
i18n (0.6.11)
|
23
24
|
json (1.8.1)
|
24
25
|
method_source (0.8.2)
|
25
|
-
mini_portile (0.6.
|
26
|
-
minitest (5.4.
|
27
|
-
nokogiri (1.6.
|
28
|
-
mini_portile (
|
26
|
+
mini_portile (0.6.1)
|
27
|
+
minitest (5.4.3)
|
28
|
+
nokogiri (1.6.5)
|
29
|
+
mini_portile (~> 0.6.0)
|
29
30
|
pry (0.9.12.6)
|
30
31
|
coderay (~> 1.0)
|
31
32
|
method_source (~> 0.8)
|
@@ -44,6 +45,7 @@ GEM
|
|
44
45
|
rspec-support (~> 3.0.0)
|
45
46
|
rspec-support (3.0.4)
|
46
47
|
slop (3.5.0)
|
48
|
+
text-table (1.2.3)
|
47
49
|
thor (0.19.1)
|
48
50
|
thread_safe (0.3.4)
|
49
51
|
tzinfo (1.2.2)
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ Modify Host Instance config, if you need.
|
|
62
62
|
magellan-cli host_instance show 1
|
63
63
|
```
|
64
64
|
|
65
|
-
#### 7. [cli terminal] start stage inculding
|
65
|
+
#### 7. [cli terminal] start stage inculding VmInstances and ContainerInstances
|
66
66
|
|
67
67
|
```
|
68
68
|
magellan-cli stage start 1
|
data/lib/magellan/cli/command.rb
CHANGED
@@ -16,9 +16,10 @@ module Magellan
|
|
16
16
|
"client_version" => "ClientVersion",
|
17
17
|
"tr" => "TransactionRouter",
|
18
18
|
"worker" => "WorkerVersion",
|
19
|
-
"instance" => "
|
19
|
+
"instance" => "VmInstance",
|
20
20
|
"image" => "ContainerImage",
|
21
21
|
"container" => "ContainerInstance",
|
22
|
+
"assignment" => "ContainerAssignment",
|
22
23
|
}.each do |name, classname|
|
23
24
|
desc "#{name} SUBCOMMAND ...ARGS", "manage #{name}"
|
24
25
|
subcommand name, ::Magellan::Cli::Resources.const_get(classname)
|
@@ -35,6 +36,7 @@ module Magellan
|
|
35
36
|
password = STDIN.noecho(&:gets).chomp
|
36
37
|
puts ""
|
37
38
|
update_selections("login" => {"email" => email, "password" => password})
|
39
|
+
Magellan::Cli::Http.new.login
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/magellan/cli/http.rb
CHANGED
@@ -10,9 +10,7 @@ module Magellan
|
|
10
10
|
def login
|
11
11
|
cli = Cli::Login.new
|
12
12
|
cli.login!
|
13
|
-
|
14
|
-
success("OK")
|
15
|
-
return r
|
13
|
+
return block_given? ? yield(cli) : success("OK")
|
16
14
|
end
|
17
15
|
|
18
16
|
# ログインしてGETします
|
@@ -26,8 +24,14 @@ module Magellan
|
|
26
24
|
url << '?' << params.map{|k,v| "%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)] }.join("&")
|
27
25
|
end
|
28
26
|
verbose("url: #{url}")
|
29
|
-
|
30
|
-
|
27
|
+
# "Unknown key: max-age = 0" というメッセージを表示させないために$stderrを一時的に上書き
|
28
|
+
$stderr, bak = StringIO.new, $stderr
|
29
|
+
begin
|
30
|
+
res = cli.httpclient.get(url)
|
31
|
+
return JSON.parse(res.body)
|
32
|
+
ensure
|
33
|
+
$stderr = bak
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
@@ -86,13 +90,15 @@ module Magellan
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def process_res(cli, http_method, rel_path, *args)
|
89
|
-
|
93
|
+
url = "#{cli.base_url}#{rel_path}"
|
94
|
+
verbose("%s %s\n%s" % [http_method, url, args])
|
95
|
+
res = cli.httpclient.send(http_method, url, *args)
|
90
96
|
case res.status
|
91
97
|
when 200...300 then
|
92
98
|
r = JSON.parse(res.body)
|
93
|
-
|
99
|
+
verbose(JSON.pretty_generate(r))
|
94
100
|
else
|
95
|
-
|
101
|
+
info("\e[31m[#{res.status}]\e[0m\ #{res.body}")
|
96
102
|
end
|
97
103
|
end
|
98
104
|
|
@@ -8,6 +8,8 @@ require 'active_support/core_ext/string/inflections'
|
|
8
8
|
require 'active_support/core_ext/class/attribute_accessors'
|
9
9
|
require 'active_support/core_ext/object/blank'
|
10
10
|
|
11
|
+
require 'text-table'
|
12
|
+
|
11
13
|
module Magellan
|
12
14
|
module Cli
|
13
15
|
module Resources
|
@@ -55,14 +57,91 @@ module Magellan
|
|
55
57
|
return r
|
56
58
|
end
|
57
59
|
|
60
|
+
def association_map(fields)
|
61
|
+
associations = {}
|
62
|
+
(self.class.field_associations || {}).each do |f, obj|
|
63
|
+
i = fields.index(f)
|
64
|
+
next unless i
|
65
|
+
fields[i] = obj[:name]
|
66
|
+
res = obj[:resource] || ((k = Resources.const_get(obj[:class])) ? k.resource_name : nil)
|
67
|
+
res2 = get_json("/admin/#{res}.json?compact=true")
|
68
|
+
associations[f] = res2.each_with_object({}){|r,d| d[ r["id"].to_i ] = r["label"] }
|
69
|
+
end
|
70
|
+
return associations
|
71
|
+
end
|
72
|
+
|
73
|
+
def association_get(associations, r, f)
|
74
|
+
v = r[f]
|
75
|
+
m = associations[f]
|
76
|
+
m ? m[v] || "(not found: #{v.inspect})" : v
|
77
|
+
end
|
78
|
+
|
79
|
+
DEFAULT_HIDDEN_FIELDS = %w[created_at updated_at].map(&:freeze).freeze
|
80
|
+
|
81
|
+
|
82
|
+
def query_list
|
83
|
+
get_json("/admin/#{self.class.resource_name}.json", default_query)
|
84
|
+
end
|
85
|
+
private :query_list
|
86
|
+
|
58
87
|
def list
|
59
|
-
|
60
|
-
$stdout.puts(
|
88
|
+
res1 = query_list
|
89
|
+
return $stdout.puts("Total: 0") if res1.empty?
|
90
|
+
|
91
|
+
t = Text::Table.new
|
92
|
+
original_fields =
|
93
|
+
res1.map(&:keys).flatten.uniq -
|
94
|
+
(self.class.hidden_fields || DEFAULT_HIDDEN_FIELDS) -
|
95
|
+
(self.class.multiline_fields || [])
|
96
|
+
|
97
|
+
fields = original_fields.dup
|
98
|
+
associations = association_map(fields)
|
99
|
+
|
100
|
+
t.head = fields
|
101
|
+
t.rows = []
|
102
|
+
res1.each do |r|
|
103
|
+
row = original_fields.map do |f|
|
104
|
+
association_get(associations, r, f)
|
105
|
+
end
|
106
|
+
t.rows << row
|
107
|
+
end
|
108
|
+
# $stdout.puts(JSON.pretty_generate(res1) << "\nTotal: #{res1.length}")
|
109
|
+
$stdout.puts(t.to_s << "\nTotal: #{res1.length}")
|
61
110
|
end
|
62
111
|
|
63
112
|
def show(id)
|
64
113
|
r = get_json("/admin/#{self.class.resource_name}/#{id}.json")
|
65
|
-
|
114
|
+
t = Text::Table.new
|
115
|
+
t.head = ["field", "value"]
|
116
|
+
|
117
|
+
table_fields = r.keys - (self.class.multiline_fields || [])
|
118
|
+
associations = association_map(table_fields.dup)
|
119
|
+
table_fields.each do |f|
|
120
|
+
t.rows << [f, association_get(associations, r, f)]
|
121
|
+
end
|
122
|
+
$stdout.puts t.to_s
|
123
|
+
|
124
|
+
(self.class.multiline_fields || []).each do |f|
|
125
|
+
$stdout.puts "\n"
|
126
|
+
$stdout.puts " #{f} ".center(50, "=")
|
127
|
+
v = r[f]
|
128
|
+
next unless v
|
129
|
+
|
130
|
+
case f
|
131
|
+
when /_json\Z/ then
|
132
|
+
next if v.empty?
|
133
|
+
begin
|
134
|
+
o = JSON.parse(v)
|
135
|
+
$stdout.puts(JSON.pretty_generate(o))
|
136
|
+
rescue JSON::ParserError => e
|
137
|
+
$stdout.puts "\e[33m[WARN] #{e.message}\e[0m"
|
138
|
+
$stdout.puts v
|
139
|
+
end
|
140
|
+
# when /_yaml\Z/ then
|
141
|
+
else
|
142
|
+
$stdout.puts v
|
143
|
+
end
|
144
|
+
end
|
66
145
|
end
|
67
146
|
|
68
147
|
def select(name)
|
@@ -83,6 +162,9 @@ module Magellan
|
|
83
162
|
no_commands do
|
84
163
|
cattr_accessor :resource_name
|
85
164
|
cattr_accessor :resource_dependency
|
165
|
+
cattr_accessor :field_associations
|
166
|
+
cattr_accessor :hidden_fields, :multiline_fields
|
167
|
+
|
86
168
|
def self.parameter_name
|
87
169
|
resource_name.gsub(/~/, "_")
|
88
170
|
end
|
@@ -7,7 +7,12 @@ module Magellan
|
|
7
7
|
|
8
8
|
class ClientVersion < Base
|
9
9
|
self.resource_name = "client_version"
|
10
|
-
self.resource_dependency = {"
|
10
|
+
self.resource_dependency = {"project" => "project"}
|
11
|
+
|
12
|
+
self.hidden_fields = %w[project_id created_at updated_at].map(&:freeze).freeze
|
13
|
+
self.field_associations = {
|
14
|
+
"stage_title_id" => {name: "stage", class: "Stage"},
|
15
|
+
}
|
11
16
|
|
12
17
|
desc "create VERSION", "create New Client Version"
|
13
18
|
def create(version)
|
@@ -0,0 +1,43 @@
|
|
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
|
@@ -8,6 +8,8 @@ module Magellan
|
|
8
8
|
class ContainerImage < Base
|
9
9
|
self.resource_name = "container~image"
|
10
10
|
self.resource_dependency = {"stage" => "stage-version"}
|
11
|
+
self.hidden_fields = %w[function_id function_type created_at updated_at].map(&:freeze).freeze
|
12
|
+
self.field_associations = {"stage_version_id" => {name: "stage", resource: "stage~version"} }
|
11
13
|
end
|
12
14
|
|
13
15
|
end
|
@@ -8,6 +8,14 @@ module Magellan
|
|
8
8
|
class ContainerInstance < Base
|
9
9
|
self.resource_name = "container~instance"
|
10
10
|
self.resource_dependency = {"stage" => "stage-version"}
|
11
|
+
self.hidden_fields = %w[created_at updated_at].map(&:freeze).freeze
|
12
|
+
self.multiline_fields = %w[docker_properties_json links_yaml publishings_yaml volumes_yaml env_yaml].map(&:freeze).freeze
|
13
|
+
self.field_associations = {
|
14
|
+
"stage_version_id" => {name: "stage", resource: "stage~version"},
|
15
|
+
"vm_instance_id" => {name: "instance", class: "VmInstance"},
|
16
|
+
"container_image_id" => {name: "image", class: "ContainerImage"},
|
17
|
+
# "container_assignment_id" => {name: "assignment", class: "ContainerAssignment"},
|
18
|
+
}
|
11
19
|
end
|
12
20
|
|
13
21
|
end
|
@@ -8,6 +8,8 @@ module Magellan
|
|
8
8
|
class Project < Base
|
9
9
|
self.resource_name = "project"
|
10
10
|
self.resource_dependency = nil
|
11
|
+
self.hidden_fields = %w[default_nebula_id created_at updated_at].map(&:freeze).freeze
|
12
|
+
self.field_associations = {"organization_id" => {name: "organization", class: "Organization"} }
|
11
13
|
|
12
14
|
desc "update ATTRIBUTES", "update project with ATTRIBUTES"
|
13
15
|
def update(attrs)
|
@@ -9,6 +9,8 @@ module Magellan
|
|
9
9
|
class Stage < Base
|
10
10
|
self.resource_name = "stage~title"
|
11
11
|
self.resource_dependency = {"project" => "project"}
|
12
|
+
self.hidden_fields = %w[nebula_id created_at updated_at].map(&:freeze).freeze
|
13
|
+
self.field_associations = {"project_id" => {name: "project", class: "Project"} }
|
12
14
|
|
13
15
|
desc "create NAME [-t development|staging|production|other]", "create Stage with Name and Type"
|
14
16
|
option :t, type: :string, default: "development", desc: "-t development|staging|production. specify Stage Type"
|
@@ -8,6 +8,7 @@ module Magellan
|
|
8
8
|
class Team < Base
|
9
9
|
self.resource_name = "magellan~auth~team"
|
10
10
|
self.resource_dependency = { "organization" => Organization.parameter_name }
|
11
|
+
self.field_associations = {"organization_id" => {name: "organization", class: "Organization"} }
|
11
12
|
|
12
13
|
desc "create NAME ROLE", "create Team with NAME ROLE"
|
13
14
|
def create(name, role)
|
@@ -0,0 +1,55 @@
|
|
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
|
@@ -8,6 +8,9 @@ module Magellan
|
|
8
8
|
class WorkerVersion < Base
|
9
9
|
self.resource_name = "functions~worker"
|
10
10
|
self.resource_dependency = {"stage" => "stage-version"}
|
11
|
+
self.hidden_fields = %w[created_at updated_at].map(&:freeze).freeze
|
12
|
+
self.multiline_fields = %w[migration_command_1 migration_command_2 run_command environment_vars_yaml].map(&:freeze).freeze
|
13
|
+
self.field_associations = {"stage_version_id" => {name: "stage", resource: "stage~version"} }
|
11
14
|
|
12
15
|
desc "create NAME, IMAGE", "create WorkerVersion with NAME, IMAGE"
|
13
16
|
method_option :attributes_yaml, aliases: "-A", desc: "path to YAML file which defines attributes"
|
@@ -19,10 +19,11 @@ module Magellan
|
|
19
19
|
autoload :TransactionRouter, "magellan/cli/resources/transaction_router"
|
20
20
|
autoload :WorkerVersion , "magellan/cli/resources/worker_version"
|
21
21
|
|
22
|
-
autoload :
|
22
|
+
autoload :VmInstance , "magellan/cli/resources/vm_instance"
|
23
23
|
|
24
24
|
autoload :ContainerImage , "magellan/cli/resources/container_image"
|
25
25
|
autoload :ContainerInstance, "magellan/cli/resources/container_instance"
|
26
|
+
autoload :ContainerAssignment, "magellan/cli/resources/container_assignment"
|
26
27
|
|
27
28
|
end
|
28
29
|
end
|
data/lib/magellan/cli/version.rb
CHANGED
data/magellan-cli.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "thor"
|
23
23
|
spec.add_runtime_dependency "nokogiri"
|
24
24
|
spec.add_runtime_dependency "activesupport", "~> 4.1.4"
|
25
|
+
spec.add_runtime_dependency "text-table", "~> 1.2.3"
|
25
26
|
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.6"
|
27
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -7,7 +7,7 @@ describe Magellan::Cli::Resources::ClientVersion do
|
|
7
7
|
|
8
8
|
describe :list do
|
9
9
|
before do
|
10
|
-
expect(cmd).to receive(:load_selections).and_return({"
|
10
|
+
expect(cmd).to receive(:load_selections).and_return({"project" => {"id" => 1, "name" => "ProjectA"}})
|
11
11
|
expect(cmd).to receive(:get_json).and_return([{id: 1, project_id: 1, stage_title_id: 1, version: "1.0.0", url_mapping_yaml: nil, status: "1" }])
|
12
12
|
expect($stdout).to receive(:puts)
|
13
13
|
end
|
@@ -19,7 +19,7 @@ describe Magellan::Cli::Resources::ClientVersion do
|
|
19
19
|
describe :create do
|
20
20
|
describe :success do
|
21
21
|
before do
|
22
|
-
expect(cmd).to receive(:load_selections).and_return({"stage" => {"id" => 1, "name" => "StageA"}})
|
22
|
+
expect(cmd).to receive(:load_selections).and_return({"project" => {"id" => 1, "name" => "ProjectA"}, "stage" => {"id" => 1, "name" => "StageA"} })
|
23
23
|
expect(cmd).to receive(:post_json).with("/admin/client_version/new.js", { "client_version" => { "stage_title_id" => 1, "version" => "1.1.0" } })
|
24
24
|
end
|
25
25
|
it do
|
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.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 4.1.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: text-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2.3
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,14 +151,15 @@ files:
|
|
137
151
|
- lib/magellan/cli/resources.rb
|
138
152
|
- lib/magellan/cli/resources/base.rb
|
139
153
|
- lib/magellan/cli/resources/client_version.rb
|
154
|
+
- lib/magellan/cli/resources/container_assignment.rb
|
140
155
|
- lib/magellan/cli/resources/container_image.rb
|
141
156
|
- lib/magellan/cli/resources/container_instance.rb
|
142
|
-
- lib/magellan/cli/resources/host_instance.rb
|
143
157
|
- lib/magellan/cli/resources/organization.rb
|
144
158
|
- lib/magellan/cli/resources/project.rb
|
145
159
|
- lib/magellan/cli/resources/stage.rb
|
146
160
|
- lib/magellan/cli/resources/team.rb
|
147
161
|
- lib/magellan/cli/resources/transaction_router.rb
|
162
|
+
- lib/magellan/cli/resources/vm_instance.rb
|
148
163
|
- lib/magellan/cli/resources/worker_version.rb
|
149
164
|
- lib/magellan/cli/sample_launch_options.json
|
150
165
|
- 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 HostInstance < Base
|
9
|
-
self.resource_name = "vm~instance"
|
10
|
-
self.resource_dependency = {"stage" => "stage"}
|
11
|
-
|
12
|
-
desc "list", "list instances"
|
13
|
-
def list
|
14
|
-
stage_id = load_selection("stage")["id"] rescue nil
|
15
|
-
r = ""
|
16
|
-
if stage_id
|
17
|
-
r = get_json("/admin/stage~title/#{stage_id}/instance_list.json", {})
|
18
|
-
else
|
19
|
-
r = get_json("/admin/vm~instance.json")
|
20
|
-
end
|
21
|
-
$stdout.puts(JSON.pretty_generate(r) << "\nTotal: #{r.length}")
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "create NAME [LAUNCH_OPTIONS]", "create Host Instance"
|
25
|
-
def create(name, launch_options = nil)
|
26
|
-
stage_id = load_selection("stage-version")
|
27
|
-
launch_options = JSON.parse(File.readable?(launch_options) ? File.read(launch_options) : launch_options)
|
28
|
-
|
29
|
-
params = {
|
30
|
-
"host_instance" => {
|
31
|
-
"stage_id" => stage_id,
|
32
|
-
"name" => name,
|
33
|
-
"launch_options_yaml" => YAML.dump(launch_options),
|
34
|
-
}
|
35
|
-
}
|
36
|
-
post_json("/admin/vm~instance/new.js", params)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|