class Connect

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

Public Class Methods

new(params) click to toggle source

This function is used to initialise node paramters and establish connection with the given paramters.

parameters:
file   :config file

return: Connect object
# 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

Public Instance Methods

getCookie() click to toggle source

This API returns Cookie for the current node connection.

parameters:

return: Cookie - string
# File lib/cnos-rbapi/connect.rb, line 150
def getCookie()
        return @cookie
end
getFacts(facts_url, args={}) click to toggle source

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

parameters:
facts_url - string
any extra arguemnts

return: facts data - in json format
# 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
getHdr() click to toggle source

This API returns Header Info for the current node connection.

parameters:

return: header - string
# File lib/cnos-rbapi/connect.rb, line 160
def getHdr()
        return @hdr
end
getIp() click to toggle source

This API returns IP for the current node connection.

parameters:

return: IP   - string
# File lib/cnos-rbapi/connect.rb, line 120
def getIp()
        return @ip
end
getPassword() click to toggle source

This API returns Password for the current node connection.

parameters:

return: Password - string
# File lib/cnos-rbapi/connect.rb, line 140
def getPassword()
        return @password
end
getPort() click to toggle source

This API returns Port for the current node connection.

parameters:

return: port - string
# File lib/cnos-rbapi/connect.rb, line 110
def getPort()
        return @port
end
getTransport() click to toggle source

This API returns Transport protocol for the current node connection.

parameters:

return: transport - string
# File lib/cnos-rbapi/connect.rb, line 100
def getTransport()
        return @transport
end
getUser() click to toggle source

This API returns User for the current node connection.

parameters:

return: User - string
# File lib/cnos-rbapi/connect.rb, line 130
def getUser()
        return @user
end