Class: OcpClient

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/client/OcpClient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOcpClient

Returns a new instance of OcpClient.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/client/OcpClient.rb', line 33

def initialize
	@method = nil
	@url = nil
	@token = nil
	@noverifyssl = false
   @pretty = false
   @clientcert = nil
   @clientkey = nil
   @clientca = nil
   @clientcafile = nil
   @debug = nil
   @response = nil
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



31
32
33
# File 'lib/client/OcpClient.rb', line 31

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



30
31
32
# File 'lib/client/OcpClient.rb', line 30

def url
  @url
end

Instance Method Details

#delete(location) ⇒ Object



123
124
125
126
# File 'lib/client/OcpClient.rb', line 123

def delete(location)
  @method = :delete
  return call(location,nil,:delete)
end

#get(location) ⇒ Object



108
109
110
111
# File 'lib/client/OcpClient.rb', line 108

def get(location)
  @method = :get
 return call(location,nil,:get)
end

#post(location, body) ⇒ Object



113
114
115
116
# File 'lib/client/OcpClient.rb', line 113

def post(location, body)
  @method = :post
  return call(location,body,:post)
end

#put(location, body) ⇒ Object



118
119
120
121
# File 'lib/client/OcpClient.rb', line 118

def put(location, body)
  @method = :put
  return call(location,body,:put)
end

#setup(url, noverifyssl, pretty, debug, token, clientcertfile, clientkeyfile, clientcafile) ⇒ Object



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
77
78
79
# File 'lib/client/OcpClient.rb', line 47

def setup(url, noverifyssl, pretty, debug, token,
              clientcertfile, clientkeyfile, clientcafile)
  @noverifyssl = noverifyssl
  @pretty = pretty
  @debug = debug

  @url = url

  unless clientcertfile.nil? or clientkeyfile.nil?
    @clientcertfile = clientcertfile
    @clientkeyfile = clientkeyfile
  end

  unless clientcafile.nil?
    @clientcafile = clientcafile
  end

  unless @clientcertfile.nil? or @clientkeyfile.nil?
    @clientcert = OpenSSL::X509::Certificate.new File.read @clientcertfile
    @clientkey = OpenSSL::PKey::RSA.new File.read @clientkeyfile
  end

  unless @clientcafile.nil?
    @clientca = OpenSSL::X509::Certificate.new File.read @clientcafile
  end

  unless token.nil?
    @token = token
  end

  validate_options

end

#setup_by_config_file(configfile, pretty, debug) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/client/OcpClient.rb', line 81

def setup_by_config_file(configfile, pretty, debug)
  config = read_config(configfile)
  @debug=debug
  @pretty=pretty

  unless config.nil?
    @token = config["connection"]["token"]
    @url = config["connection"]["master"]
    @noverifyssl = config["connection"]["no_verify_ssl"]
    @clientcertfile = config["connection"]["client-certificate-file"]
    @clientkeyfile = config["connection"]["client-key-file"]
    @clientcafile = config["connection"]["client-ca-file"]
  end

  unless @clientcertfile.nil? or @clientkeyfile.nil?
    @clientcert = OpenSSL::X509::Certificate.new File.read @clientcertfile
    @clientkey = OpenSSL::PKey::RSA.new File.read @clientkeyfile
  end

  unless @clientcafile.nil?
    @clientca = OpenSSL::X509::Certificate.new File.read @clientcafile
  end

  validate_options
end