ruboty-niftycloud 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf5afa3cf305d41677d68c153ac5bae57ca1dad2
4
- data.tar.gz: 56f2612995b3a6864d215164175cfd453c18306d
3
+ metadata.gz: e2fbaea4da6186886970574cccbe543fdcbd5bd0
4
+ data.tar.gz: 5f4de5c82986028326b02500b786cdb9bb773b03
5
5
  SHA512:
6
- metadata.gz: 154297170fdede2cf6050d27dd811f99ed312880f02876f5ecd8439fbdeeffee6797004ed428adb783323d31ffd8b69359119645609d701951659899192bd1de
7
- data.tar.gz: a20509044adafb99623764caa38067d8bce01a912a3ac1e49de00eb508af7da414b3d5015390f230622c09b4f55465bc53f7694fa2e898e0077497318bebfdf5
6
+ metadata.gz: d38adba0d69534049f5b9660e7c97907407ff11477de024e3e92ef156cc96f3c666a8151818c990daae1e2b9e550bd1086c083aa4b8cd084cb6c5d25bbad549b
7
+ data.tar.gz: 33f7218e3c80464c30a033e9b6e4bcff4798a152a248676cec8004ba85ae6e9dfbce674a1ca4cc599df6278d65765a5cd8098adf457d1361cf1b87fb162c1fd0
data/README.md CHANGED
@@ -14,6 +14,8 @@ gem "ruboty-niftycloud"
14
14
  ```
15
15
  @ruboty niftycloud account list - list accounts
16
16
  @ruboty niftycloud account use <account or number> - use account
17
+ @ruboty niftycloud event watch - watch events
18
+ @ruboty niftycloud event unwatch - unwatch events
17
19
  @ruboty niftycloud computing region list - list computing regions
18
20
  @ruboty niftycloud computing region use - use computing region
19
21
  @ruboty niftycloud computing availability zone list - list computing availability zones
@@ -1,3 +1,4 @@
1
+ # coding:utf-8
1
2
  module Ruboty
2
3
  module Handlers
3
4
  class Niftycloud < Base
@@ -261,6 +262,7 @@ module Ruboty
261
262
 
262
263
  def event_watch(message)
263
264
  return if @thread
265
+ message.reply "started to watch events"
264
266
  @thread = Thread.new do
265
267
  base = Ruboty::Niftycloud::Actions::Base.new(message)
266
268
  loop do
@@ -271,30 +273,50 @@ module Ruboty
271
273
  base.current_region(region['regionName'])
272
274
 
273
275
  resources = {
274
- 'volumes' => 'volumeId',
275
- 'key_pairs' => 'keyName',
276
- 'images' => 'imageId',
277
- 'ssl_certificates' => 'fqdnId',
278
- 'addresses' => ['publicIp', 'privateIpAddress'],
279
- 'uploads' => ['conversionTaskId'],
280
- 'instances' => ['instanceId'],
276
+ %w(computing volumes) => {id: 'volumeId', label: 'ディスク'},
277
+ %w(computing key_pairs) => {id: 'keyName', label: 'SSH キー'},
278
+ %w(computing images) => {id: 'imageId', label: 'イメージ'},
279
+ %w(computing ssl_certificates) => {id: 'fqdnId', label: 'SSL 証明書'},
280
+ %w(computing addresses) => {id: ['publicIp', 'privateIpAddress'], label: '付替 IP アドレス'},
281
+ %w(computing uploads) => {id: 'conversionTaskId', label: 'アップロード'},
282
+ %w(computing instances) => {id: 'instanceId', label: 'サーバー'},
283
+ %w(rdb db_instances) => {id: 'DBInstanceIdentifier', label: 'DB サーバー'},
284
+ %w(rdb db_snapshots) => {id: 'instanceId', label: 'DB スナップショット'},
285
+ %w(computing security_groups) => {id: 'groupName', ignore: 'ipPermissions', label: 'ファイアウォールグループ'},
286
+ %w(rdb db_security_groups) => {id: 'DBSecurityGroupName', ignore: ['EC2SecurityGroups', 'IPRanges'], label: 'DB ファイアウォールグループ'},
287
+ %w(rdb db_parameter_groups) => {id: 'DBParameterGroupName', label: 'DB パラメーターグループ'},
281
288
  }
282
- resources.each do |resource, id|
283
- key = [account[:name], region['regionName'], resource].join(':')
284
- prev = @prev[key]
285
- curr = base.computing.send(resource)
286
- if prev
287
- events = D2E.new(id: id).d2e(prev, curr)
288
- events.each do |event|
289
- robot.say body: "#{account[:name]}(#{account[:description]}) #{region['regionName']} で下記 #{resource} が #{event['type']} されました"
290
- if event['type'] == 'create' || event['type'] == 'delete'
291
- robot.say body: event['item']
292
- else
293
- robot.say body: event
289
+ resources.each do |options, d2e|
290
+ begin
291
+ service, resource = options
292
+ key = [account[:name], region['regionName'], resource].join(':')
293
+ prev = @prev[key]
294
+ curr = base.send(service).send(resource)
295
+ if prev
296
+ events = D2E.new(d2e).d2e(prev, curr)
297
+ events.each do |event|
298
+ ja = case event['type']
299
+ when 'create'; '作成'
300
+ when 'delete'; '削除'
301
+ when 'update'; '更新'
302
+ end
303
+ if event['type'] == 'create' || event['type'] == 'delete'
304
+ robot.say body: "#{account[:name]} (#{account[:description]}) の #{region['regionName']} で下記#{d2e[:label]}が#{ja}されました"
305
+ table = Table(event['item'].keys)
306
+ table << event['item'].values
307
+ robot.say body: table.to_s
308
+ else
309
+ robot.say body: "#{account[:name]} (#{account[:description]}) の #{region['regionName']} で下記#{d2e[:label]}(#{event['id']})が#{ja}されました"
310
+ table = Table(event['diff'].keys)
311
+ table << event['diff'].values.map {|val| "#{val[0]} -> #{val[1]}" }
312
+ robot.say body: table.to_s
313
+ end
294
314
  end
295
315
  end
316
+ @prev[key] = curr
317
+ rescue StandardError => e
318
+ robot.say "Error: #{e}"
296
319
  end
297
- @prev[key] = curr
298
320
  end
299
321
  end
300
322
  end
@@ -305,7 +327,10 @@ module Ruboty
305
327
  end
306
328
 
307
329
  def event_unwatch(message)
308
- @thread.kill if @thread
330
+ return if @thread.nil
331
+ @thread.kill
332
+ @thread = nil
333
+ message.reply "stopped to watch events"
309
334
  end
310
335
  end
311
336
  end
@@ -25,4 +25,5 @@ require "ruboty/niftycloud/version"
25
25
  require "ruboty/handlers/niftycloud"
26
26
 
27
27
  require 'd2e'
28
+ require 'ruport'
28
29
  require "ace-client"
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Niftycloud
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "ace-client"
26
26
  spec.add_dependency "ace-client-ext"
27
27
  spec.add_dependency "d2e"
28
+ spec.add_dependency "ruport"
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-niftycloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - tily
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Manage NIFTYCloud via Ruboty
98
112
  email:
99
113
  - tily05@gmail.com