berta 1.6.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/README.md +4 -0
- data/berta.gemspec +7 -9
- data/config/berta.yml +1 -0
- data/config/email.erb +5 -4
- data/lib/berta.rb +2 -1
- data/lib/berta/cli.rb +18 -2
- data/lib/berta/command_executor.rb +3 -16
- data/lib/berta/entities/expiration.rb +2 -2
- data/lib/berta/entity_handler.rb +27 -0
- data/lib/berta/errors/entities.rb +1 -1
- data/lib/berta/errors/entities/{no_user_email_error.rb → no_email_error.rb} +1 -1
- data/lib/berta/notification.rb +34 -0
- data/lib/berta/service.rb +13 -2
- data/lib/berta/version.rb +1 -1
- metadata +46 -45
- data/lib/berta/user_handler.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe77a2da93232291aabe8c6d12e3eeda3c739744
|
4
|
+
data.tar.gz: 93770cebde1409fcf7c20f36329f5728b05768e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c928e9fcb19dac4de670aeba0a3ef82b409b6ba27e76db22ee6bdc47c79e6e1cd4143ec22d5b309ecb746395d83a29aded0aee9d75a2d136ae1ff05a0b1ab86a
|
7
|
+
data.tar.gz: 21184a21e33aee401b61a79c6720f6ccfbff2522080fdf5d075534a0d7c4aa6cc9400b2fdbed3f725d7a36845b98ccccb16110c8470721798c3375025c42cb51
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.1
|
5
5
|
|
6
6
|
Metrics/LineLength:
|
7
7
|
Max: 135
|
@@ -17,6 +17,11 @@ Metrics/BlockLength:
|
|
17
17
|
- '**/*.rake'
|
18
18
|
- 'spec/**/*.rb'
|
19
19
|
- '*.gemspec'
|
20
|
+
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Exclude:
|
23
|
+
- 'lib/berta/cli.rb'
|
24
|
+
|
20
25
|
Metrics/AbcSize:
|
21
26
|
Max: 20
|
22
27
|
Exclude:
|
data/README.md
CHANGED
data/berta.gemspec
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
lib = File.expand_path('../lib', __FILE__)
|
4
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
require 'berta/version'
|
@@ -20,20 +18,20 @@ Gem::Specification.new do |s|
|
|
20
18
|
s.require_paths = ['lib']
|
21
19
|
|
22
20
|
s.add_development_dependency 'bundler', '~> 1.13'
|
21
|
+
s.add_development_dependency 'coveralls', '~> 0.8'
|
22
|
+
s.add_development_dependency 'pry', '~> 0.10'
|
23
23
|
s.add_development_dependency 'rake', '~> 11.2'
|
24
24
|
s.add_development_dependency 'rspec', '~> 3.5'
|
25
25
|
s.add_development_dependency 'rubocop', '~> 0.42'
|
26
26
|
s.add_development_dependency 'rubocop-rspec', '~> 1.7'
|
27
|
-
s.add_development_dependency 'pry', '~> 0.10'
|
28
|
-
s.add_development_dependency 'webmock', '~> 2.3'
|
29
27
|
s.add_development_dependency 'vcr', '~> 3.0'
|
30
|
-
s.add_development_dependency '
|
28
|
+
s.add_development_dependency 'webmock', '~> 2.3'
|
31
29
|
|
32
|
-
s.add_runtime_dependency 'thor', '~> 0.19'
|
33
|
-
s.add_runtime_dependency 'settingslogic', '~> 2.0'
|
34
|
-
s.add_runtime_dependency 'yell', '~> 2.0'
|
35
|
-
s.add_runtime_dependency 'opennebula', '~> 5.2'
|
36
30
|
s.add_runtime_dependency 'chronic_duration', '~> 0.10'
|
37
31
|
s.add_runtime_dependency 'mail', '~> 2.6'
|
32
|
+
s.add_runtime_dependency 'opennebula', '~> 5.2'
|
33
|
+
s.add_runtime_dependency 'settingslogic', '~> 2.0'
|
34
|
+
s.add_runtime_dependency 'thor', '~> 0.19'
|
38
35
|
s.add_runtime_dependency 'tilt', '~> 2.0'
|
36
|
+
s.add_runtime_dependency 'yell', '~> 2.0'
|
39
37
|
end
|
data/config/berta.yml
CHANGED
data/config/email.erb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
<%# Available parameters: %>
|
2
|
-
<%# [String]
|
3
|
-
<%# [String]
|
2
|
+
<%# [String] name %>
|
3
|
+
<%# [String] email %>
|
4
|
+
<%# [String] type %>
|
4
5
|
<%# [Array<Hash>] vms, Array of Hashes with values: %>
|
5
6
|
<%# [String] id %>
|
6
7
|
<%# [String] name %>
|
7
8
|
<%# [String] expiration %>
|
8
9
|
From: cesnet@mail.muni.cz
|
9
|
-
To: <%=
|
10
|
+
To: <%= email %>
|
10
11
|
Subject: OpenNebula VM expiration
|
11
12
|
|
12
|
-
Hi <%=
|
13
|
+
Hi <%= name %>,
|
13
14
|
your vms are about to expire..
|
14
15
|
|
15
16
|
VM Name | Expiration Date
|
data/lib/berta.rb
CHANGED
@@ -3,7 +3,8 @@ module Berta
|
|
3
3
|
autoload :Service, 'berta/service'
|
4
4
|
autoload :Exclusions, 'berta/exclusions'
|
5
5
|
autoload :VirtualMachineHandler, 'berta/virtual_machine_handler'
|
6
|
-
autoload :
|
6
|
+
autoload :EntityHandler, 'berta/entity_handler'
|
7
|
+
autoload :Notification, 'berta/notification'
|
7
8
|
autoload :CommandExecutor, 'berta/command_executor'
|
8
9
|
autoload :CLI, 'berta/cli'
|
9
10
|
autoload :Errors, 'berta/errors'
|
data/lib/berta/cli.rb
CHANGED
@@ -59,19 +59,30 @@ module Berta
|
|
59
59
|
class_option :debug,
|
60
60
|
default: safe_fetch(%w[debug]),
|
61
61
|
type: :boolean
|
62
|
+
class_option :'email-template',
|
63
|
+
required: true,
|
64
|
+
default: safe_fetch(%w[email-template]),
|
65
|
+
type: :string
|
62
66
|
|
63
67
|
desc 'cleanup', 'Task that sets all expiration to all vms and notifies users'
|
64
68
|
def cleanup
|
65
69
|
initialize_configuration(options)
|
66
70
|
initialize_logger(options)
|
71
|
+
initialize_email
|
67
72
|
Berta::CommandExecutor.new.cleanup
|
68
73
|
end
|
69
74
|
|
70
|
-
desc 'version', 'Prints
|
75
|
+
desc 'version', 'Prints Berta version'
|
71
76
|
def version
|
72
77
|
$stdout.puts Berta::VERSION
|
73
78
|
end
|
74
79
|
|
80
|
+
desc 'config', 'Prints Berta config values'
|
81
|
+
def config
|
82
|
+
initialize_configuration(options)
|
83
|
+
Berta::Settings.each { |key, val| $stdout.puts "#{key}\t=\t#{val}" }
|
84
|
+
end
|
85
|
+
|
75
86
|
default_task :cleanup
|
76
87
|
|
77
88
|
private
|
@@ -92,6 +103,7 @@ module Berta
|
|
92
103
|
settings['debug'] = options['debug']
|
93
104
|
settings['logging']['file'] = options['logging-file']
|
94
105
|
settings['logging']['level'] = options['logging-level']
|
106
|
+
settings['email-template'] = options['email-template']
|
95
107
|
Berta::Settings.merge!(settings)
|
96
108
|
end
|
97
109
|
|
@@ -104,7 +116,7 @@ module Berta
|
|
104
116
|
|
105
117
|
setup_file_logger(options['logging-file']) if options['logging-file']
|
106
118
|
|
107
|
-
logger.debug 'Running in debug mode...'
|
119
|
+
logger.debug { 'Running in debug mode...' }
|
108
120
|
end
|
109
121
|
|
110
122
|
def setup_file_logger(logging_file)
|
@@ -114,5 +126,9 @@ module Berta
|
|
114
126
|
end
|
115
127
|
logger.adapter :file, logging_file
|
116
128
|
end
|
129
|
+
|
130
|
+
def initialize_email
|
131
|
+
Mail.defaults { delivery_method :sendmail }
|
132
|
+
end
|
117
133
|
end
|
118
134
|
end
|
@@ -1,21 +1,6 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'tilt'
|
3
|
-
require 'mail'
|
4
|
-
|
5
1
|
module Berta
|
6
2
|
# Class for executing main berta commands
|
7
3
|
class CommandExecutor
|
8
|
-
def initialize
|
9
|
-
email_file = 'email.erb'.freeze
|
10
|
-
email_template_path = "#{File.dirname(__FILE__)}/../../config/#{email_file}"
|
11
|
-
email_template_path = "/etc/berta/#{email_file}" \
|
12
|
-
if File.exist?("/etc/berta/#{email_file}")
|
13
|
-
email_template_path = "#{ENV['HOME']}/.berta/#{email_file}" \
|
14
|
-
if File.exist?("#{ENV['HOME']}/.berta/#{email_file}")
|
15
|
-
@email_template = Tilt.new(email_template_path)
|
16
|
-
Mail.defaults { delivery_method :sendmail }
|
17
|
-
end
|
18
|
-
|
19
4
|
# Function that performs clean up operation.
|
20
5
|
# Connects to opennebula database,
|
21
6
|
# runs expiration update process and
|
@@ -25,8 +10,10 @@ module Berta
|
|
25
10
|
Berta::Settings['opennebula']['endpoint'])
|
26
11
|
vms = service.running_vms
|
27
12
|
users = service.users
|
13
|
+
groups = service.groups
|
28
14
|
vms.each(&:update)
|
29
|
-
users.each { |user| user.notify(service.user_vms(user)
|
15
|
+
users.each { |user| user.notify(service.user_vms(user)) }
|
16
|
+
groups.each { |group| group.notify(service.group_vms(group)) }
|
30
17
|
rescue Berta::Errors::BackendError => e
|
31
18
|
logger.error e.message
|
32
19
|
end
|
@@ -41,13 +41,13 @@ module Berta
|
|
41
41
|
#
|
42
42
|
# @return [String] Schelude action template
|
43
43
|
def template
|
44
|
-
<<-
|
44
|
+
<<-VM_TEMPLATE
|
45
45
|
SCHED_ACTION = [
|
46
46
|
ID = "#{id}",
|
47
47
|
ACTION = "#{action}",
|
48
48
|
TIME = "#{time}"
|
49
49
|
]
|
50
|
-
|
50
|
+
VM_TEMPLATE
|
51
51
|
end
|
52
52
|
|
53
53
|
# Determines if this schelude action is in notification interval.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Berta
|
2
|
+
# Class for handeling entities in OpenNebula
|
3
|
+
class EntityHandler
|
4
|
+
attr_reader :type, :name, :email, :id, :handle
|
5
|
+
|
6
|
+
def initialize(handle)
|
7
|
+
@handle = handle
|
8
|
+
@type = handle.class.name.split('::').last
|
9
|
+
@name = handle['NAME']
|
10
|
+
@email = handle['TEMPLATE/EMAIL']
|
11
|
+
@id = handle['ID']
|
12
|
+
end
|
13
|
+
|
14
|
+
def notify(vms)
|
15
|
+
notification = Berta::Notification.new(name, email, type)
|
16
|
+
to_notify = vms.keep_if(&:should_notify?)
|
17
|
+
if to_notify.empty?
|
18
|
+
logger.debug { "No notifications for #{type} #{name} with id #{id}" }
|
19
|
+
return
|
20
|
+
end
|
21
|
+
notification.notify(to_notify)
|
22
|
+
to_notify.each(&:update_notified)
|
23
|
+
rescue Berta::Errors::Entities::NoEmailError
|
24
|
+
logger.debug { "#{type} #{id} has no email, skipping" }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -3,7 +3,7 @@ module Berta
|
|
3
3
|
# Module for entity errors
|
4
4
|
module Entities
|
5
5
|
autoload :InvalidEntityXMLError, 'berta/errors/entities/invalid_entity_xml_error'
|
6
|
-
autoload :
|
6
|
+
autoload :NoEmailError, 'berta/errors/entities/no_email_error'
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'tilt'
|
3
|
+
require 'mail'
|
4
|
+
|
5
|
+
module Berta
|
6
|
+
# Class that encapsulates mailing functionality
|
7
|
+
class Notification
|
8
|
+
attr_accessor :name, :email, :template, :type
|
9
|
+
|
10
|
+
def initialize(name, email, type)
|
11
|
+
@type = type
|
12
|
+
@name = name
|
13
|
+
@email = email
|
14
|
+
@template = Tilt.new(Berta::Settings['email-template'])
|
15
|
+
raise Berta::Errors::Entities::NoEmailError, 'Notification requires email' \
|
16
|
+
unless email
|
17
|
+
end
|
18
|
+
|
19
|
+
def notify(vms)
|
20
|
+
text = template.render(Object.new, name: name, email: email, type: type, vms: vms_hash(vms))
|
21
|
+
logger.info "Sending mail to entity: #{name} on email: #{email}"
|
22
|
+
logger.debug { text }
|
23
|
+
Mail.new(text).deliver unless Berta::Settings['dry-run']
|
24
|
+
end
|
25
|
+
|
26
|
+
def vms_hash(vms)
|
27
|
+
vms.map do |vm|
|
28
|
+
{ id: vm.handle['ID'],
|
29
|
+
name: vm.handle['NAME'],
|
30
|
+
expiration: vm.default_expiration.time.to_i }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/berta/service.rb
CHANGED
@@ -61,7 +61,14 @@ module Berta
|
|
61
61
|
user_pool = OpenNebula::UserPool.new(client)
|
62
62
|
Berta::Utils::OpenNebula::Helper.handle_error { user_pool.info }
|
63
63
|
logger.debug "Fetched users: #{user_pool.map(&:id)}"
|
64
|
-
user_pool.map { |user| Berta::
|
64
|
+
user_pool.map { |user| Berta::EntityHandler.new(user) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def groups
|
68
|
+
group_pool = OpenNebula::GroupPool.new(client)
|
69
|
+
Berta::Utils::OpenNebula::Helper.handle_error { group_pool.info }
|
70
|
+
logger.debug "Fetched groups: #{group_pool.map(&:id)}"
|
71
|
+
group_pool.map { |group| Berta::EntityHandler.new(group) }
|
65
72
|
end
|
66
73
|
|
67
74
|
# Return vms that belong to given user
|
@@ -70,7 +77,11 @@ module Berta
|
|
70
77
|
# @param user [Berta::UserHandler] User to find vms for
|
71
78
|
# @return [Array<Berta::VirtualMachineHandler>] VMs that belong to given user
|
72
79
|
def user_vms(user)
|
73
|
-
running_vms.select { |vm| vm.handle['UID'] == user.
|
80
|
+
running_vms.select { |vm| vm.handle['UID'] == user.id }
|
81
|
+
end
|
82
|
+
|
83
|
+
def group_vms(group)
|
84
|
+
running_vms.select { |vm| vm.handle['GID'] == group.id }
|
74
85
|
end
|
75
86
|
|
76
87
|
# Fetch clusters from OpenNebula
|
data/lib/berta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dusan Baran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,89 +25,89 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: coveralls
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.8'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0.10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0.10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '11.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '11.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.5'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.42'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.42'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rubocop-rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '1.7'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '1.7'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: vcr
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,105 +123,105 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: webmock
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '2.3'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '2.3'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: chronic_duration
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '0.
|
145
|
+
version: '0.10'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '0.
|
152
|
+
version: '0.10'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: mail
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '2.
|
159
|
+
version: '2.6'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '2.
|
166
|
+
version: '2.6'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: opennebula
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '2
|
173
|
+
version: '5.2'
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '2
|
180
|
+
version: '5.2'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: settingslogic
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
187
|
+
version: '2.0'
|
188
188
|
type: :runtime
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
194
|
+
version: '2.0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: thor
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '0.
|
201
|
+
version: '0.19'
|
202
202
|
type: :runtime
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: '0.
|
208
|
+
version: '0.19'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
210
|
+
name: tilt
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - "~>"
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: '2.
|
215
|
+
version: '2.0'
|
216
216
|
type: :runtime
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: '2.
|
222
|
+
version: '2.0'
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
224
|
+
name: yell
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - "~>"
|
@@ -258,11 +258,12 @@ files:
|
|
258
258
|
- lib/berta/command_executor.rb
|
259
259
|
- lib/berta/entities.rb
|
260
260
|
- lib/berta/entities/expiration.rb
|
261
|
+
- lib/berta/entity_handler.rb
|
261
262
|
- lib/berta/errors.rb
|
262
263
|
- lib/berta/errors/backend_error.rb
|
263
264
|
- lib/berta/errors/entities.rb
|
264
265
|
- lib/berta/errors/entities/invalid_entity_xml_error.rb
|
265
|
-
- lib/berta/errors/entities/
|
266
|
+
- lib/berta/errors/entities/no_email_error.rb
|
266
267
|
- lib/berta/errors/opennebula.rb
|
267
268
|
- lib/berta/errors/opennebula/authentication_error.rb
|
268
269
|
- lib/berta/errors/opennebula/resource_not_found_error.rb
|
@@ -273,9 +274,9 @@ files:
|
|
273
274
|
- lib/berta/errors/standard_error.rb
|
274
275
|
- lib/berta/errors/wrong_filter_type_error.rb
|
275
276
|
- lib/berta/exclusions.rb
|
277
|
+
- lib/berta/notification.rb
|
276
278
|
- lib/berta/service.rb
|
277
279
|
- lib/berta/settings.rb
|
278
|
-
- lib/berta/user_handler.rb
|
279
280
|
- lib/berta/utils.rb
|
280
281
|
- lib/berta/utils/exclude_filter.rb
|
281
282
|
- lib/berta/utils/filter.rb
|
@@ -304,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
305
|
version: '0'
|
305
306
|
requirements: []
|
306
307
|
rubyforge_project:
|
307
|
-
rubygems_version: 2.6.
|
308
|
+
rubygems_version: 2.6.13
|
308
309
|
signing_key:
|
309
310
|
specification_version: 4
|
310
311
|
summary: Berta VM expiration tool
|
data/lib/berta/user_handler.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'mail'
|
2
|
-
require 'erb'
|
3
|
-
require 'tilt'
|
4
|
-
|
5
|
-
module Berta
|
6
|
-
# Class for handeling user methods
|
7
|
-
class UserHandler
|
8
|
-
attr_reader :handle
|
9
|
-
|
10
|
-
# Initializes UserHandler object
|
11
|
-
#
|
12
|
-
# @param user [OpenNebula::User] User that will this
|
13
|
-
# handle use
|
14
|
-
def initialize(user)
|
15
|
-
@handle = user
|
16
|
-
end
|
17
|
-
|
18
|
-
# Notifies user about all vms that are in notification interval
|
19
|
-
#
|
20
|
-
# @param user_vms [Array<Berta::VirtualMachineHandler>] All vms that belong to
|
21
|
-
# this user
|
22
|
-
# @param email_template [Tilt::ERBTemplate] Email template
|
23
|
-
def notify(user_vms, email_template)
|
24
|
-
to_notify = user_vms.keep_if(&:should_notify?)
|
25
|
-
if to_notify.empty?
|
26
|
-
logger.debug "No notifications for user #{handle['NAME']}"
|
27
|
-
return
|
28
|
-
end
|
29
|
-
send_notification(to_notify, email_template)
|
30
|
-
user_vms.each(&:update_notified)
|
31
|
-
rescue ArgumentError, Berta::Errors::Entities::NoUserEmailError => e
|
32
|
-
logger.error e.message
|
33
|
-
end
|
34
|
-
|
35
|
-
def send_notification(user_vms, email_template)
|
36
|
-
user_email = handle['TEMPLATE/EMAIL']
|
37
|
-
user_name = handle['NAME']
|
38
|
-
raise Berta::Errors::Entities::NoUserEmailError, "User: #{user_name} with id: #{handle['ID']} has no email set" \
|
39
|
-
unless user_email
|
40
|
-
email_text = email_template.render(Hash, user_email: user_email, user_name: user_name, vms: vms_data(user_vms))
|
41
|
-
logger.info "Sending mail to user: #{user_name} on email: #{user_email}"
|
42
|
-
logger.debug email_text
|
43
|
-
Mail.new(email_text).deliver unless Berta::Settings['dry-run']
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def vms_data(vms)
|
49
|
-
vms.map do |vm|
|
50
|
-
{ id: vm.handle['ID'],
|
51
|
-
name: vm.handle['NAME'],
|
52
|
-
expiration: vm.default_expiration.time.to_i }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|