Class: CCSH::Hosts
- Inherits:
-
Object
- Object
- CCSH::Hosts
- Defined in:
- lib/ccsh/hosts.rb
Instance Attribute Summary collapse
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
Instance Method Summary collapse
- #filter_by(targets) ⇒ Object
-
#initialize ⇒ Hosts
constructor
A new instance of Hosts.
- #parser!(filename) ⇒ Object
Constructor Details
#initialize ⇒ Hosts
Returns a new instance of Hosts.
11 12 13 |
# File 'lib/ccsh/hosts.rb', line 11 def initialize # TODO end |
Instance Attribute Details
#defaults ⇒ Object
Returns the value of attribute defaults.
8 9 10 |
# File 'lib/ccsh/hosts.rb', line 8 def defaults @defaults end |
#hosts ⇒ Object
Returns the value of attribute hosts.
9 10 11 |
# File 'lib/ccsh/hosts.rb', line 9 def hosts @hosts end |
Instance Method Details
#filter_by(targets) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ccsh/hosts.rb', line 53 def filter_by(targets) return @hosts if targets.include? 'all' hosts = [] @hosts.each do |host| targets.each do |target| hosts << host if host.groups.include? target end end return hosts end |
#parser!(filename) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ccsh/hosts.rb', line 15 def parser!(filename) begin file = Pathname.new(filename) raise "The file does not exists: '#{file.realpath}'" if not file.exist? raise "The host file is not regular file: '#{file.realpath}'" if not file.file? hostfile = YAML.load_file(file.realpath) @hosts = [] @defaults = CCSH::Utils.merge_defaults(hostfile['defaults']) hostfile['hosts'].each do |h| host = Host.new host.name = CCSH::Utils.('name', h, @defaults['name']) host.user = CCSH::Utils.('user', h, @defaults['user']) host.port = CCSH::Utils.('port', h, @defaults['port']) host.hostname = CCSH::Utils.('hostname', h, @defaults['hostname']) host.password = CCSH::Utils.('password', h, @defaults['password']) host.private_key = CCSH::Utils.('private_key', h, @defaults['private_key']) host. = CCSH::Utils.('ssh_options', h, @defaults['ssh_options']) host.timeout = CCSH::Utils.('timeout', h, @defaults['timeout']) host.groups = h['groups'] @hosts << host end rescue Exception => e puts e. puts e.backtrace puts end return self end |