berta 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09e6600e17620f40aa1c19a1f1522fb9fea2bc90
4
- data.tar.gz: 7d8f55eb72b8ef4bb0880d1f6e2674d5ff5ab238
3
+ metadata.gz: 38b7c4c208604f8f2f38e396c03dd8d0950626a9
4
+ data.tar.gz: 844a95982da959c7be4ba173095a7910c96e21cf
5
5
  SHA512:
6
- metadata.gz: 9efb8c04d2f4cba86e470c574729cfa842b9458b536d3e9ae347a8b4909aff75b1df3909a7f6a7f513d1fdcfd7c030a58a9a80d4211b15be4ea9ecae68033669
7
- data.tar.gz: b9a6e029de8abcc36a12c79eba6ada28b103cee8fff57ceda78a4bf4724e1b9a8cf70207478a39b3c8003acf207b3dad150d1b5c39fecd32d44c25dd20febd76
6
+ metadata.gz: 7fca088e770e144d0ad3027a54a36f4bf7b9e04a80aecc2533a7244a84ae03b88a4cfadc86fb635793a4463b5b5ef3437d6c6dee1b1d0fe53ea3b8a674a928fc
7
+ data.tar.gz: 63ea0386912c8a2ee7a6ba3d9d4fa5ea60521510f1614ab03a671c53547145f2bbb9d07f5b9c5268aea3e4a7e8f8a29f91474771df699205de53570f88ecc6de
@@ -22,7 +22,10 @@ module Berta
22
22
  # @param email_template [Tilt::ERBTemplate] Email template
23
23
  def notify(user_vms, email_template)
24
24
  to_notify = user_vms.keep_if(&:should_notify?)
25
- return if to_notify.empty?
25
+ if to_notify.empty?
26
+ logger.debug "No notifications for user #{handle['NAME']}"
27
+ return
28
+ end
26
29
  send_notification(to_notify, email_template)
27
30
  user_vms.each(&:update_notified)
28
31
  rescue ArgumentError, Berta::Errors::Entities::NoUserEmailError => e
@@ -35,7 +38,8 @@ module Berta
35
38
  raise Berta::Errors::Entities::NoUserEmailError, "User: #{user_name} with id: #{handle['ID']} has no email set" \
36
39
  unless user_email
37
40
  email_text = email_template.render(Hash, user_email: user_email, user_name: user_name, vms: vms_data(user_vms))
38
- logger.debug "Sending mail to user: #{user_name} with email: #{user_email}:\n#{email_text}"
41
+ logger.info "Sending mail to user: #{user_name} on email: #{user_email}"
42
+ logger.debug email_text
39
43
  Mail.new(email_text).deliver unless Berta::Settings['dry-run']
40
44
  end
41
45
 
data/lib/berta/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Berta
2
- VERSION = '1.5.1'.freeze
2
+ VERSION = '1.5.2'.freeze
3
3
  end
@@ -20,7 +20,11 @@ module Berta
20
20
  def update
21
21
  exps = expirations.keep_if(&:in_expiration_interval?)
22
22
  exps << next_expiration unless default_expiration
23
- update_expirations(exps) unless exps == expirations
23
+ if exps == expirations
24
+ logger.debug "No changes in expirations for vm #{handle['ID']}"
25
+ else
26
+ update_expirations(exps)
27
+ end
24
28
  rescue Berta::Errors::BackendError => e
25
29
  logger.error "#{e.message} on vm with id #{vm.handle['ID']}"
26
30
  end
@@ -40,12 +44,8 @@ module Berta
40
44
  exp = default_expiration
41
45
  return unless exp
42
46
  notify_time = exp.time
43
- logger.debug "Setting notified flag of VM with id #{handle['ID']} to #{notify_time}"
44
- return if Berta::Settings['dry-run']
45
- Berta::Utils::OpenNebula::Helper.handle_error do
46
- handle.update("#{NOTIFIED_FLAG} = #{notify_time.to_i}", true)
47
- handle.info
48
- end
47
+ logger.info "Setting notified flag of VM with id #{handle['ID']} to #{notify_time}"
48
+ send_update("#{NOTIFIED_FLAG} = #{notify_time.to_i}")
49
49
  end
50
50
 
51
51
  # Determines if VM meets criteria to be notified.
@@ -105,11 +105,15 @@ module Berta
105
105
  # @note This method modifies OpenNebula database
106
106
  # @param exps [Array<Berta::Entities::Expiration>] Expirations to use
107
107
  def update_expirations(exps)
108
- template = ''
109
- exps.each { |exp| template += exp.template }
108
+ template = exps.inject('') { |temp, exp| temp + exp.template }
110
109
  return if template == ''
111
- logger.debug \
112
- "Setting expirations on vm with id=#{handle['ID']} usr=#{handle['UNAME']} grp=#{handle['GNAME']} : #{template.delete("\n ")}"
110
+ logger.info "Setting expirations on vm with id=#{handle['ID']} usr=#{handle['UNAME']} grp=#{handle['GNAME']}"
111
+ logger.debug template.delete("\n ")
112
+ send_update(template)
113
+ end
114
+
115
+ # Sends data to opennebula service
116
+ def send_update(template)
113
117
  return if Berta::Settings['dry-run']
114
118
  Berta::Utils::OpenNebula::Helper.handle_error do
115
119
  handle.update(template, true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Baran