Class: Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/cnos-rbapi/connect.rb

Overview

The Connect class provides a class implementation and methods for establishing node connections and initializations. This class presents an abstraction

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Connect

parameters:

file   :config file

return: Connect object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cnos-rbapi/connect.rb', line 46

def initialize(params)
	#params = YAML.load_file(file)
	@transport = params['transport']
	@port      = params['port']
	@ip        = params['ip']
	@user      = params['user']
	@password  = params['password']
	@cookie    = ''
               #Puppet.notice("transport  = #{@ip}")
               if @transport == 'http'
		@url       = @transport + '://' + @ip + ':' + @port + '/nos/api/login/'
               end
               if @transport == 'https'
		@url       = @transport + '://' + @ip + '/nos/api/login/'
               end
	
	begin
		RestClient::Request.execute(method: :get, url: @url, user: @user, password: @password, timeout: 10, :verify_ssl => false)
	rescue RestClient::Unauthorized, RestClient::Forbidden => err
 			@cookie =  err.response.cookies['auth_cookie']
	end
	
	@hdr = {}
	tmp_ckie = 'auth_cookie=' + @cookie + ';user=' + @user + '; Max-Age=3600; Path=/'
	@hdr['Cookie'] = tmp_ckie
	resp = RestClient::Request.execute(method: :get, url: @url, headers: @hdr, user: @user, password: @password, timeout: 10, :verify_ssl => false)
	@cookie = resp.cookies['auth_cookie']
	@hdr['Content-type'] = 'application/json'
               #Puppet.notice("resp  = #{resp}")

end

Instance Method Details

#getCookieObject

parameters:

return: Cookie - string


150
151
152
# File 'lib/cnos-rbapi/connect.rb', line 150

def getCookie()
               return @cookie
end

#getFacts(facts_url, args = {}) ⇒ Object

This API returns the facts asspociated with the URL being supplied.

parameters:
facts_url - string
any extra arguemnts

return: facts data - in json format


85
86
87
88
89
90
91
92
# File 'lib/cnos-rbapi/connect.rb', line 85

def getFacts(facts_url, args={})
        #Puppet.notice("URL is   = #{facts_url}")
        url = form_url(self, facts_url)
        hdr = form_hdr(self)
        resp = Rest.get(self, url, hdr)
        #Puppet.notice("Response  = #{resp}")
        return resp.to_json
end

#getHdrObject

parameters:

return: header - string


160
161
162
# File 'lib/cnos-rbapi/connect.rb', line 160

def getHdr()
	return @hdr
end

#getIpObject

parameters:

return: IP	- string


120
121
122
# File 'lib/cnos-rbapi/connect.rb', line 120

def getIp()
               return @ip
end

#getPasswordObject

parameters:

return: Password - string


140
141
142
# File 'lib/cnos-rbapi/connect.rb', line 140

def getPassword()
               return @password
end

#getPortObject

parameters:

return: port - string


110
111
112
# File 'lib/cnos-rbapi/connect.rb', line 110

def getPort()
               return @port
end

#getTransportObject

parameters:

return: transport - string


100
101
102
# File 'lib/cnos-rbapi/connect.rb', line 100

def getTransport()
	return @transport
end

#getUserObject

parameters:

return: User	- string


130
131
132
# File 'lib/cnos-rbapi/connect.rb', line 130

def getUser()
	return @user
end