ncf 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,2 +1,20 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ desc 'vup'
4
+ task :vup do
5
+ version = ENV['VERSION']
6
+ File.open('lib/ncf/version.rb', 'w') do |f|
7
+ f.write <<-EOF
8
+ module Ncf
9
+ VERSION = "#{version}"
10
+ end
11
+ EOF
12
+ end
13
+ system "git add lib/ncf/version.rb"
14
+ system "git tag v#{version} -m v#{version}"
15
+ system "git commit -m 'version up to #{version}'"
16
+ system "git push origin master"
17
+ system "git push --tags"
18
+ system "rake build"
19
+ system "gem push pkg/ncf-#{version}.gem"
20
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/ncf ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # coding:utf-8
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
+ require 'ncf/command'
5
+ Ncf::Command.start
data/lib/ncf.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "ncf/version"
2
- require "thor"
3
2
 
4
3
  module Ncf
5
4
  # Your code goes here...
@@ -0,0 +1,31 @@
1
+ require 'ace-client'
2
+
3
+ module Ncf
4
+ class Client < AceClient::Query2
5
+ class ResponseError < StandardError; end
6
+
7
+ def initialize(options)
8
+ super(options)
9
+ end
10
+
11
+ def execute_stack(json)
12
+ @response = self.action('ExecuteStack', 'TemplateBody' => json)
13
+ raise_if_response_error
14
+ @response
15
+ end
16
+
17
+ def describe_stack(exec_id)
18
+ @response = self.action('DescribeStack', 'ExecutionId' => exec_id)
19
+ raise_if_response_error
20
+ @response
21
+ end
22
+
23
+ def raise_if_response_error
24
+ if @response.code != 200
25
+ code = @response['ErrorResponse']['Error']['Code']
26
+ message = @response['ErrorResponse']['Error']['Message']
27
+ raise ResponseError, "#{code}: #{message}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,73 @@
1
+ # coding:utf-8
2
+ require 'thor'
3
+ require 'json'
4
+ require 'ncf/client'
5
+
6
+ module Ncf
7
+ class Command < ::Thor
8
+ desc 'exec /path/to/template.json', 'JSON テンプレートを実行します'
9
+ def exec(path)
10
+ validate_env
11
+ if !File.exists?(path)
12
+ abort "ファイルが存在しません: #{path}"
13
+ end
14
+ json = File.read(path)
15
+ response = nil
16
+ begin
17
+ response = client.execute_stack(json)
18
+ rescue Ncf::Client::ResponseError => e
19
+ abort "ResponseError: #{e}"
20
+ end
21
+ exec_id = response['ExecuteStackResponse']['ExecuteStackResult']['ExecutionId']
22
+ status = nil
23
+ File.write('exec_id.txt', exec_id)
24
+ loop do
25
+ response = client.describe_stack(exec_id)
26
+ status = response['DescribeStackResponse']['DescribeStackResult']['StackStatus']
27
+ puts "処理中です"
28
+ break if status != 'EXECUTE_IN_PROGRESS'
29
+ sleep 5
30
+ end
31
+ if status == 'EXECUTE_COMPLETE'
32
+ puts "処理が正常終了しました"
33
+ else
34
+ puts "処理が異常終了しました"
35
+ end
36
+ end
37
+
38
+ desc 'desc', '実行状況を確認します (exec コマンドで書き出される request_id.txt が必要です)'
39
+ def desc
40
+ validate_env
41
+ if !File.exists?('exec_id.txt')
42
+ abort "最初に exec を実行してください"
43
+ end
44
+ exec_id = File.read('exec_id.txt').chomp
45
+ response = client.describe_stack(exec_id)
46
+ status = response['DescribeStackResponse']['DescribeStackResult']['StackStatus']
47
+ reason = response['DescribeStackResponse']['DescribeStackResult']['StackStatusReason']
48
+ case status
49
+ when 'EXECUTE_IN_PROGRESS'; puts "前回の処理が実行中です"
50
+ when 'EXECUTE_COMPLETE'; puts "前回の処理が正常終了しました"
51
+ else puts "前回の処理が異常終了しました (#{reason})"
52
+ end
53
+ end
54
+
55
+ no_commands do
56
+ def validate_env
57
+ keys = ['NCF_ACCESS_KEY_ID', 'NCF_SECRET_ACCESS_KEY', 'NCF_ENDPOINT']
58
+ if keys.any? {|x| ENV[x].nil? }
59
+ abort "環境変数 #{keys.join(',')} のすべてを設定してください"
60
+ end
61
+ end
62
+
63
+ def client
64
+ @client ||= Ncf::Client.new(
65
+ access_key_id_key: 'AccessKeyId',
66
+ access_key_id: ENV['NCF_ACCESS_KEY_ID'],
67
+ secret_access_key: ENV['NCF_SECRET_ACCESS_KEY'],
68
+ endpoint: ENV['NCF_ENDPOINT']
69
+ )
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module Ncf
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "ace-client"
24
- spec.add_dependency "thor"
25
- spec.add_dependency "json"
23
+ spec.add_dependency "ace-client", "0.0.20"
24
+ spec.add_dependency "thor", "0.19.1"
25
+ spec.add_dependency "json", "1.8.2"
26
+ spec.add_dependency "builder"
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,35 +48,51 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 0.0.20
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.0.20
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: thor
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 0.19.1
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 0.19.1
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.2
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: builder
80
96
  requirement: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
@@ -94,7 +110,8 @@ dependencies:
94
110
  description: ncf
95
111
  email:
96
112
  - tidnlyam@gmail.com
97
- executables: []
113
+ executables:
114
+ - ncf
98
115
  extensions: []
99
116
  extra_rdoc_files: []
100
117
  files:
@@ -103,7 +120,11 @@ files:
103
120
  - LICENSE.txt
104
121
  - README.md
105
122
  - Rakefile
123
+ - VERSION
124
+ - bin/ncf
106
125
  - lib/ncf.rb
126
+ - lib/ncf/client.rb
127
+ - lib/ncf/command.rb
107
128
  - lib/ncf/version.rb
108
129
  - ncf.gemspec
109
130
  homepage: ''