Module: KnifeGandi::PluginHelper
- Defined in:
- lib/knife-gandi/plugin_helper.rb
Instance Method Summary collapse
- #config_has_value?(key) ⇒ Boolean
-
#ip_objects_of(server, opts = {}) ⇒ Object
Returns the public IP Resource objects sent from the API.
- #locate_config_value(key) ⇒ Object
- #public_ips_of(server, opts = {}) ⇒ Object
- #public_reverses_of(server, opts = {}) ⇒ Object
-
#suppress_warnings ⇒ Object
Keeps the vm’s warnings out of $stdout.
- #until_done(operation) ⇒ Object
Instance Method Details
#config_has_value?(key) ⇒ Boolean
19 20 21 22 |
# File 'lib/knife-gandi/plugin_helper.rb', line 19 def config_has_value?(key) key = key.to_sym Chef::Config[:knife].has_key?(key) || config.has_key?(key) end |
#ip_objects_of(server, opts = {}) ⇒ Object
Returns the public IP Resource objects sent from the API. Look up their representation in the Gandi API docs.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/knife-gandi/plugin_helper.rb', line 46 def ip_objects_of(server, opts={}) # Server has n ifaces which hold 2 IPs (IPv4 and IPv6) public_ifaces = server['ifaces'] if opts.has_key?(:type) public_ifaces = public_ifaces.find_all { |iface| iface['type'] == 'public' } end public_ips = public_ifaces.map { |iface| iface['ips'] }.flatten(1) if opts.has_key?(:version) # Filter IP version (4|6) public_ips = public_ips.find_all { |ip| ip['version'] == opts[:version] } end public_ips end |
#locate_config_value(key) ⇒ Object
14 15 16 17 |
# File 'lib/knife-gandi/plugin_helper.rb', line 14 def locate_config_value(key) key = key.to_sym Chef::Config[:knife][key] || config[key] end |
#public_ips_of(server, opts = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/knife-gandi/plugin_helper.rb', line 32 def public_ips_of(server, opts={}) = opts.merge({:type => 'public'}) public_ips = ip_objects_of(server, ) public_ips.collect { |ip| ip['ip'] } end |
#public_reverses_of(server, opts = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/knife-gandi/plugin_helper.rb', line 38 def public_reverses_of(server, opts={}) = opts.merge({:type => 'public'}) public_ips = ip_objects_of(server, ) public_ips.collect { |ip| ip['reverse'] } end |
#suppress_warnings ⇒ Object
Keeps the vm’s warnings out of $stdout. Helpful when changing the value of a constant.
6 7 8 9 10 11 12 |
# File 'lib/knife-gandi/plugin_helper.rb', line 6 def suppress_warnings original_verbosity = $VERBOSE $VERBOSE = nil result = yield $VERBOSE = original_verbosity return result end |
#until_done(operation) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/knife-gandi/plugin_helper.rb', line 24 def until_done(operation) while operation['step'] != 'DONE' operation = connection.call('operation.info', api_key, operation['id']) yield sleep 2 end end |