Class: NSXDriver::NSXClient

Inherits:
Object
  • Object
show all
Defined in:
lib/nsx_client.rb

Overview

Class NSXClient

Direct Known Subclasses

NSXTClient, NSXVClient

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nsxmgr, nsx_user, nsx_password) ⇒ NSXClient

CONSTRUCTORS



72
73
74
75
76
# File 'lib/nsx_client.rb', line 72

def initialize(nsxmgr, nsx_user, nsx_password)
    @nsxmgr = nsxmgr
    @nsx_user = nsx_user
    @nsx_password = nsx_password
end

Instance Attribute Details

#nsx_passwordObject

Returns the value of attribute nsx_password.



69
70
71
# File 'lib/nsx_client.rb', line 69

def nsx_password
  @nsx_password
end

#nsx_userObject

Returns the value of attribute nsx_user.



68
69
70
# File 'lib/nsx_client.rb', line 68

def nsx_user
  @nsx_user
end

#nsxmgrObject

ATTIBUTES



67
68
69
# File 'lib/nsx_client.rb', line 67

def nsxmgr
  @nsxmgr
end

Class Method Details

.new_child(nsxmgr, nsx_user, nsx_password, type) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/nsx_client.rb', line 78

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



97
98
99
100
101
102
103
104
# File 'lib/nsx_client.rb', line 97

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



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/nsx_client.rb', line 106

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.message}"
    end

    new_from_host(host)
end

Instance Method Details

#add_headers(aditional_headers = []) ⇒ Object

Prepare headers



153
# File 'lib/nsx_client.rb', line 153

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



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/nsx_client.rb', line 123

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



148
# File 'lib/nsx_client.rb', line 148

def delete(url); end

#get(url, aditional_headers = []) ⇒ Object

Return: respose.body



138
# File 'lib/nsx_client.rb', line 138

def get(url, aditional_headers = []); end

#get_full_response(url, aditional_headers = []) ⇒ Object

Return: response



141
# File 'lib/nsx_client.rb', line 141

def get_full_response(url, aditional_headers = []); end

#get_token(url) ⇒ Object



150
# File 'lib/nsx_client.rb', line 150

def get_token(url); end

#post(url, data, aditional_headers = []) ⇒ Object

Return: id of the created object



144
# File 'lib/nsx_client.rb', line 144

def post(url, data, aditional_headers = []); end

#put(url, data, aditional_headers = []) ⇒ Object



146
# File 'lib/nsx_client.rb', line 146

def put(url, data, aditional_headers = []); end