Class: Ruboty::Handlers::Niftycloud

Inherits:
Base
  • Object
show all
Defined in:
lib/ruboty/handlers/niftycloud.rb

Constant Summary collapse

NIFTYCLOUD =
"(?:niftycloud|nc)"
ACCOUNT =
"(?:account|a)"
COMPUTING =
"(?:computing|c)"
RDB =
"(?:rdb|r)"
INSTANCE =
"(?:instance|i)"
KEY_PAIR =
"(?:key_pair|kp)"
SECURITY_GROUP =
"(?:security_group|sg)"
VOLUME =
"(?:volume|v)"
IMAGE =
"(?:image)"
LOAD_BALANCER =
"(?:load_balancer|lb)"
ADDRESS =
"(?:address)"
SSL_CERTIFICATE =
"(?:ssl_certificate|ssl)"
AVAILABILITY_ZONE =
"(?:availability_zone|zone)"
DB_INSTANCE =
"(?:db_instance|i)"
LIST =
"(?:list|l)"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot) ⇒ Niftycloud

Returns a new instance of Niftycloud.



7
8
9
10
# File 'lib/ruboty/handlers/niftycloud.rb', line 7

def initialize(robot)
  super(robot)
  @prev = {}
end

Instance Attribute Details

#prevObject

Returns the value of attribute prev.



5
6
7
# File 'lib/ruboty/handlers/niftycloud.rb', line 5

def prev
  @prev
end

Instance Method Details

#account_list(message) ⇒ Object



175
176
177
# File 'lib/ruboty/handlers/niftycloud.rb', line 175

def (message)
  Ruboty::Niftycloud::Actions::AccountList.new(message).call
end

#account_use(message) ⇒ Object



179
180
181
# File 'lib/ruboty/handlers/niftycloud.rb', line 179

def (message)
  Ruboty::Niftycloud::Actions::AccountUse.new(message).call
end

#computing_address_list(message) ⇒ Object



215
216
217
# File 'lib/ruboty/handlers/niftycloud.rb', line 215

def computing_address_list(message)
  Ruboty::Niftycloud::Actions::ComputingAddressList.new(message).call
end

#computing_availability_zone_list(message) ⇒ Object



219
220
221
# File 'lib/ruboty/handlers/niftycloud.rb', line 219

def computing_availability_zone_list(message)
  Ruboty::Niftycloud::Actions::ComputingAvailabilityZoneList.new(message).call
end

#computing_image_list(message) ⇒ Object



223
224
225
# File 'lib/ruboty/handlers/niftycloud.rb', line 223

def computing_image_list(message)
  Ruboty::Niftycloud::Actions::ComputingImageList.new(message).call
end

#computing_image_show(message) ⇒ Object



227
228
229
# File 'lib/ruboty/handlers/niftycloud.rb', line 227

def computing_image_show(message)
  Ruboty::Niftycloud::Actions::ComputingImageShow.new(message).call
end

#computing_instance_list(message) ⇒ Object



183
184
185
# File 'lib/ruboty/handlers/niftycloud.rb', line 183

def computing_instance_list(message)
  Ruboty::Niftycloud::Actions::ComputingInstanceList.new(message).call
end

#computing_instance_show(message) ⇒ Object



187
188
189
# File 'lib/ruboty/handlers/niftycloud.rb', line 187

def computing_instance_show(message)
  Ruboty::Niftycloud::Actions::ComputingInstanceShow.new(message).call
end

#computing_key_pair_list(message) ⇒ Object



231
232
233
# File 'lib/ruboty/handlers/niftycloud.rb', line 231

def computing_key_pair_list(message)
  Ruboty::Niftycloud::Actions::ComputingKeyPairList.new(message).call
end

#computing_key_pair_show(message) ⇒ Object



235
236
237
# File 'lib/ruboty/handlers/niftycloud.rb', line 235

def computing_key_pair_show(message)
  Ruboty::Niftycloud::Actions::ComputingKeyPairShow.new(message).call
end

#computing_load_balancer_list(message) ⇒ Object



207
208
209
# File 'lib/ruboty/handlers/niftycloud.rb', line 207

def computing_load_balancer_list(message)
  Ruboty::Niftycloud::Actions::ComputingLoadBalancerList.new(message).call
end

#computing_load_balancer_show(message) ⇒ Object



211
212
213
# File 'lib/ruboty/handlers/niftycloud.rb', line 211

def computing_load_balancer_show(message)
  Ruboty::Niftycloud::Actions::ComputingLoadBalancerShow.new(message).call
end

#computing_region_list(message) ⇒ Object



255
256
257
# File 'lib/ruboty/handlers/niftycloud.rb', line 255

def computing_region_list(message)
  Ruboty::Niftycloud::Actions::ComputingRegionList.new(message).call
end

#computing_region_use(message) ⇒ Object



259
260
261
# File 'lib/ruboty/handlers/niftycloud.rb', line 259

def computing_region_use(message)
  Ruboty::Niftycloud::Actions::ComputingRegionUse.new(message).call
end

#computing_security_group_list(message) ⇒ Object



