magellan-cli 0.1.0

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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +60 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +109 -0
  9. data/Rakefile +7 -0
  10. data/bin/magellan-cli +13 -0
  11. data/launch_options.json +7 -0
  12. data/lib/magellan/cli/base.rb +50 -0
  13. data/lib/magellan/cli/command.rb +29 -0
  14. data/lib/magellan/cli/direct.rb +32 -0
  15. data/lib/magellan/cli/errors.rb +14 -0
  16. data/lib/magellan/cli/http.rb +103 -0
  17. data/lib/magellan/cli/login.rb +134 -0
  18. data/lib/magellan/cli/resources/base.rb +136 -0
  19. data/lib/magellan/cli/resources/client_version.rb +15 -0
  20. data/lib/magellan/cli/resources/container_image.rb +13 -0
  21. data/lib/magellan/cli/resources/container_instance.rb +25 -0
  22. data/lib/magellan/cli/resources/function_unit.rb +27 -0
  23. data/lib/magellan/cli/resources/host_instance.rb +56 -0
  24. data/lib/magellan/cli/resources/project.rb +22 -0
  25. data/lib/magellan/cli/resources/stage.rb +69 -0
  26. data/lib/magellan/cli/resources/worker_version.rb +41 -0
  27. data/lib/magellan/cli/resources.rb +27 -0
  28. data/lib/magellan/cli/sample_launch_options.json +7 -0
  29. data/lib/magellan/cli/ssl.rb +35 -0
  30. data/lib/magellan/cli/version.rb +5 -0
  31. data/lib/magellan/cli.rb +23 -0
  32. data/magellan-cli.gemspec +29 -0
  33. data/spec/magellan/cli/Magellan.yml +29 -0
  34. data/spec/magellan/cli/login_page.html +42 -0
  35. data/spec/magellan/cli/login_spec.rb +46 -0
  36. data/spec/magellan/cli/resources/project_spec.rb +39 -0
  37. data/spec/magellan/cli_spec.rb +7 -0
  38. data/spec/spec_helper.rb +2 -0
  39. metadata +187 -0
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "magellan/cli/resources"
3
+
4
+ module Magellan
5
+ module Cli
6
+ module Resources
7
+
8
+ class WorkerVersion < Base
9
+ self.resource_name = "worker_version"
10
+ self.resource_dependency = {"stage" => "stage-version"}
11
+
12
+ desc "create NAME, IMAGE", "create WorkerVersion with NAME, IMAGE"
13
+ method_option :attributes_yaml, aliases: "-A", desc: "path to YAML file which defines attributes"
14
+ def create(name, image_name)
15
+ s = load_selection("stage-version")
16
+ attrs =
17
+ if path = options[:attributes_yaml]
18
+ YAML.load_file(path)
19
+ else
20
+ {}
21
+ end
22
+ params = {
23
+ "worker_version" => {
24
+ "stage_version_id" => s["id"],
25
+ "image_name" => image_name,
26
+ # "instance_base_name" => name,
27
+ "function_unit_attributes" => { # accepts_nested_attributes_for
28
+ "name" => name,
29
+ "kind" => "201",
30
+ "stage_version_id" => s["id"],
31
+ }
32
+ }.update(attrs)
33
+ }
34
+ post_json("/admin/worker_version/new.js", params)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "magellan/cli"
3
+
4
+ require 'json'
5
+ require 'yaml'
6
+ require 'active_support/core_ext/string/inflections'
7
+
8
+ module Magellan
9
+ module Cli
10
+ module Resources
11
+
12
+ autoload :Base , "magellan/cli/resources/base"
13
+ autoload :Project , "magellan/cli/resources/project"
14
+ autoload :Stage , "magellan/cli/resources/stage"
15
+ autoload :ClientVersion , "magellan/cli/resources/client_version"
16
+
17
+ autoload :FunctionUnit , "magellan/cli/resources/function_unit"
18
+ autoload :WorkerVersion , "magellan/cli/resources/worker_version"
19
+
20
+ autoload :HostInstance , "magellan/cli/resources/host_instance"
21
+
22
+ autoload :ContainerImage , "magellan/cli/resources/container_image"
23
+ autoload :ContainerInstance, "magellan/cli/resources/container_instance"
24
+
25
+ end
26
+ end
27
+ end
@@ -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,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "magellan/cli"
3
+
4
+ require 'openssl'
5
+
6
+ module Magellan
7
+ module Cli
8
+ module Ssl
9
+
10
+ DEFAULT_MAX_RETRY_COUNT = (ENV["MAGELLAN_CLI_MAX_RETRY_COUNT"] || 10).to_i
11
+
12
+ # SSLエラー発生時に規定の回数までリトライします
13
+ # @param name [String] エラー発生時に標準エラー出力に出力する文字列。処理の名前を想定しています。
14
+ # @param [Hash] options オプション
15
+ # @option options [Integer] :max_retry_count 最大リトライ回数。指定がない場合は MAGELLAN_CLI_MAX_RETRY_COUNT から、それも無ければ固定値10が使用されます。
16
+ # @option options [Numeric] :interval リトライ時のインターバルの秒数。デフォルトは0.2秒。
17
+ def retry_on_ssl_error(name, options = {})
18
+ max_retry_count = (options[:max_retry_count] || DEFAULT_MAX_RETRY_COUNT).to_i
19
+ interval = options[:interval] || 0.2
20
+ retry_count = 0
21
+ begin
22
+ return yield
23
+ rescue OpenSSL::SSL::SSLError => e
24
+ $stderr.puts("retrying #{name} [#{e.class.name}] #{e.message}")
25
+ sleep(interval)
26
+ retry_count += 1
27
+ retry if retry_count <= max_retry_count
28
+ raise e
29
+ end
30
+ end
31
+ module_function :retry_on_ssl_error
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Magellan
2
+ module Cli
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require "magellan/cli/version"
2
+
3
+ module Magellan
4
+ module Cli
5
+ autoload :Command , "magellan/cli/command"
6
+
7
+ autoload :Base , "magellan/cli/base"
8
+ autoload :Http , "magellan/cli/http"
9
+ autoload :Direct , "magellan/cli/direct"
10
+ autoload :Resources, "magellan/cli/resources"
11
+
12
+ autoload :Login , "magellan/cli/login"
13
+ autoload :Ssl , "magellan/cli/ssl"
14
+
15
+ autoload :Error , "magellan/cli/errors"
16
+ autoload :LoginError, "magellan/cli/errors"
17
+
18
+ JSON_HEADER = {
19
+ "Content-Type" => "application/json"
20
+ }.freeze
21
+
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'magellan/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "magellan-cli"
8
+ spec.version = Magellan::Cli::VERSION
9
+ spec.authors = ["akm2000"]
10
+ spec.email = ["t-akima@groovenauts.jp"]
11
+ spec.summary = %q{commandline tools for magellanic cloud service.}
12
+ spec.description = %q{commandline tools for magellanic cloud service.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "httpclient"
22
+ spec.add_runtime_dependency "thor"
23
+ spec.add_runtime_dependency "nokogiri"
24
+ spec.add_runtime_dependency "activesupport", "~> 4.1.4"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec"
29
+ end
@@ -0,0 +1,29 @@
1
+ app:
2
+ before_tasks:
3
+ - name: "stop app container"
4
+ command: docker stop app
5
+ ignore_errors: yes
6
+ - name: "remove app container"
7
+ command: docker rm app
8
+ ignore_errors: yes
9
+
10
+ - name: "make application log directory"
11
+ file:
12
+ path: /var/log/application
13
+ force: yes
14
+ state: directory
15
+
16
+ image: groovenauts/magellan-rails-example:0.0.3
17
+ # Dockerfile: "./Dockerfile"
18
+ links:
19
+ - rabbitmq:rabbitmq
20
+ env:
21
+ - VHOST=/groovenauts.app1
22
+ - REQUEST_QUEUE=groovenauts.app1.0.0.1.rails
23
+ - RESPONSE_EXCHANGE=groovenauts.app1.reply
24
+ - RABBITMQ_USER=groovenauts.app1
25
+ - RABBITMQ_PASS=workerpw
26
+ - SECRET_KEY_BASE={{ app_secret_key_base }}
27
+ volumes:
28
+ - /var/log/application:/usr/src/app/log
29
+ command: bundle exec magellan-rails
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>MagellanApi</title>
5
+ <link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
6
+ <script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
7
+ <script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
8
+ <script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
9
+ <script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
10
+ <meta content="authenticity_token" name="csrf-param" />
11
+ <meta content="047bcCC1dnyVE+7DWE6YKIJF97L/qHk1mPrf2oaqWtE=" name="csrf-token" />
12
+ </head>
13
+ <body>
14
+
15
+ <p class="notice"></p>
16
+ <p class="alert">You need to sign in or sign up before continuing.</p>
17
+
18
+ <h2>Sign in</h2>
19
+
20
+ <form accept-charset="UTF-8" action="/users/sign_in" class="new_user" id="new_user" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="047bcCC1dnyVE+7DWE6YKIJF97L/qHk1mPrf2oaqWtE=" /></div>
21
+ <div><label for="user_email">Email</label><br />
22
+ <input autofocus="autofocus" id="user_email" name="user[email]" type="email" value="" /></div>
23
+
24
+ <div><label for="user_password">Password</label><br />
25
+ <input autocomplete="off" id="user_password" name="user[password]" type="password" /></div>
26
+
27
+ <div><input name="user[remember_me]" type="hidden" value="0" /><input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1" /> <label for="user_remember_me">Remember me</label></div>
28
+
29
+ <div><input name="commit" type="submit" value="Sign in" /></div>
30
+ </form>
31
+
32
+ <a href="/users/sign_up">Sign up</a><br />
33
+
34
+ <a href="/users/password/new">Forgot your password?</a><br />
35
+
36
+
37
+
38
+
39
+
40
+
41
+ </body>
42
+ </html>
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Magellan::Cli::Login do
5
+
6
+ describe :login! do
7
+ let(:auth_token){ "047bcCC1dnyVE+7DWE6YKIJF97L/qHk1mPrf2oaqWtE=" }
8
+
9
+ context :production do
10
+ let(:cli){ Magellan::Cli::Login.new("http://example.com") }
11
+ before do
12
+ res = double(:res)
13
+ allow(cli.httpclient).to receive(:get).with("https://example.com:443/users/sign_in.html").and_return(res)
14
+ allow(res).to receive(:status).and_return(200)
15
+ allow(res).to receive(:body).and_return(File.read(File.expand_path("../login_page.html", __FILE__)))
16
+ allow(res).to receive(:body_encoding).and_return(Encoding.find("UTF-8"))
17
+ end
18
+
19
+ let(:params) do
20
+ {
21
+ "user" => {"email" => "magellan@groovenauts.jp", "password" => "password"},
22
+ "authenticity_token" => auth_token,
23
+ }
24
+ end
25
+
26
+ it :login_success do
27
+ res = double(:res)
28
+ allow(cli.httpclient).to receive(:post).with("https://example.com:443/api/sign_in.json", params.to_json, Magellan::Cli::JSON_HEADER).and_return(res)
29
+ allow(res).to receive(:status).and_return(200)
30
+ allow(res).to receive(:body).and_return({"success" => true}.to_json)
31
+ allow(res).to receive(:body_encoding).and_return(Encoding.find("UTF-8"))
32
+ expect(cli.login!).to eq cli # 自身を返す
33
+ end
34
+
35
+ it :login_failure do
36
+ res = double(:res)
37
+ allow(cli.httpclient).to receive(:post).with("https://example.com:443/api/sign_in.json", params.to_json, Magellan::Cli::JSON_HEADER).and_return(res)
38
+ allow(res).to receive(:status).and_return(401) # Unauthorized
39
+ allow(res).to receive(:body).and_return({"success" => false, "message" => "Error with your login or password"}.to_json)
40
+ allow(res).to receive(:body_encoding).and_return(Encoding.find("UTF-8"))
41
+ expect{cli.login!}.to raise_error(Magellan::Cli::LoginError, 'status: 401 {"success":false,"message":"Error with your login or password"}')
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Magellan::Cli::Resources::Project do
5
+
6
+ let(:base_url){ "https://localhost:3000" }
7
+ let(:httpclient){ double(:httpclient) }
8
+ let(:cli) do
9
+ cli = double(:login, base_https_url: base_url)
10
+ allow(cli).to receive(:httpclient).and_return(httpclient)
11
+ cli
12
+ end
13
+ let(:res){ double(:res) }
14
+
15
+ let(:cmd){ Magellan::Cli::Resources::Project.new }
16
+
17
+ before do
18
+ allow(cmd).to receive(:login).and_yield(cli)
19
+ end
20
+
21
+ describe :list do
22
+ it do
23
+ allow(res).to receive(:body).and_return("[]")
24
+ expect(httpclient).to receive(:get).with("#{base_url}/admin/project.json").and_return(res)
25
+ expect($stdout).to receive(:puts)
26
+ cmd.list
27
+ end
28
+ end
29
+
30
+ describe :show do
31
+ it do
32
+ allow(res).to receive(:body).and_return("{}")
33
+ expect(httpclient).to receive(:get).with("#{base_url}/admin/project/1.json").and_return(res)
34
+ expect($stdout).to receive(:puts)
35
+ cmd.show(1)
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magellan::Cli do
4
+ it 'has a version number' do
5
+ expect(Magellan::Cli::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'magellan/cli'
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magellan-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - akm2000
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.1.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.1.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: commandline tools for magellanic cloud service.
112
+ email:
113
+ - t-akima@groovenauts.jp
114
+ executables:
115
+ - magellan-cli
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/magellan-cli
128
+ - launch_options.json
129
+ - lib/magellan/cli.rb
130
+ - lib/magellan/cli/base.rb
131
+ - lib/magellan/cli/command.rb
132
+ - lib/magellan/cli/direct.rb
133
+ - lib/magellan/cli/errors.rb
134
+ - lib/magellan/cli/http.rb
135
+ - lib/magellan/cli/login.rb
136
+ - lib/magellan/cli/resources.rb
137
+ - lib/magellan/cli/resources/base.rb
138
+ - lib/magellan/cli/resources/client_version.rb
139
+ - lib/magellan/cli/resources/container_image.rb
140
+ - lib/magellan/cli/resources/container_instance.rb
141
+ - lib/magellan/cli/resources/function_unit.rb
142
+ - lib/magellan/cli/resources/host_instance.rb
143
+ - lib/magellan/cli/resources/project.rb
144
+ - lib/magellan/cli/resources/stage.rb
145
+ - lib/magellan/cli/resources/worker_version.rb
146
+ - lib/magellan/cli/sample_launch_options.json
147
+ - lib/magellan/cli/ssl.rb
148
+ - lib/magellan/cli/version.rb
149
+ - magellan-cli.gemspec
150
+ - spec/magellan/cli/Magellan.yml
151
+ - spec/magellan/cli/login_page.html
152
+ - spec/magellan/cli/login_spec.rb
153
+ - spec/magellan/cli/resources/project_spec.rb
154
+ - spec/magellan/cli_spec.rb
155
+ - spec/spec_helper.rb
156
+ homepage: ''
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.2.2
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: commandline tools for magellanic cloud service.
180
+ test_files:
181
+ - spec/magellan/cli/Magellan.yml
182
+ - spec/magellan/cli/login_page.html
183
+ - spec/magellan/cli/login_spec.rb
184
+ - spec/magellan/cli/resources/project_spec.rb
185
+ - spec/magellan/cli_spec.rb
186
+ - spec/spec_helper.rb
187
+ has_rdoc: