ms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/hp-config.rb +61 -0
  3. data/lib/ms-email.rb +18 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 542e8835950dc3977a77cdfc4285f2ee0285ab38
4
+ data.tar.gz: 2c7c71d9dea6ffc4e9ebaba32b521c1c90be5c1a
5
+ SHA512:
6
+ metadata.gz: daf58995ea889880db88768cbc4e199e685aeeee73bab9be8a67a6dd50867ff3beec7f2a4e5f8dcae9cc7b87d1578ec341299f590c4dffc678d08a71a6e096db
7
+ data.tar.gz: e473e3abe7826e822ea43d92635f85fca9a27934de0eaff4f50e7102d530866c9abafb6b6b16cb9a8267378756cdb5edb63103f6064512cc4f42b2cac6066de5
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'fog'
3
+ require 'date'
4
+ require 'time'
5
+
6
+ conn = Fog::Compute.new(
7
+ :provider => "HP",
8
+ :version => :v2,
9
+ :hp_access_key => ENV['HP_ACCESS_KEY'],
10
+ :hp_secret_key => ENV['HP_SECRET_KEY'],
11
+ #:hp_auth_uri => "",
12
+ :hp_tenant_id => ENV['HP_TENANT_ID'],
13
+ :hp_avl_zone => "region-b.geo-1",
14
+ )
15
+
16
+ response = conn.list_servers_detail
17
+ #puts "#{response.body['servers'][0]['image']}"
18
+
19
+
20
+ class Notify_instances
21
+ def initialize(name)
22
+ @instance_name= name
23
+ end
24
+ def display_details()
25
+ puts "Instance name #@instance_name"
26
+ end
27
+ end
28
+
29
+ # For instance name display
30
+ $i = 0
31
+ while $i<2
32
+ inst=Notify_instances.new("#{response.body['servers'][$i]['name']}")
33
+ inst.display_details()
34
+ $i+=1
35
+ end
36
+
37
+ # For instance creation
38
+ $j = 0
39
+ while $j<2
40
+ puts "Checking #{$j} instances "
41
+ puts Time.parse("#{response.body['servers'][$j]['created']}")
42
+ t1 = Time.parse("#{response.body['servers'][$j]['created']}")
43
+ t2 = Time.now
44
+ # puts t1
45
+ # puts t2
46
+ # standardize the time and date
47
+ date1 = (t1.year + t1.mon + t1.day)
48
+ puts date1
49
+ date2 = (t2.year + t2.mon + t2.day)
50
+ puts date2
51
+ if date1 == date2 then
52
+ time1 = (t1.hour * 60 * 60 + t1.min * 60 + t1.sec)
53
+ # puts time1
54
+ time2 = (t2.hour * 60 * 60 + t2.min * 60 + t2.sec)
55
+ # puts time2
56
+ if (time2 - time1) <= 1800 then
57
+ system("ruby ms-email.rb")
58
+ end
59
+ end
60
+ $j += 1
61
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gmail'
4
+ gmail = Gmail.new(ENV['username'],ENV['password'])
5
+
6
+
7
+ puts "Count: #{gmail.inbox.count}"
8
+ puts "=========== Sending Email =============================="
9
+ gmail.deliver do
10
+ to "admin@gmail.com"
11
+ subject "Hi from HPCloud"
12
+ text_part do
13
+ body "New instance created"
14
+ end
15
+
16
+ end
17
+ puts "Sent"
18
+ gmail.logout
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manish Sethi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Send emails to admin regading new instance creation.
14
+ email:
15
+ - manish@sethis.in
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - hp-config.rb
21
+ - lib/ms-email.rb
22
+ homepage:
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Notifiy new instance created
45
+ test_files: []