magellan-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +22 -0
- data/README.md +109 -0
- data/Rakefile +7 -0
- data/bin/magellan-cli +13 -0
- data/launch_options.json +7 -0
- data/lib/magellan/cli/base.rb +50 -0
- data/lib/magellan/cli/command.rb +29 -0
- data/lib/magellan/cli/direct.rb +32 -0
- data/lib/magellan/cli/errors.rb +14 -0
- data/lib/magellan/cli/http.rb +103 -0
- data/lib/magellan/cli/login.rb +134 -0
- data/lib/magellan/cli/resources/base.rb +136 -0
- data/lib/magellan/cli/resources/client_version.rb +15 -0
- data/lib/magellan/cli/resources/container_image.rb +13 -0
- data/lib/magellan/cli/resources/container_instance.rb +25 -0
- data/lib/magellan/cli/resources/function_unit.rb +27 -0
- data/lib/magellan/cli/resources/host_instance.rb +56 -0
- data/lib/magellan/cli/resources/project.rb +22 -0
- data/lib/magellan/cli/resources/stage.rb +69 -0
- data/lib/magellan/cli/resources/worker_version.rb +41 -0
- data/lib/magellan/cli/resources.rb +27 -0
- data/lib/magellan/cli/sample_launch_options.json +7 -0
- data/lib/magellan/cli/ssl.rb +35 -0
- data/lib/magellan/cli/version.rb +5 -0
- data/lib/magellan/cli.rb +23 -0
- data/magellan-cli.gemspec +29 -0
- data/spec/magellan/cli/Magellan.yml +29 -0
- data/spec/magellan/cli/login_page.html +42 -0
- data/spec/magellan/cli/login_spec.rb +46 -0
- data/spec/magellan/cli/resources/project_spec.rb +39 -0
- data/spec/magellan/cli_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fe639545cc422de3632c16deacd1a9081fe0a37d
|
4
|
+
data.tar.gz: 022da8e08cc29ac43e162c433439f378b5d3cee8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74b31f9bb8ae7f7ddee9c63090bc153178766ed0b31347b23c6c23ae5c37f6b05576137dd05fdf7eb28f6f91321432f0b58ced2c0f61f753d89b0be1e9d9da67
|
7
|
+
data.tar.gz: 7a78d27190c4284673231bb57b049b9f598300232c03b1bcb2303697e1ba448f4e099e7fc5248581c30dd83d74250cc6b6d831cfc7247c850cd36a3dddb76770
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
magellan-cli (0.1.0)
|
5
|
+
activesupport (~> 4.1.4)
|
6
|
+
httpclient
|
7
|
+
nokogiri
|
8
|
+
thor
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.1.6)
|
14
|
+
i18n (~> 0.6, >= 0.6.9)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
coderay (1.1.0)
|
20
|
+
diff-lcs (1.2.5)
|
21
|
+
httpclient (2.4.0)
|
22
|
+
i18n (0.6.11)
|
23
|
+
json (1.8.1)
|
24
|
+
method_source (0.8.2)
|
25
|
+
mini_portile (0.6.0)
|
26
|
+
minitest (5.4.2)
|
27
|
+
nokogiri (1.6.3.1)
|
28
|
+
mini_portile (= 0.6.0)
|
29
|
+
pry (0.9.12.6)
|
30
|
+
coderay (~> 1.0)
|
31
|
+
method_source (~> 0.8)
|
32
|
+
slop (~> 3.4)
|
33
|
+
rake (10.3.2)
|
34
|
+
rspec (3.0.0)
|
35
|
+
rspec-core (~> 3.0.0)
|
36
|
+
rspec-expectations (~> 3.0.0)
|
37
|
+
rspec-mocks (~> 3.0.0)
|
38
|
+
rspec-core (3.0.4)
|
39
|
+
rspec-support (~> 3.0.0)
|
40
|
+
rspec-expectations (3.0.4)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.0.0)
|
43
|
+
rspec-mocks (3.0.4)
|
44
|
+
rspec-support (~> 3.0.0)
|
45
|
+
rspec-support (3.0.4)
|
46
|
+
slop (3.5.0)
|
47
|
+
thor (0.19.1)
|
48
|
+
thread_safe (0.3.4)
|
49
|
+
tzinfo (1.2.2)
|
50
|
+
thread_safe (~> 0.1)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 1.6)
|
57
|
+
magellan-cli!
|
58
|
+
pry
|
59
|
+
rake (~> 10.0)
|
60
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 akima
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Magellan::Cli
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'magellan-cli'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install magellan-cli
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### All-in-one patterns
|
24
|
+
|
25
|
+
#### 1. [API Server terminal] initialize Database
|
26
|
+
|
27
|
+
```
|
28
|
+
bundle exec rake db:drop db:create db:migrate db:seed
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
#### 2. [API Server terminal] start API server and delayed_job daemon
|
33
|
+
|
34
|
+
```
|
35
|
+
bundle exec bin/delayed_job start
|
36
|
+
bundle exec bin/delayed_job status
|
37
|
+
bundle exec rails s
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
#### 3. [cli terminal] Load Magellan.yml
|
42
|
+
|
43
|
+
```
|
44
|
+
magellan-cli project load 1 path/to/Magellan.yml
|
45
|
+
```
|
46
|
+
|
47
|
+
#### 4. [cli terminal] create and configure Host Instance
|
48
|
+
|
49
|
+
```
|
50
|
+
magellan-cli host_instance sample_launch_options > launch_options.json
|
51
|
+
magellan-cli host_instance create 1 gce magellan-gce-sandbox1 launch_options.json
|
52
|
+
magellan-cli stage configure 1
|
53
|
+
```
|
54
|
+
|
55
|
+
#### 5. [API Server terminal]
|
56
|
+
|
57
|
+
Modify Host Instance config, if you need.
|
58
|
+
|
59
|
+
#### 6. [cli terminal] confirm Host Instance data
|
60
|
+
|
61
|
+
```
|
62
|
+
magellan-cli host_instance show 1
|
63
|
+
```
|
64
|
+
|
65
|
+
#### 7. [cli terminal] start stage inculding HostInstances and ContainerInstances
|
66
|
+
|
67
|
+
```
|
68
|
+
magellan-cli stage start 1
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
#### 8. [cli terminal] wait for stage working
|
73
|
+
|
74
|
+
check status of stage, host_instance and container_instance
|
75
|
+
|
76
|
+
```
|
77
|
+
magellan-cli stage list
|
78
|
+
magellan-cli host_instance list
|
79
|
+
magellan-cli container_instance list
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
#### 9. [cli terminal] connection check
|
84
|
+
|
85
|
+
```
|
86
|
+
irb
|
87
|
+
|
88
|
+
require 'json'
|
89
|
+
host_ip = JSON.parse(`magellan-cli host_instance show 1`)["public_ip"]
|
90
|
+
require 'libmagellan'
|
91
|
+
lm = Libmagellan.new(host: host_ip, port: 80,
|
92
|
+
consumer_key: "groovenauts.app1",
|
93
|
+
consumer_secret: "test")
|
94
|
+
puts Libmagellan::VERSION
|
95
|
+
lm.request("/ping").body
|
96
|
+
# => "pong\n"
|
97
|
+
lm.request("/hello/index").body
|
98
|
+
# => "{\"hello\":\"world\"}"
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
1. Fork it ( https://github.com/[my-github-username]/magellan-cli/fork )
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
107
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
109
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/magellan-cli
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'magellan/cli'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Magellan::Cli::Command.start(ARGV)
|
7
|
+
rescue Magellan::Cli::Error => e
|
8
|
+
$stderr.puts("\e[31m#{e.message}\e[0m")
|
9
|
+
exit(1)
|
10
|
+
rescue => e
|
11
|
+
$stderr.puts("\e[31m[#{e.class}] #{e.message}\e[0m\n " << e.backtrace.join("\n "))
|
12
|
+
exit(1)
|
13
|
+
end
|
data/launch_options.json
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"machine_type": "n1-standard-1",
|
3
|
+
"image": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/backports-debian-7-wheezy-v20140718",
|
4
|
+
"zone": "asia-east1-a",
|
5
|
+
"network": "magellan-staging",
|
6
|
+
"ansible_python_interpreter": "/usr/bin/env python"
|
7
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "magellan/cli"
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Magellan
|
6
|
+
module Cli
|
7
|
+
class Base < Thor
|
8
|
+
class_option :verbose, type: :boolean, aliases: "-V"
|
9
|
+
class_option :dryrun , type: :boolean, aliases: "-D"
|
10
|
+
|
11
|
+
no_commands do
|
12
|
+
|
13
|
+
def sub(klass)
|
14
|
+
task = klass.new
|
15
|
+
task.options = self.options
|
16
|
+
task
|
17
|
+
end
|
18
|
+
|
19
|
+
def opts
|
20
|
+
@opts ||= options || {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def dryrun?
|
24
|
+
opts[:dryrun]
|
25
|
+
end
|
26
|
+
|
27
|
+
def verbose?
|
28
|
+
opts[:verbose]
|
29
|
+
end
|
30
|
+
|
31
|
+
def verbose(msg)
|
32
|
+
$stderr.puts("\e[34m#{msg}\e[0m") if verbose?
|
33
|
+
end
|
34
|
+
|
35
|
+
def info(msg)
|
36
|
+
$stderr.puts(msg)
|
37
|
+
end
|
38
|
+
def success(msg)
|
39
|
+
$stderr.puts("\e[32m#{msg}\e[0m")
|
40
|
+
end
|
41
|
+
|
42
|
+
def error(msg)
|
43
|
+
raise Cli::Error, msg
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "magellan/cli"
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'active_support/core_ext/string/inflections'
|
5
|
+
|
6
|
+
module Magellan
|
7
|
+
module Cli
|
8
|
+
class Command < Base
|
9
|
+
|
10
|
+
{
|
11
|
+
"project" => "Project",
|
12
|
+
"stage" => "Stage",
|
13
|
+
"client_version" => "ClientVersion",
|
14
|
+
"function_unit" => "FunctionUnit",
|
15
|
+
"worker" => "WorkerVersion",
|
16
|
+
"instance" => "HostInstance",
|
17
|
+
"image" => "ContainerImage",
|
18
|
+
"container" => "ContainerInstance",
|
19
|
+
}.each do |name, classname|
|
20
|
+
desc "#{name} SUBCOMMAND ...ARGS", "manage #{name}"
|
21
|
+
subcommand name, ::Magellan::Cli::Resources.const_get(classname)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "direct SUBCOMMAND ...ARGS", "send request directly"
|
25
|
+
subcommand "direct", ::Magellan::Cli::Direct
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "magellan/cli"
|
3
|
+
|
4
|
+
module Magellan
|
5
|
+
module Cli
|
6
|
+
class Direct < ::Magellan::Cli::Http
|
7
|
+
|
8
|
+
desc "get PATH", "send GET request with PATH"
|
9
|
+
def get(path)
|
10
|
+
r = get_json(path)
|
11
|
+
$stdout.puts(JSON.pretty_generate(r))
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "post PATH [PARAMS]", "send POST request with PATH and PARAMS"
|
15
|
+
def post(path, params = nil)
|
16
|
+
post_json(path)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "put PATH [PARAMS]", "send PUT request with PATH and PARAMS"
|
20
|
+
def put(path, params = nil)
|
21
|
+
put_json(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "delete PATH", "send DELETE request with PATH"
|
25
|
+
def delete(path)
|
26
|
+
delete(path)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "magellan/cli"
|
3
|
+
|
4
|
+
module Magellan
|
5
|
+
module Cli
|
6
|
+
class Http < ::Magellan::Cli::Base
|
7
|
+
|
8
|
+
no_commands do
|
9
|
+
|
10
|
+
def login
|
11
|
+
cli = Cli::Login.new
|
12
|
+
cli.login!
|
13
|
+
r = yield(cli)
|
14
|
+
success("OK")
|
15
|
+
return r
|
16
|
+
end
|
17
|
+
|
18
|
+
# ログインしてGETします
|
19
|
+
# @param [String] rel_path cli.base_https_url からの相対パス
|
20
|
+
# @param [Hash] params クエリ文字列
|
21
|
+
# @return [Object] レスポンスのBODYをJSONとしてパースした結果オブジェクト
|
22
|
+
def get_json(rel_path, params = nil)
|
23
|
+
login do |cli|
|
24
|
+
url = "#{cli.base_https_url}#{rel_path}"
|
25
|
+
if params && !params.empty?
|
26
|
+
url << '?' << params.map{|k,v| "%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)] }.join("&")
|
27
|
+
end
|
28
|
+
verbose("url: #{url}")
|
29
|
+
res = cli.httpclient.get(url)
|
30
|
+
JSON.parse(res.body)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# ログインしてPOSTします
|
35
|
+
# @param [String] rel_path cli.base_https_url からの相対パス
|
36
|
+
# @param [Hash] params POSTで渡されるパラメータ
|
37
|
+
# @return nil
|
38
|
+
def post(rel_path, params)
|
39
|
+
login do |cli|
|
40
|
+
params = {authenticity_token: cli.auth_token}.update(params || {})
|
41
|
+
process_res(cli, :post, rel_path, params)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# ログインしてJSON形式のbodyをPOSTします
|
46
|
+
# @param [String] rel_path cli.base_https_url からの相対パス
|
47
|
+
# @param [Hash] params POSTで渡されるパラメータ
|
48
|
+
# @return nil
|
49
|
+
def post_json(rel_path, params)
|
50
|
+
login do |cli|
|
51
|
+
params = {authenticity_token: cli.auth_token}.update(params || {})
|
52
|
+
process_res(cli, :post, rel_path, params.to_json, JSON_HEADER)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# ログインしてPUTします
|
57
|
+
# @param [String] rel_path cli.base_https_url からの相対パス
|
58
|
+
# @param [Hash] params PUTで渡されるパラメータ
|
59
|
+
# @return nil
|
60
|
+
def put(rel_path, params)
|
61
|
+
login do |cli|
|
62
|
+
params = {authenticity_token: cli.auth_token}.update(params || {})
|
63
|
+
process_res(cli, :put, rel_path, params)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# ログインしてJSON形式のbodyをPUTします
|
68
|
+
# @param [String] rel_path cli.base_https_url からの相対パス
|
69
|
+
# @param [Hash] params PUTで渡されるパラメータ
|
70
|
+
# @return nil
|
71
|
+
def put_json(rel_path, params)
|
72
|
+
login do |cli|
|
73
|
+
params = {authenticity_token: cli.auth_token}.update(params || {})
|
74
|
+
process_res(cli, :put, rel_path, params.to_json, JSON_HEADER)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# ログインしてDELETEします
|
79
|
+
# @param [String] rel_path cli.base_https_url からの相対パス
|
80
|
+
# @return nil
|
81
|
+
def delete(rel_path)
|
82
|
+
login do |cli|
|
83
|
+
params = {authenticity_token: cli.auth_token}
|
84
|
+
process_res(cli, :delete, rel_path, params)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def process_res(cli, http_method, rel_path, *args)
|
89
|
+
res = cli.httpclient.send(http_method, "#{cli.base_https_url}#{rel_path}", *args)
|
90
|
+
case res.status
|
91
|
+
when 200...300 then
|
92
|
+
r = JSON.parse(res.body)
|
93
|
+
$stdout.puts(JSON.pretty_generate(r))
|
94
|
+
else
|
95
|
+
$stdout.puts("\e[31m[#{res.status}]\e[0m\ #{res.body}")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|