Class: Netscaler::ConfigurationReader

Inherits:
Object
  • Object
show all
Defined in:
lib/netscaler/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml) ⇒ ConfigurationReader

Returns a new instance of ConfigurationReader.



9
10
11
# File 'lib/netscaler/config.rb', line 9

def initialize(yaml)
  @servers = yaml
end

Class Method Details

.read_config_file(file) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/netscaler/config.rb', line 35

def self.read_config_file(file)
  if file.nil?
    file = File.expand_path(".netscaler-cli.yml", Etc.getpwuid.dir)
  end

  if !File.exists?(file)
    raise Netscaler::ConfigurationError.new("Unable to locate the netscaler-cli configuration file")
  end

  begin
    yaml = File.read(file)
    ConfigurationReader.new(YAML::load(yaml))
  rescue Exception => e
    raise Netscaler::ConfigurationError.new("Unable to load the netscaler-cli configuration file")
  end
end

Instance Method Details

#[](name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/netscaler/config.rb', line 13

def [](name)
  # First, try the aliases
  @servers.each_key do |lbname|
    found = @servers[lbname]
    if found['alias'] == name
      return create_config(lbname, found)
    end
  end

  # Next, check the actual server names
  found = @servers[name]
  if found.nil?
    raise Netscaler::ConfigurationError.new("The specified Netscaler host was not found")
  end

  return create_config(name, found)
end

#load_balancersObject



31
32
33
# File 'lib/netscaler/config.rb', line 31

def load_balancers
  @servers.keys
end