egi-fedcloud-vmhound 0.0.3 → 0.0.4
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/bin/egi-fedcloud-vmhound +13 -10
- data/config/settings.yml +3 -3
- data/lib/egi/fedcloud/vmhound/connectors/base_connector.rb +2 -2
- data/lib/egi/fedcloud/vmhound/connectors/dummy_connector.rb +2 -2
- data/lib/egi/fedcloud/vmhound/connectors/opennebula_connector.rb +8 -8
- data/lib/egi/fedcloud/vmhound/extractor.rb +3 -3
- data/lib/egi/fedcloud/vmhound/formatter.rb +39 -18
- data/lib/egi/fedcloud/vmhound/version.rb +1 -1
- 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: 29a4951b4b00abba293dba93b23a58adba7180bb
|
4
|
+
data.tar.gz: ae139838f5f0ab021364674fd7e7cd6afa15dede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b56664baf23c15eff28ee89e9e6452a72ac44e5c8d462a639cd53b5b12e5c42287f8f57a64dc3534e65f83c2bbf8fd42b07130d466f53682fa7cf77a89e56a
|
7
|
+
data.tar.gz: 939a73c56afafda06d4847676e7939d46bef7701483049cba814c1e612d6e2a1bb4b69e38635d568293b901f5a58e2457702dce0a09cd81f08a5c8d9a8b69a39
|
data/bin/egi-fedcloud-vmhound
CHANGED
@@ -23,6 +23,8 @@ class EgiFedcloudVmhound < Thor
|
|
23
23
|
include Thor::Actions
|
24
24
|
|
25
25
|
desc "ip IP_ADDRESS", "Prints information based on the provided IP address or IP address range"
|
26
|
+
method_option :format, :type => :string, :default => Egi::Fedcloud::Vmhound::Settings.format,
|
27
|
+
:enum => Egi::Fedcloud::Vmhound::Formatter::FORMATS, :aliases => '-o', :desc => 'Output formatting'
|
26
28
|
method_option :cmf, :type => :string, :default => Egi::Fedcloud::Vmhound::Settings.cmf,
|
27
29
|
:aliases => '-c', :desc => 'Type of the underlying CMF'
|
28
30
|
method_option :endpoint, :type => :string, :default => nil,
|
@@ -37,14 +39,13 @@ class EgiFedcloudVmhound < Thor
|
|
37
39
|
:aliases => '-x', :desc => 'Directory path to all trusted CA certificates'
|
38
40
|
method_option :insecure, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.insecure,
|
39
41
|
:aliases => '-k', :desc => 'Enable insecure mode for SSL (no peer validation)'
|
40
|
-
method_option :details, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.details,
|
41
|
-
:aliases => '-l', :desc => 'Enable wide tables with more details (off by default)'
|
42
42
|
method_option :debug, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.debug,
|
43
43
|
:aliases => '-d', :desc => 'Enable debugging'
|
44
44
|
def ip(ip_address)
|
45
45
|
init_log options[:debug]
|
46
46
|
|
47
|
-
$stdout.puts Egi::Fedcloud::Vmhound::Formatter.
|
47
|
+
$stdout.puts Egi::Fedcloud::Vmhound::Formatter.send(
|
48
|
+
"as_#{options[:format]}",
|
48
49
|
Egi::Fedcloud::Vmhound::Extractor.find_by_ip(
|
49
50
|
ip_address,
|
50
51
|
options
|
@@ -54,6 +55,8 @@ class EgiFedcloudVmhound < Thor
|
|
54
55
|
end
|
55
56
|
|
56
57
|
desc "appuri URI", "Prints information based on the provided Appliance MPURI"
|
58
|
+
method_option :format, :type => :string, :default => Egi::Fedcloud::Vmhound::Settings.format,
|
59
|
+
:enum => Egi::Fedcloud::Vmhound::Formatter::FORMATS, :aliases => '-o', :desc => 'Output formatting'
|
57
60
|
method_option :cmf, :type => :string, :default => Egi::Fedcloud::Vmhound::Settings.cmf,
|
58
61
|
:aliases => '-c', :desc => 'Type of the underlying CMF'
|
59
62
|
method_option :endpoint, :type => :string, :default => nil,
|
@@ -68,14 +71,13 @@ class EgiFedcloudVmhound < Thor
|
|
68
71
|
:aliases => '-x', :desc => 'Directory path to all trusted CA certificates'
|
69
72
|
method_option :insecure, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.insecure,
|
70
73
|
:aliases => '-k', :desc => 'Enable insecure mode for SSL (no peer validation)'
|
71
|
-
method_option :details, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.details,
|
72
|
-
:aliases => '-l', :desc => 'Enable wide tables with more details (off by default)'
|
73
74
|
method_option :debug, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.debug,
|
74
75
|
:aliases => '-d', :desc => 'Enable debugging'
|
75
76
|
def appuri(uri)
|
76
77
|
init_log options[:debug]
|
77
78
|
|
78
|
-
$stdout.puts Egi::Fedcloud::Vmhound::Formatter.
|
79
|
+
$stdout.puts Egi::Fedcloud::Vmhound::Formatter.send(
|
80
|
+
"as_#{options[:format]}",
|
79
81
|
Egi::Fedcloud::Vmhound::Extractor.find_by_appuri(
|
80
82
|
uri,
|
81
83
|
options
|
@@ -85,6 +87,8 @@ class EgiFedcloudVmhound < Thor
|
|
85
87
|
end
|
86
88
|
|
87
89
|
desc "user ID", "Prints information based on the provided user identifier"
|
90
|
+
method_option :format, :type => :string, :default => Egi::Fedcloud::Vmhound::Settings.format,
|
91
|
+
:enum => Egi::Fedcloud::Vmhound::Formatter::FORMATS, :aliases => '-o', :desc => 'Output formatting'
|
88
92
|
method_option :cmf, :type => :string, :default => Egi::Fedcloud::Vmhound::Settings.cmf,
|
89
93
|
:aliases => '-c', :desc => 'Type of the underlying CMF'
|
90
94
|
method_option :endpoint, :type => :string, :default => nil,
|
@@ -99,14 +103,13 @@ class EgiFedcloudVmhound < Thor
|
|
99
103
|
:aliases => '-x', :desc => 'Directory path to all trusted CA certificates'
|
100
104
|
method_option :insecure, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.insecure,
|
101
105
|
:aliases => '-k', :desc => 'Enable insecure mode for SSL (no peer validation)'
|
102
|
-
method_option :details, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.details,
|
103
|
-
:aliases => '-l', :desc => 'Enable wide tables with more details (off by default)'
|
104
106
|
method_option :debug, :type => :boolean, :default => Egi::Fedcloud::Vmhound::Settings.debug,
|
105
107
|
:aliases => '-d', :desc => 'Enable debugging'
|
106
108
|
def user(id)
|
107
109
|
init_log options[:debug]
|
108
110
|
|
109
|
-
$stdout.puts Egi::Fedcloud::Vmhound::Formatter.
|
111
|
+
$stdout.puts Egi::Fedcloud::Vmhound::Formatter.send(
|
112
|
+
"as_#{options[:format]}",
|
110
113
|
Egi::Fedcloud::Vmhound::Extractor.find_by_user(
|
111
114
|
id,
|
112
115
|
options
|
@@ -129,7 +132,7 @@ class EgiFedcloudVmhound < Thor
|
|
129
132
|
# @return [Egi::Fedcloud::Vmhound::Log] logger instance for additional configuration
|
130
133
|
def init_log(debug = false)
|
131
134
|
logger = Egi::Fedcloud::Vmhound::Log.new(STDERR)
|
132
|
-
logger.level = debug ? Egi::Fedcloud::Vmhound::Log::DEBUG : Egi::Fedcloud::Vmhound::Log::
|
135
|
+
logger.level = debug ? Egi::Fedcloud::Vmhound::Log::DEBUG : Egi::Fedcloud::Vmhound::Log::WARN
|
133
136
|
logger
|
134
137
|
end
|
135
138
|
end
|
data/config/settings.yml
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
---
|
2
2
|
production:
|
3
|
+
format: table
|
3
4
|
cmf: opennebula
|
4
5
|
ca_path: '/etc/grid-security/certificates'
|
5
6
|
insecure: false
|
6
|
-
details: false
|
7
7
|
debug: false
|
8
8
|
|
9
9
|
development:
|
10
|
+
format: table
|
10
11
|
cmf: opennebula
|
11
12
|
ca_path: '/etc/grid-security/certificates'
|
12
13
|
insecure: true
|
13
|
-
details: true
|
14
14
|
debug: true
|
15
15
|
|
16
16
|
test:
|
17
|
+
format: table
|
17
18
|
cmf: dummy
|
18
19
|
ca_path: '/etc/grid-security/certificates'
|
19
20
|
insecure: true
|
20
|
-
details: true
|
21
21
|
debug: true
|
@@ -13,12 +13,12 @@ class Egi::Fedcloud::Vmhound::Connectors::BaseConnector
|
|
13
13
|
# included.
|
14
14
|
#
|
15
15
|
# @return [Array<Hash>] List of instances, each represented as a hash
|
16
|
-
def
|
16
|
+
def instances; end
|
17
17
|
|
18
18
|
# Retrieves running instances from the underlying CMF. Only currently
|
19
19
|
# running instances will be included.
|
20
20
|
#
|
21
21
|
# @return [Array<Hash>] List of instances, each represented as a hash
|
22
|
-
def
|
22
|
+
def active_instances; end
|
23
23
|
|
24
24
|
end
|
@@ -6,7 +6,7 @@ class Egi::Fedcloud::Vmhound::Connectors::DummyConnector < Egi::Fedcloud::Vmhoun
|
|
6
6
|
# included.
|
7
7
|
#
|
8
8
|
# @return [Array<Hash>] List of instances, each represented as a hash
|
9
|
-
def
|
9
|
+
def instances
|
10
10
|
Egi::Fedcloud::Vmhound::Log.info "[#{self.class}] Retrieving active instances"
|
11
11
|
[]
|
12
12
|
end
|
@@ -15,7 +15,7 @@ class Egi::Fedcloud::Vmhound::Connectors::DummyConnector < Egi::Fedcloud::Vmhoun
|
|
15
15
|
# running instances will be included.
|
16
16
|
#
|
17
17
|
# @return [Array<Hash>] List of instances, each represented as a hash
|
18
|
-
def
|
18
|
+
def active_instances
|
19
19
|
Egi::Fedcloud::Vmhound::Log.info "[#{self.class}] Retrieving running instances"
|
20
20
|
[]
|
21
21
|
end
|
@@ -41,18 +41,18 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
|
|
41
41
|
# included.
|
42
42
|
#
|
43
43
|
# @return [Array<Hash>] List of instances, each represented as a hash
|
44
|
-
def
|
44
|
+
def instances
|
45
45
|
Egi::Fedcloud::Vmhound::Log.info "[#{self.class}] Retrieving active instances"
|
46
|
-
|
46
|
+
fetch_instances
|
47
47
|
end
|
48
48
|
|
49
49
|
# Retrieves running instances from the underlying OpenNebula. Only currently
|
50
50
|
# running instances will be included.
|
51
51
|
#
|
52
52
|
# @return [Array<Hash>] List of instances, each represented as a hash
|
53
|
-
def
|
53
|
+
def active_instances
|
54
54
|
Egi::Fedcloud::Vmhound::Log.info "[#{self.class}] Retrieving running instances"
|
55
|
-
|
55
|
+
fetch_instances ['ACTIVE']
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
@@ -62,14 +62,14 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
|
|
62
62
|
# @param allow_states [Array<String>] a list of allowed states
|
63
63
|
# @param reject_states [Array<String>] a list of states to be rejected
|
64
64
|
# @return [Array<Hash>] a list of instances matching given criteria
|
65
|
-
def
|
65
|
+
def fetch_instances(allow_states = nil, reject_states = nil)
|
66
66
|
Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Retrieving instances: " \
|
67
67
|
"allow_states=#{allow_states.inspect} & " \
|
68
68
|
"reject_states=#{reject_states.inspect}"
|
69
69
|
return if allow_states && allow_states.empty?
|
70
70
|
reject_states ||= []
|
71
71
|
|
72
|
-
@vm_pool_ary =
|
72
|
+
@vm_pool_ary = fetch_instances_batch_pool(@vm_pool) unless @vm_pool_ary
|
73
73
|
|
74
74
|
vms = []
|
75
75
|
@vm_pool_ary.each do |vm|
|
@@ -91,7 +91,7 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
|
|
91
91
|
#
|
92
92
|
# @param vm_pool [OpenNebula::VirtualMachinePool] ONe pool instance
|
93
93
|
# @return [Array<OpenNebula::VirtualMachine>] a list of VM instances
|
94
|
-
def
|
94
|
+
def fetch_instances_batch_pool(vm_pool)
|
95
95
|
fail 'Pool object not provided!' unless vm_pool
|
96
96
|
Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Iterating over the VM " \
|
97
97
|
"pool without batch processing"
|
@@ -266,7 +266,7 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
|
|
266
266
|
fail 'User object not provided!' unless opennebula_user
|
267
267
|
{
|
268
268
|
id: opennebula_user['ID'].to_i,
|
269
|
-
name: opennebula_user['TEMPLATE/NAME'],
|
269
|
+
name: opennebula_user['TEMPLATE/NAME'] || opennebula_user['NAME'],
|
270
270
|
identities: canonical_user_identities(opennebula_user),
|
271
271
|
email: opennebula_user['TEMPLATE/EMAIL'],
|
272
272
|
groups: [
|
@@ -22,21 +22,21 @@ class Egi::Fedcloud::Vmhound::Extractor
|
|
22
22
|
def find_by_ip(ip, options = {})
|
23
23
|
env_init options
|
24
24
|
Egi::Fedcloud::Vmhound::Log.debug "[#{self}] Searching for instances by IP: #{ip.inspect}"
|
25
|
-
@@connector.
|
25
|
+
@@connector.instances.select { |instance| instance[:ips] && instance[:ips].include?(ip) }
|
26
26
|
end
|
27
27
|
|
28
28
|
#
|
29
29
|
def find_by_appuri(uri, options = {})
|
30
30
|
env_init options
|
31
31
|
Egi::Fedcloud::Vmhound::Log.debug "[#{self}] Searching for instances by MPURI: #{uri.inspect}"
|
32
|
-
@@connector.
|
32
|
+
@@connector.instances.select { |instance| instance[:appliance] && instance[:appliance][:identifiers].include?(uri) }
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
36
36
|
def find_by_user(id, options = {})
|
37
37
|
env_init options
|
38
38
|
Egi::Fedcloud::Vmhound::Log.debug "[#{self}] Searching for instances by user ID: #{id.inspect}"
|
39
|
-
@@connector.
|
39
|
+
@@connector.instances.select { |instance| instance[:owner] && instance[:owner][:identities].include?(id) }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -3,33 +3,29 @@ require 'terminal-table'
|
|
3
3
|
#
|
4
4
|
class Egi::Fedcloud::Vmhound::Formatter
|
5
5
|
|
6
|
+
FORMATS = %w(table json plain).freeze
|
7
|
+
LINE_SEPARATOR = "\n\t".freeze
|
8
|
+
RECORD_SEPARATOR = "\n\n".freeze
|
9
|
+
|
6
10
|
class << self
|
7
11
|
#
|
8
12
|
def as_table(data, opts = {})
|
9
|
-
data ||= []
|
10
13
|
Egi::Fedcloud::Vmhound::Log.debug "[#{self}] Transforming #{data.inspect} into a table"
|
14
|
+
|
15
|
+
data ||= []
|
11
16
|
table = Terminal::Table.new
|
12
17
|
|
13
|
-
|
14
|
-
' >>> VM ID <<< ', ' >>> Contact <<< ',
|
15
|
-
' >>>
|
18
|
+
table.add_row [
|
19
|
+
' >>> VM ID <<< ', ' >>> Group <<< ', ' >>> Contact <<< ',
|
20
|
+
' >>> Host <<< ', ' >>> State <<< ',
|
16
21
|
]
|
17
|
-
thead.concat [
|
18
|
-
' >>> Owner Identity <<< ', ' >>> Group <<< ', ' >>> IPs <<< '
|
19
|
-
] if opts[:details]
|
20
|
-
|
21
|
-
table.add_row thead
|
22
22
|
table.add_separator
|
23
23
|
data.each do |vm|
|
24
24
|
table.add_separator
|
25
|
-
|
26
|
-
vm[:id], vm[:
|
25
|
+
table.add_row [
|
26
|
+
vm[:id], vm[:group], vm[:owner][:email],
|
27
|
+
vm[:host], vm[:state]
|
27
28
|
]
|
28
|
-
tbody.concat [
|
29
|
-
vm[:owner][:identities].join("\n"),
|
30
|
-
vm[:group], vm[:ips].join("\n")
|
31
|
-
] if opts[:details]
|
32
|
-
table.add_row tbody
|
33
29
|
end
|
34
30
|
|
35
31
|
table
|
@@ -37,8 +33,33 @@ class Egi::Fedcloud::Vmhound::Formatter
|
|
37
33
|
|
38
34
|
#
|
39
35
|
def as_json(data, opts = {})
|
40
|
-
data
|
41
|
-
|
36
|
+
Egi::Fedcloud::Vmhound::Log.debug "[#{self}] Transforming #{data.inspect} into a JSON document"
|
37
|
+
return '{}' if data.blank?
|
38
|
+
|
39
|
+
JSON.generate(data)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
def as_plain(data, opts = {})
|
44
|
+
Egi::Fedcloud::Vmhound::Log.debug "[#{self}] Transforming #{data.inspect} into plain text"
|
45
|
+
return '' if data.blank?
|
46
|
+
|
47
|
+
lines = {}
|
48
|
+
data.each do |vm|
|
49
|
+
Egi::Fedcloud::Vmhound::Log.warn "[#{self}] #{vm[:owner][:name]} doesn't " \
|
50
|
+
"have a contact e-mail! VM[#{vm[:id]}]" if vm[:owner][:email].blank?
|
51
|
+
next if vm[:owner][:email].blank?
|
52
|
+
|
53
|
+
line_key = "\"#{vm[:owner][:name]} in #{vm[:owner][:groups].first}\" <#{vm[:owner][:email]}>"
|
54
|
+
lines[line_key] ||= []
|
55
|
+
lines[line_key] << "#{vm[:id]} is #{vm[:state]} on #{vm[:host]}"
|
56
|
+
end
|
57
|
+
|
58
|
+
plain = []
|
59
|
+
lines.each_pair do |line_key, line_vals|
|
60
|
+
plain << "#{line_key}: #{line_vals.count} VMs#{LINE_SEPARATOR}#{line_vals.join LINE_SEPARATOR}"
|
61
|
+
end
|
62
|
+
plain.join RECORD_SEPARATOR
|
42
63
|
end
|
43
64
|
end
|
44
65
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: egi-fedcloud-vmhound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Parak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|