191
192
193
# File 'lib/ruboty/handlers/niftycloud.rb', line 191

def computing_security_group_list(message)
  Ruboty::Niftycloud::Actions::ComputingSecurityGroupList.new(message).call
end

#computing_security_group_show(message) ⇒ Object



195
196
197
# File 'lib/ruboty/handlers/niftycloud.rb', line 195

def computing_security_group_show(message)
  Ruboty::Niftycloud::Actions::ComputingSecurityGroupShow.new(message).call
end

#computing_ssl_certificate_list(message) ⇒ Object



239
240
241
# File 'lib/ruboty/handlers/niftycloud.rb', line 239

def computing_ssl_certificate_list(message)
  Ruboty::Niftycloud::Actions::ComputingSslCertificateList.new(message).call
end

#computing_ssl_certificate_show(message) ⇒ Object



243
244
245
# File 'lib/ruboty/handlers/niftycloud.rb', line 243

def computing_ssl_certificate_show(message)
  Ruboty::Niftycloud::Actions::ComputingSslCertificateShow.new(message).call
end

#computing_volume_list(message) ⇒ Object



199
200
201
# File 'lib/ruboty/handlers/niftycloud.rb', line 199

def computing_volume_list(message)
  Ruboty::Niftycloud::Actions::ComputingVolumeList.new(message).call
end

#computing_volume_show(message) ⇒ Object



203
204
205
# File 'lib/ruboty/handlers/niftycloud.rb', line 203

def computing_volume_show(message)
  Ruboty::Niftycloud::Actions::ComputingVolumeShow.new(message).call
end

#event_watch(message) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/ruboty/handlers/niftycloud.rb', line 263

def event_watch(message)
  return if @thread
  message.reply "started to watch events"
  @thread = Thread.new do
    base = Ruboty::Niftycloud::Actions::Base.new(message)
    loop do
      base.accounts.each do ||
        base.([:name])

        base.computing.regions.each do |region|
          base.current_region(region['regionName'])

          resources = {
            %w(computing volumes) => {id: 'volumeId', label: 'ディスク'},
            %w(computing key_pairs) => {id: 'keyName', label: 'SSH キー'},
            %w(computing images) => {id: 'imageId', label: 'イメージ'},
            %w(computing ssl_certificates) => {id: 'fqdnId', label: 'SSL 証明書'},
            %w(computing addresses) => {id: ['publicIp', 'privateIpAddress'], label: '付替 IP アドレス'},
            %w(computing uploads) => {id: 'conversionTaskId', label: 'アップロード'},
            %w(computing instances) => {id: 'instanceId', label: 'サーバー'},
            %w(rdb db_instances) => {id: 'DBInstanceIdentifier', label: 'DB サーバー'},
            %w(rdb db_snapshots) => {id: 'instanceId', label: 'DB スナップショット'},
            %w(computing security_groups) => {id: 'groupName', ignore: 'ipPermissions', label: 'ファイアウォールグループ'},
            %w(rdb db_security_groups) => {id: 'DBSecurityGroupName', ignore: ['EC2SecurityGroups', 'IPRanges'], label: 'DB ファイアウォールグループ'},
            %w(rdb db_parameter_groups) => {id: 'DBParameterGroupName', label: 'DB パラメーターグループ'},
          }
          resources.each do |options, d2e|
            begin
              service, resource = options
              key = [[:name], region['regionName'], resource].join(':')
              prev = @prev[key]
              curr = base.send(service).send(resource)
              if prev
                events = D2E.new(d2e).d2e(prev, curr) 
                events.each do |event|
                  ja = case event['type']
                  when 'create'; '作成'
                  when 'delete'; '削除'
                  when 'update'; '更新'
                  end
                  if event['type'] == 'create' || event['type'] == 'delete'
                    table = Table(event['item'].keys)
                    table << event['item'].values
                    message.reply [
                      "#{[:name]} (#{[:description]}) の #{region['regionName']} で下記#{d2e[:label]}#{ja}されました",
                      table.to_s
                    ]
                  else
                    table = Table(event['diff'].keys)
                    table << event['diff'].values.map {|val| "#{val[0]} -> #{val[1]}" }
                    message.reply [
                      "#{[:name]} (#{[:description]}) の #{region['regionName']} で下記#{d2e[:label]}(#{event['id']})が#{ja}されました",
                      table.to_s
                    ].join("\n")
                  end
                end
              end
              @prev[key] = curr
            rescue StandardError => e
              message.reply "Error: #{e}"
            end
          end
        end
      end
      sleep 5
    end
  end.run
end

#rdb_db_instance_list(message) ⇒ Object



247
248
249
# File 'lib/ruboty/handlers/niftycloud.rb', line 247

def rdb_db_instance_list(message)
  Ruboty::Niftycloud::Actions::RdbDbInstanceList.new(message).call
end

#rdb_db_instance_show(message) ⇒ Object



251
252
253
# File 'lib/ruboty/handlers/niftycloud.rb', line 251

def rdb_db_instance_show(message)
  Ruboty::Niftycloud::Actions::RdbDbInstanceShow.new(message).call
end