· 7 years ago · Mar 07, 2018, 12:50 AM
1#!/usr/bin/env ruby
2
3require 'rubygems'
4require 'vfci'
5#require 'cSlib'
6require 'cSlog'
7require 'cScustomerData'
8
9#lib = CSlib.new
10log = CSlog.open(File.basename(__FILE__))
11
12$stderr = File.open("/tmp/new_ssh_key.stderr", "w")
13$stdout = File.open("/tmp/new_ssh_key.stdout", "w")
14
15log.info("Processing new_ssh_key event")
16log.info("#{event.name} event dump: #{event.inspect}")
17log.info("Connecting to AWS Service EC2 to generate new SSH key")
18Customer.cx
19thisCustomer = Customer.find(:first)
20thisCustomersVF=thisCustomer.virtual_fabrics.find_by_name('EC2')
21myFabric=Vfci::Fabric.new(
22 :access_key => thisCustomersVF.access_key,
23 :secret_key => thisCustomersVF.secret_key,
24 :vf_type => 'EC2'
25 )
26keydata=myFabric.new_ssh_key(event.opts[:keyname])
27thisCustomer.ssh_keys << SshKey.new(:name => keydata[:keyName], :privkey => keydata[:keyMaterial])
28thisCustomer.save!
29Customer.dx
30log.info("Completed AWS EC2 Call")