egi-fedcloud-vmhound 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29a4951b4b00abba293dba93b23a58adba7180bb
4
- data.tar.gz: ae139838f5f0ab021364674fd7e7cd6afa15dede
3
+ metadata.gz: aa4eb6dedfd6c0c0da42d64722f528b1f3731cab
4
+ data.tar.gz: 1fa2317b48bccc8dde25efa50caf66851390cbe7
5
5
  SHA512:
6
- metadata.gz: 92b56664baf23c15eff28ee89e9e6452a72ac44e5c8d462a639cd53b5b12e5c42287f8f57a64dc3534e65f83c2bbf8fd42b07130d466f53682fa7cf77a89e56a
7
- data.tar.gz: 939a73c56afafda06d4847676e7939d46bef7701483049cba814c1e612d6e2a1bb4b69e38635d568293b901f5a58e2457702dce0a09cd81f08a5c8d9a8b69a39
6
+ metadata.gz: 309e16398fe2852c1382704c4dcb2c726c2e32c0640aee50828fedd5f0265c4ae361f5d8e70e3ef75da50f72082fefcd5fc84247609ae1c0207b447ae23b619b
7
+ data.tar.gz: 864c1d2514cbb6cdfa6ca44a89d4407f8b661a212b219c7fb771f483a34d0a228ad805f8992e619145f3cf25b0f3161ca10dde8dd7f95454025322248842b820
data/README.md CHANGED
@@ -3,10 +3,73 @@
3
3
  [![Gem Version](https://fury-badge.herokuapp.com/rb/egi-fedcloud-vmhound.png)](https://badge.fury.io/rb/egi-fedcloud-vmhound)
4
4
  [![Code Climate](https://codeclimate.com/github/arax/egi-fedcloud-vmhound.png)](https://codeclimate.com/github/arax/egi-fedcloud-vmhound)
5
5
 
6
- # EGI FedCloud CloudHound
6
+ # EGI FedCloud VMHound
7
7
 
8
8
  A proof-of-concept utility for locating VM instances in EGI Federated Cloud.
9
9
 
10
+ ## Installation
11
+ ### Dependencies
12
+ * __Debian-based__
13
+ ```bash
14
+ $ sudo apt-get install ruby ruby-dev libxml2 build-essential
15
+ ```
16
+ * __RHEL-based__
17
+ ```bash
18
+ $ sudo yum install ruby ruby-devel libxml2
19
+ ```
20
+
21
+ ### From RubyGems.org
22
+ ```bash
23
+ $ gem install egi-fedcloud-vmhound
24
+ $ egi-fedcloud-vmhound help
25
+ ```
26
+
27
+ ### From Source
28
+ ```bash
29
+ $ git clone https://github.com/arax/egi-fedcloud-vmhound.git
30
+ $ cd egi-fedcloud-vmhound
31
+ $ gem install bundler
32
+ $ bundle install
33
+ $ bundle exec bin/egi-fedcloud-vmhound help
34
+ ```
35
+
36
+ ## Usage
37
+ ```bash
38
+ $ egi-fedcloud-vmhound help
39
+ Commands:
40
+ egi-fedcloud-vmhound appuri URI # Prints information based on the provided Appliance MPURI
41
+ egi-fedcloud-vmhound help [COMMAND] # Describe available commands or one specific command
42
+ egi-fedcloud-vmhound ip IP_ADDRESS # Prints information based on the provided IP address or IP address range
43
+ egi-fedcloud-vmhound user ID # Prints information based on the provided user identifier
44
+ ```
45
+
46
+ ```bash
47
+ $ egi-fedcloud-vmhound help user
48
+
49
+ $ USER_DN="/DC=cz/DC=cesnet-ca/O=CESNET/CN=John Doe"
50
+ $ egi-fedcloud-vmhound user $USER_DN
51
+ $ egi-fedcloud-vmhound user $USER_DN --format=plain
52
+ $ egi-fedcloud-vmhound user $USER_DN --format=json
53
+ ```
54
+
55
+ ```bash
56
+ $ egi-fedcloud-vmhound help appuri
57
+
58
+ $ MPURI="https://appdb.egi.eu/store/vo/image/ac34bc96-4d78-583a-b73b-a9102aeec206:403/"
59
+ $ egi-fedcloud-vmhound appuri $MPURI
60
+ $ egi-fedcloud-vmhound appuri $MPURI --format=plain
61
+ $ egi-fedcloud-vmhound appuri $MPURI --format=json
62
+ ```
63
+
64
+ ```bash
65
+ $ egi-fedcloud-vmhound help ip
66
+
67
+ $ IP_ADDRESS="192.168.5.0/24" # range or host IP
68
+ $ egi-fedcloud-vmhound ip $IP_ADDRESS
69
+ $ egi-fedcloud-vmhound ip $IP_ADDRESS --format=plain
70
+ $ egi-fedcloud-vmhound ip $IP_ADDRESS --format=json
71
+ ```
72
+
10
73
  ## Contributing
11
74
 
12
75
  1. Fork it ( https://github.com/arax/egi-fedcloud-vmhound/fork )
@@ -9,31 +9,13 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
9
9
  def initialize(opts = {})
10
10
  super
11
11
 
12
- secret = if opts[:username] && opts[:password]
13
- Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Using provided plain credentials"
14
- "#{opts[:username]}:#{opts[:password]}"
15
- else
16
- Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Falling back to file and environment credentials"
17
- opts[:auth_file] ? File.read(opts[:auth_file]) : nil
18
- end
19
- secret.strip! if secret
20
-
21
12
  options = {}
22
13
  options[:sync] = true
23
14
  # TODO: fix https://github.com/OpenNebula/one/blob/ced1a29bfb3f3d1991ea88e658ea9462071fe4b8/src/oca/ruby/opennebula/client.rb#L166
24
15
  #options[:cert_dir] = opts[:ca_path] unless opts[:ca_path].blank?
25
16
  options[:disable_ssl_verify] = opts[:insecure]
26
17
 
27
- client = OpenNebula::Client.new(secret, opts[:endpoint], options)
28
-
29
- @vm_pool = OpenNebula::VirtualMachinePool.new(client)
30
- @vm_pool_ary = nil
31
-
32
- @image_pool = OpenNebula::ImagePool.new(client)
33
- @canonical_image_pool = nil
34
-
35
- @user_pool = OpenNebula::UserPool.new(client)
36
- @canonical_user_pool = nil
18
+ initialize_pools initialize_secret(opts), opts, options
37
19
  end
38
20
 
39
21
  # Retrieves active instances from the underlying OpenNebula. Including instances
@@ -57,9 +39,47 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
57
39
 
58
40
  private
59
41
 
42
+ # Processes options and extracts the secret used to connect to
43
+ # OpenNebula. This can be username & password, file with a token,
44
+ # or nothing (`nil`).
45
+ #
46
+ # @param opts [Hash] hash with options
47
+ # @return [NilClass, String] constructed secret
48
+ def initialize_secret(opts = {})
49
+ secret = if opts[:username] && opts[:password]
50
+ Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Using provided plain credentials"
51
+ "#{opts[:username]}:#{opts[:password]}"
52
+ else
53
+ Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Falling back to file and environment credentials"
54
+ opts[:auth_file] ? File.read(opts[:auth_file]) : nil
55
+ end
56
+ secret.strip! if secret
57
+ secret
58
+ end
59
+
60
+ # Initializes client instance and corresponding OpenNebula
61
+ # resource pools and caches.
62
+ #
63
+ # @param secret [String, NilClass] authentication secret
64
+ # @param opts [Hash] user-defined options
65
+ # @param options [Hash] computed options for ONe client
66
+ # @return [NilClass] nothing
67
+ def initialize_pools(secret, opts = {}, options = {})
68
+ client = OpenNebula::Client.new(secret, opts[:endpoint], options)
69
+
70
+ @vm_pool = OpenNebula::VirtualMachinePool.new(client)
71
+ @vm_pool_ary = nil
72
+
73
+ @image_pool = OpenNebula::ImagePool.new(client)
74
+ @canonical_image_pool = nil
75
+
76
+ @user_pool = OpenNebula::UserPool.new(client)
77
+ @canonical_user_pool = nil
78
+ end
79
+
60
80
  # Retrieves a list of instances matching given criteria.
61
81
  #
62
- # @param allow_states [Array<String>] a list of allowed states
82
+ # @param allow_states [Array<String>] a list of allowed states, `nil` represents all
63
83
  # @param reject_states [Array<String>] a list of states to be rejected
64
84
  # @return [Array<Hash>] a list of instances matching given criteria
65
85
  def fetch_instances(allow_states = nil, reject_states = nil)
@@ -69,20 +89,25 @@ class Egi::Fedcloud::Vmhound::Connectors::OpennebulaConnector < Egi::Fedcloud::V
69
89
  return if allow_states && allow_states.empty?
70
90
  reject_states ||= []
71
91
 
72
- @vm_pool_ary = fetch_instances_batch_pool(@vm_pool) unless @vm_pool_ary
73
-
74
- vms = []
75
- @vm_pool_ary.each do |vm|
76
- if reject_states.include? vm.state_str
77
- Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Rejecting VM #{vm['ID']} " \
78
- "-- #{vm.state_str}"
79
- next
80
- end
92
+ @vm_pool_ary ||= fetch_instances_batch_pool(@vm_pool)
93
+ @vm_pool_ary.collect { |vm| fetch_instances_vm(vm, allow_states, reject_states) }.compact
94
+ end
81
95
 
82
- vms << canonical_instance(vm) if (allow_states.nil? || (allow_states && allow_states.include?(vm.state_str)))
96
+ # Applies given selection criteria and returns canonical representation
97
+ # of a VM or `nil`.
98
+ #
99
+ # @param vm [OpenNebula::VirtualMachine] VM instance from OpenNebula
100
+ # @param allow_states [NilClass, Array] allowed VM states, `nil` represents all
101
+ # @param reject_states [Array] reject VMs in given states
102
+ # @return [NilClass, Hash] normalized VM instance structure
103
+ def fetch_instances_vm(vm, allow_states, reject_states)
104
+ if reject_states.include? vm.state_str
105
+ Egi::Fedcloud::Vmhound::Log.debug "[#{self.class}] Rejecting VM #{vm['ID']} " \
106
+ "-- #{vm.state_str}"
107
+ return
83
108
  end
84
109
 
85
- vms
110
+ allow_states.nil? || allow_states.include?(vm.state_str) ? canonical_instance(vm) : nil
86
111
  end
87
112
 
88
113
  # Hides batch processing from the rest of the application. Returns
@@ -2,7 +2,7 @@ module Egi
2
2
  module Fedcloud
3
3
  module Vmhound
4
4
  # Versioning constant
5
- VERSION = "0.0.4" unless defined?(::Egi::Fedcloud::Vmhound::VERSION)
5
+ VERSION = "0.0.5" unless defined?(::Egi::Fedcloud::Vmhound::VERSION)
6
6
  end
7
7
  end
8
8
  end
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
4
+ version: 0.0.5
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-07-03 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport