Class: Netscaler::VServer::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



3
4
5
6
7
8
9
# File 'lib/netscaler/vserver/response.rb', line 3

def initialize(raw_response)
  @info = if raw_response[:return]
            raw_response[:return][:list][:item]
          else
            raw_response
          end
end

Instance Method Details

#ip_addressObject



15
16
17
18
19
20
21
# File 'lib/netscaler/vserver/response.rb', line 15

def ip_address
  if @info[:ipaddress] =~ /0\.0\.0\.0/
    @info[:ipaddress2]
  else
    @info[:ipaddress]
  end
end

#nameObject



11
12
13
# File 'lib/netscaler/vserver/response.rb', line 11

def name
  @info[:name]
end

#portObject



27
28
29
# File 'lib/netscaler/vserver/response.rb', line 27

def port
  @info[:port].to_i
end

#service_groupsObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/netscaler/vserver/response.rb', line 50

def service_groups
  @service_groups ||= if @info[:servicegroupname] && @info[:servicegroupname][:item]
                        groups = @info[:servicegroupname][:item]
                        if groups.is_a?(Array)
                          groups
                        else
                          [groups]
                        end
                      else
                        []
                      end
end

#servicesObject



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

def services
  @parsed_services ||= []
  return @parsed_services if !@parsed_services.empty? || @info[:servicename].nil?

  if @info[:servicename][:item].is_a?(String)
    @parsed_services << ServiceInfo.new(@info, nil)
  else
    @info[:servicename][:item].each_with_index do |name, i|
      @parsed_services << ServiceInfo.new(@info, i)
    end
  end

  @parsed_services
end

#stateObject



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

def state
  @info[:state]
end

#to_hashObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/netscaler/vserver/response.rb', line 63

def to_hash
  hash = { :name => name,
    :ip_address => ip_address,
    :state => state,
    :port => port,
    :type => type,
  }

  if !services.empty?
    hash[:services] = services.map {|s| s.to_hash}
  end

  if !service_groups.empty?
    hash[:service_groups] = service_groups
  end
  
  hash
end

#typeObject



23
24
25
# File 'lib/netscaler/vserver/response.rb', line 23

def type
  @info[:servicetype]
end