class Bcome::Node::Inventory::Defined
Constants
- MACHINES_CACHE_PATH
Attributes
dynamic_nodes_loaded[R]
Public Class Methods
new(*params)
click to toggle source
Calls superclass method
Bcome::Node::Inventory::Base::new
# File lib/objects/node/inventory/defined.rb, line 13 def initialize(*params) @load_machines_from_cache = false @cache_handler = ::Bcome::Node::CacheHandler.new(self) super end
Public Instance Methods
cache()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 69 def cache @answer = ::Bcome::Interactive::Session.run(self, :capture_input, terminal_prompt: 'Are you sure you want to cache these machines (saving will overwrite any previous selections) [Y|N] ? ') if @answer && @answer == 'Y' cache_nodes_in_memory data = load_machines_config data.delete(namespace) data.delete(namespace.to_sym) data[namespace] = views[:static_servers] File.open(machines_cache_path, 'w') do |file| file.write data.to_yaml end puts "\nMachines have been cached to #{machines_cache_path} for node #{namespace}".informational else puts 'Nothing saved'.warning end end
cache_nodes_in_memory()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 100 def cache_nodes_in_memory @cache_handler.do_cache_nodes! end
do_reload()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 104 def do_reload resources.unset! load_dynamic_nodes end
fetch_server_list()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 133 def fetch_server_list return [] unless network_driver network_driver.fetch_server_list(filters) end
load_dynamic_nodes()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 115 def load_dynamic_nodes raw_servers = fetch_server_list raw_servers ||= [] raw_servers.each do |raw_server| if raw_server.is_a?(Google::Apis::ComputeBeta::Instance) resources << ::Bcome::Node::Server::Dynamic::Gcp.new_from_gcp_instance(raw_server, self) elsif raw_server.is_a?(Fog::Compute::AWS::Server) resources << ::Bcome::Node::Server::Dynamic::Ec2.new_from_fog_instance(raw_server, self) else raise Bcome::Exception::UnknownDynamicServerType, "Unknown dynamic server type #{raw_server.class}" end end resources.rename_initial_duplicate if resources.should_rename_initial_duplicate? end
load_machines_config()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 91 def load_machines_config config = YAML.load_file(machines_cache_path).deep_symbolize_keys config rescue ArgumentError, Psych::SyntaxError raise Bcome::Exception::InvalidMachinesCacheConfig, 'Invalid yaml in config' rescue Errno::ENOENT {} end
load_nodes()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 109 def load_nodes set_static_servers load_dynamic_nodes unless resources.any? nodes_loaded! end
machines_cache_path()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 65 def machines_cache_path "#{::Bcome::Node::Factory::CONFIG_PATH}/#{MACHINES_CACHE_PATH}" end
raw_static_machines_from_cache()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 61 def raw_static_machines_from_cache load_machines_config[namespace.to_sym] end
reload()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 40 def reload resources.reset_duplicate_nodes! do_reload puts "\n\nDone. Hit 'ls' to see the refreshed inventory.\n".informational end
set_static_servers()
click to toggle source
# File lib/objects/node/inventory/defined.rb, line 46 def set_static_servers cached_machines = raw_static_machines_from_cache if cached_machines&.any? print "\n" title = 'Loading' + "\sCACHE".bc_orange.bold + "\s" + namespace.to_s.underline wrap_indicator type: :basic, title: title, completed_title: '' do cached_machines.each do |server_config| resources << ::Bcome::Node::Server::Static.new(views: server_config, parent: self) end signal_success end end end