Class: NSXDriver::NSXClient
- Inherits:
-
Object
- Object
- NSXDriver::NSXClient
- Defined in:
- lib/nsx_client.rb
Overview
Class NSXClient
Direct Known Subclasses
Instance Attribute Summary collapse
-
#nsx_password ⇒ Object
Returns the value of attribute nsx_password.
-
#nsx_user ⇒ Object
Returns the value of attribute nsx_user.
-
#nsxmgr ⇒ Object
ATTIBUTES.
Class Method Summary collapse
- .new_child(nsxmgr, nsx_user, nsx_password, type) ⇒ Object
- .new_from_host(host) ⇒ Object
- .new_from_id(hid) ⇒ Object
Instance Method Summary collapse
-
#add_headers(aditional_headers = []) ⇒ Object
Prepare headers.
-
#check_response(response, codes_array) ⇒ Object
Return response if match with responses codes, If response not match with expected responses codes then raise an IncorrectResponseCodeError.
- #delete(url) ⇒ Object
-
#get(url, aditional_headers = []) ⇒ Object
Return: respose.body.
-
#get_full_response(url, aditional_headers = []) ⇒ Object
Return: response.
- #get_token(url) ⇒ Object
-
#initialize(nsxmgr, nsx_user, nsx_password) ⇒ NSXClient
constructor
CONSTRUCTORS.
-
#post(url, data, aditional_headers = []) ⇒ Object
Return: id of the created object.
- #put(url, data, aditional_headers = []) ⇒ Object
Constructor Details
#initialize(nsxmgr, nsx_user, nsx_password) ⇒ NSXClient
CONSTRUCTORS
59 60 61 62 63 |
# File 'lib/nsx_client.rb', line 59 def initialize(nsxmgr, nsx_user, nsx_password) @nsxmgr = nsxmgr @nsx_user = nsx_user @nsx_password = nsx_password end |
Instance Attribute Details
#nsx_password ⇒ Object
Returns the value of attribute nsx_password.
56 57 58 |
# File 'lib/nsx_client.rb', line 56 def nsx_password @nsx_password end |
#nsx_user ⇒ Object
Returns the value of attribute nsx_user.
55 56 57 |
# File 'lib/nsx_client.rb', line 55 def nsx_user @nsx_user end |
#nsxmgr ⇒ Object
ATTIBUTES
54 55 56 |
# File 'lib/nsx_client.rb', line 54 def nsxmgr @nsxmgr end |
Class Method Details
.new_child(nsxmgr, nsx_user, nsx_password, type) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nsx_client.rb', line 65 def self.new_child(nsxmgr, nsx_user, nsx_password, type) [nsxmgr, nsx_user, nsx_password, type].each do |v| next if !v.nil? && !v.empty? return nil end case type.upcase when NSXConstants::NSXT NSXTClient.new(nsxmgr, nsx_user, nsx_password) when NSXConstants::NSXV NSXVClient.new(nsxmgr, nsx_user, nsx_password) else error_msg = "Unknown NSX type: #{type}" error = NSXError::UnknownObject.new(error_msg) raise error end end |
.new_from_host(host) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/nsx_client.rb', line 84 def self.new_from_host(host) nsxmgr = host['TEMPLATE/NSX_MANAGER'] nsx_user = host['TEMPLATE/NSX_USER'] nsx_password = host['TEMPLATE/NSX_PASSWORD'] nsx_type = host['TEMPLATE/NSX_TYPE'] new_child(nsxmgr, nsx_user, nsx_password, nsx_type) end |
.new_from_id(hid) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nsx_client.rb', line 93 def self.new_from_id(hid) client = OpenNebula::Client.new host = OpenNebula::Host.new_with_id(hid, client) rc = host.info(true) if OpenNebula.is_error?(rc) raise "Could not get host info for ID: #{hid} - #{rc.}" end new_from_host(host) end |
Instance Method Details
#add_headers(aditional_headers = []) ⇒ Object
Prepare headers
140 |
# File 'lib/nsx_client.rb', line 140 def add_headers(aditional_headers = []); end |
#check_response(response, codes_array) ⇒ Object
Return response if match with responses codes, If response not match with expected responses codes then raise an IncorrectResponseCodeError
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/nsx_client.rb', line 110 def check_response(response, codes_array) unless response.nil? return response if codes_array.include?(response.code.to_i) response_json = JSON.parse(response.body) nsx_error = "\nNSX error code: " \ "#{response_json['errorCode']}, " \ "\nNSX error details: " \ "#{response_json['details']}" raise NSXError::IncorrectResponseCodeError, nsx_error end raise NSXError::IncorrectResponseCodeError, nsx_error end |
#delete(url) ⇒ Object
135 |
# File 'lib/nsx_client.rb', line 135 def delete(url); end |
#get(url, aditional_headers = []) ⇒ Object
Return: respose.body
125 |
# File 'lib/nsx_client.rb', line 125 def get(url, aditional_headers = []); end |
#get_full_response(url, aditional_headers = []) ⇒ Object
Return: response
128 |
# File 'lib/nsx_client.rb', line 128 def get_full_response(url, aditional_headers = []); end |
#get_token(url) ⇒ Object
137 |
# File 'lib/nsx_client.rb', line 137 def get_token(url); end |
#post(url, data, aditional_headers = []) ⇒ Object
Return: id of the created object
131 |
# File 'lib/nsx_client.rb', line 131 def post(url, data, aditional_headers = []); end |
#put(url, data, aditional_headers = []) ⇒ Object
133 |
# File 'lib/nsx_client.rb', line 133 def put(url, data, aditional_headers = []); end |