Class: Vipruby
- Inherits:
-
Object
- Object
- Vipruby
- Defined in:
- lib/vipruby.rb
Constant Summary collapse
- SSL_VERSION =
'TLSv1'
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#tenant_uid ⇒ Object
Returns the value of attribute tenant_uid.
-
#verify_cert ⇒ Object
Returns the value of attribute verify_cert.
Instance Method Summary collapse
- #add_host(host) ⇒ Object
- #add_host_and_initiators(host) ⇒ Object
- #add_initiators(initiators, host_href) ⇒ Object
- #find_host_object(search_hash) ⇒ Object
- #get_hosts ⇒ Object
- #host_exists?(hostname) ⇒ Boolean
-
#initialize(base_url, user_name, password, verify_cert) ⇒ Vipruby
constructor
A new instance of Vipruby.
Constructor Details
#initialize(base_url, user_name, password, verify_cert) ⇒ Vipruby
Returns a new instance of Vipruby.
8 9 10 11 12 13 14 |
# File 'lib/vipruby.rb', line 8 def initialize(base_url,user_name,password,verify_cert) #add condition later for trusted certs (This ignores) @base_url = base_url @verify_cert = to_boolean(verify_cert) @auth_token = get_auth_token(user_name,password) @tenant_uid = get_tenant_uid['id'] end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
5 6 7 |
# File 'lib/vipruby.rb', line 5 def auth_token @auth_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
5 6 7 |
# File 'lib/vipruby.rb', line 5 def base_url @base_url end |
#tenant_uid ⇒ Object
Returns the value of attribute tenant_uid.
5 6 7 |
# File 'lib/vipruby.rb', line 5 def tenant_uid @tenant_uid end |
#verify_cert ⇒ Object
Returns the value of attribute verify_cert.
5 6 7 |
# File 'lib/vipruby.rb', line 5 def verify_cert @verify_cert end |
Instance Method Details
#add_host(host) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vipruby.rb', line 39 def add_host(host) JSON.parse(RestClient::Request.execute(method: :post, url: "#{base_url}/tenants/#{@tenant_uid}/hosts", verify_ssl: @verify_cert, payload: host, headers: { :'X-SDS-AUTH-TOKEN' => @auth_token, content_type: 'application/json', accept: :json })) end |
#add_host_and_initiators(host) ⇒ Object
74 75 76 77 |
# File 'lib/vipruby.rb', line 74 def add_host_and_initiators(host) new_host = add_host(host.generate_json) add_initiators(host.generate_initiators_json,new_host['resource']['link']['href']) end |
#add_initiators(initiators, host_href) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vipruby.rb', line 51 def add_initiators(initiators,host_href) initiators.each do |initiator| RestClient::Request.execute(method: :post, url: "#{@base_url}#{host_href}/initiators", verify_ssl: @verify_cert, payload: initiator, headers: { :'X-SDS-AUTH-TOKEN' => @auth_token, content_type: 'application/json', accept: :json }) end end |
#find_host_object(search_hash) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/vipruby.rb', line 83 def find_host_object(search_hash) JSON.parse(RestClient::Request.execute(method: :get, url: "#{@base_url}/compute/hosts/search?name=#{search_hash}", verify_ssl: @verify_cert, headers: { :'X-SDS-AUTH-TOKEN' => @auth_token, accept: :json })) end |
#get_hosts ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/vipruby.rb', line 65 def get_hosts JSON.parse(RestClient::Request.execute(method: :get,url: "#{@base_url}/tenants/#{@tenant_uid}/hosts", verify_ssl: @verify_cert, headers: { :'X-SDS-AUTH-TOKEN' => @auth_token, accept: :json })) end |
#host_exists?(hostname) ⇒ Boolean
79 80 81 |
# File 'lib/vipruby.rb', line 79 def host_exists?(hostname) JSON.parse(find_vipr_object(hostname))['resource'].any? end |