berta 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/berta.gemspec +1 -1
- data/lib/berta/expiration_manager.rb +22 -21
- data/lib/berta/virtual_machine_handler.rb +9 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4e81e829b874c07ff7ab8ae0226238d5baa52b4
|
4
|
+
data.tar.gz: 99b0e83b23f5213db848f45403b8c901071a6c8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a6e7deea100c608d490391b4f3f3377f1771139399f7917c074c4d2faea12e5c905923568b68855c3bbe6718338e1d5c50b9d8a3db8adb2cd68c0e7b644062
|
7
|
+
data.tar.gz: df347f0d85a29be79b8c5152e5c13c9ed9de2a3201a3add8c7ebde8f34aad4888705fa146b40d62ba17d38e2b949851e1b12116940459a8372848bc4aaef079d
|
data/README.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
[](https://codeclimate.com/github/dudoslav/berta)
|
6
6
|
[](http://inch-ci.org/github/dudoslav/berta)
|
7
7
|
[](https://gemnasium.com/github.com/dudoslav/berta)
|
8
|
+
[](https://badge.fury.io/rb/berta)
|
8
9
|
|
9
10
|
Berta cleans cloud from unused vms. She sets expiration to all virtual machines
|
10
11
|
and when expiration is close she will notify owners. Berta is developed as ruby gem.
|
@@ -23,7 +24,7 @@ From source:
|
|
23
24
|
|
24
25
|
```bash
|
25
26
|
git clone git://github.com/dudoslav/berta.git
|
26
|
-
cd
|
27
|
+
cd berta
|
27
28
|
gem install bundler
|
28
29
|
bundle install
|
29
30
|
```
|
@@ -33,7 +34,7 @@ bundle install
|
|
33
34
|
Config files can be located in:
|
34
35
|
* `~/.berta/berta.yml`
|
35
36
|
* `/etc/berta/berta.yml`
|
36
|
-
* `PATH_TO_GEM_DIR/config/
|
37
|
+
* `PATH_TO_GEM_DIR/config/berta.yml`
|
37
38
|
|
38
39
|
### Execution
|
39
40
|
|
data/berta.gemspec
CHANGED
@@ -8,35 +8,36 @@ module Berta
|
|
8
8
|
# to update expiration on.
|
9
9
|
def update_expirations(vms)
|
10
10
|
vms.each do |vm|
|
11
|
-
|
12
|
-
|
11
|
+
begin
|
12
|
+
vm.update_expirations(add_default_expiration(vm, remove_invalid_expirations(vm.expirations)))
|
13
|
+
rescue Berta::Errors::BackendError => e
|
14
|
+
logger.error "#{e.message}\n\tOn vm with id #{vm.handle['ID']}"
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
# Removes invalid expirations
|
17
|
-
#
|
19
|
+
# Removes invalid expirations from array of expirations.
|
20
|
+
# Invalid expirations are expirations that are planned
|
21
|
+
# later than expiration offset value.
|
18
22
|
#
|
19
|
-
# @param
|
20
|
-
#
|
21
|
-
def remove_invalid_expirations(
|
22
|
-
exps = vm.expirations
|
23
|
+
# @param exps [Array<Berta::Entities::Expiration>] Expirations to filter
|
24
|
+
# @return [Array<Berta::Entities::Expiration>] Filtered expirations
|
25
|
+
def remove_invalid_expirations(exps)
|
23
26
|
exps.keep_if(&:in_expiration_interval?)
|
24
|
-
vm.update_expirations(exps) if exps.length != vm.expirations.length
|
25
|
-
rescue Berta::Errors::BackendError => e
|
26
|
-
logger.error "#{e.message}\n\tOn vm with id #{vm.handle['ID']}"
|
27
27
|
end
|
28
28
|
|
29
|
-
# Adds default expiration
|
30
|
-
#
|
29
|
+
# Adds default vm expiration into given array of expirations
|
30
|
+
# assuming that array of expirations are expirations of given vm.
|
31
|
+
# If vm already has default expiration nothing will be changed.
|
31
32
|
#
|
32
|
-
# @param vm [Berta::VirtualMachineHandler]
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
# @param vm [Berta::VirtualMachineHandler] VM with or without default expiration
|
34
|
+
# @param exps [Array<Berta::Entities::Expiration>] VMs expirations to modify
|
35
|
+
# @return Expirations with default expiration
|
36
|
+
def add_default_expiration(vm, exps)
|
37
|
+
return exps if vm.default_expiration
|
38
|
+
exps << Berta::Entities::Expiration.new(vm.next_expiration_id,
|
39
|
+
Time.now.to_i + Berta::Settings.expiration_offset,
|
40
|
+
Berta::Settings.expiration.action)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Berta
|
2
2
|
# Class for Berta operations on virtual machines
|
3
3
|
class VirtualMachineHandler
|
4
|
+
NOTIFIED_FLAG = 'BERTA_NOTIFIED'.freeze
|
5
|
+
|
4
6
|
attr_reader :handle
|
5
7
|
|
6
8
|
# Constructs Virtual machine handler from given vm.
|
@@ -22,10 +24,11 @@ module Berta
|
|
22
24
|
# @raise [Berta::Errors::OpenNebula::ResourceStateError]
|
23
25
|
# @raise [Berta::Errors::OpenNebula::ResourceRetrievalError]
|
24
26
|
def update_notified
|
25
|
-
|
27
|
+
notify_time = Time.now
|
28
|
+
logger.debug "Setting notified flag of VM with id #{handle['ID']} to #{notify_time}"
|
26
29
|
return if Berta::Settings['dry-run']
|
27
30
|
Berta::Utils::OpenNebula::Helper.handle_error do
|
28
|
-
handle.update("
|
31
|
+
handle.update("#{NOTIFIED_FLAG} = #{notify_time.to_i}", true)
|
29
32
|
handle.info
|
30
33
|
end
|
31
34
|
end
|
@@ -36,7 +39,7 @@ module Berta
|
|
36
39
|
# @return [Numeric] Time when notified was set else nil.
|
37
40
|
# Time is in UNIX epoch time format.
|
38
41
|
def notified
|
39
|
-
time = handle[
|
42
|
+
time = handle["USER_TEMPLATE/#{NOTIFIED_FLAG}"]
|
40
43
|
time.to_i if time
|
41
44
|
end
|
42
45
|
|
@@ -54,23 +57,6 @@ module Berta
|
|
54
57
|
expiration.in_notification_interval?
|
55
58
|
end
|
56
59
|
|
57
|
-
# Adds schelude action to virtual machine. This command
|
58
|
-
# modifies USER_TEMPLATE of virtual machine. But does
|
59
|
-
# not delete old variables is USER_TEMPLATE.
|
60
|
-
#
|
61
|
-
# @note This method modifies OpenNebula database
|
62
|
-
# @param time [Numeric] Time when to notify user
|
63
|
-
# @param action [String] Action to perform on expiration
|
64
|
-
def add_expiration(time, action)
|
65
|
-
logger.debug "Setting expiration date of #{handle['ID']} to #{action} on #{time} with id #{next_sched_action_id}"
|
66
|
-
return if Berta::Settings['dry-run']
|
67
|
-
new_expiration = \
|
68
|
-
Berta::Entities::Expiration.new(next_sched_action_id,
|
69
|
-
time,
|
70
|
-
action)
|
71
|
-
update_expirations(expirations << new_expiration)
|
72
|
-
end
|
73
|
-
|
74
60
|
# Sets array of expirations to vm, rewrites all old ones.
|
75
61
|
# Receiving empty array wont change anything.
|
76
62
|
#
|
@@ -79,6 +65,7 @@ module Berta
|
|
79
65
|
def update_expirations(exps)
|
80
66
|
template = ''
|
81
67
|
exps.each { |exp| template += exp.template }
|
68
|
+
return if template == ''
|
82
69
|
logger.debug "Setting multiple expirations:\n#{template}"
|
83
70
|
return if Berta::Settings['dry-run']
|
84
71
|
Berta::Utils::OpenNebula::Helper.handle_error do
|
@@ -109,9 +96,8 @@ module Berta
|
|
109
96
|
.min { |exp| exp.time.to_i }
|
110
97
|
end
|
111
98
|
|
112
|
-
|
113
|
-
|
114
|
-
def next_sched_action_id
|
99
|
+
# TODO
|
100
|
+
def next_expiration_id
|
115
101
|
elems = handle.retrieve_elements('USER_TEMPLATE/SCHED_ACTION/ID')
|
116
102
|
return 0 unless elems
|
117
103
|
elems.to_a.max.to_i + 1
|
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: 1.
|
4
|
+
version: 1.1.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-02-
|
11
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|