class NSXDriver::OpaqueNetwork
Class Opaque Network NSX-T Network
Public Class Methods
Source
# File lib/opaque_network.rb, line 25 def initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil) super(nsx_client) if ls_id initialize_with_id(ls_id) else if tz_id && ls_data begin @ls_id = new_logical_switch(ls_data) rescue NSXError::IncorrectResponseCodeError => e raise 'Opaque Network not created in ' \ "NSX Manager: #{e.message}" end unless @ls_id raise 'Opaque Network not created in NSX Manager: '\ 'generic error' end # Construct URL of the created logical switch @url_ls = NSXConstants::NSXT_LS_SECTION + @ls_id @ls_vni = ls_vni @ls_name = ls_name @tz_id = ls_tz @admin_display = 'UP' end end end
CONSTRUCTOR
Calls superclass method
Source
# File lib/opaque_network.rb, line 53 def self.new_from_name(nsx_client, ls_name) lswitch = new(nsx_client) ls_id = lswitch.ls_id_from_name(nsx_client, ls_name) unless ls_id error_msg = "Opaque Network with name: #{ls_name} not found" error = NSXError::ObjectNotFound .new(error_msg) raise error end # initialize_with_id(@ls_id) lswitch.initialize_with_id(ls_id) lswitch end
Creates a OpaqueNetwork
from its name
Public Instance Methods
Source
# File lib/opaque_network.rb, line 128 def delete_logical_switch @nsx_client.delete(@url_ls) end
Delete a logical switch
Source
# File lib/opaque_network.rb, line 69 def initialize_with_id(ls_id) @ls_id = ls_id # Construct URL of the created logical switch @url_ls = NSXConstants::NSXT_LS_SECTION + \ @ls_id if ls? @ls_vni = ls_vni @ls_name = ls_name @tz_id = ls_tz @admin_display = 'UP' else error_msg = "Opaque Network with id: #{ls_id} not found" error = NSXError::ObjectNotFound .new(error_msg) raise error end end
Creates a OpaqueNetwork
from its id
Source
# File lib/opaque_network.rb, line 103 def ls? @nsx_client.get(@url_ls) ? true : false end
METHODS Check if logical switch exists
Source
# File lib/opaque_network.rb, line 88 def ls_id_from_name(nsx_client, name) url = NSXConstants::NSXT_LS_SECTION lswitches = nsx_client.get(url)['results'] lswitches.each do |lswitch| lsname = lswitch['display_name'] lsid = lswitch['id'] if lsname == name && lsid return lsid end end nil end
Get the logical switch id from its name
Source
# File lib/opaque_network.rb, line 108 def ls_name @nsx_client.get(@url_ls)['display_name'] end
Get logical switch’s name
Source
# File lib/opaque_network.rb, line 118 def ls_tz @nsx_client.get(@url_ls)['transport_zone_id'] end
Get the Transport Zone of the logical switch
Source
# File lib/opaque_network.rb, line 113 def ls_vni @nsx_client.get(@url_ls)['vni'] end
Get logical switch’s vni
Source
# File lib/opaque_network.rb, line 123 def new_logical_switch(ls_data) @nsx_client.post(NSXConstants::NSXT_LS_SECTION, ls_data) end
Create a new logical switch (NSX-T: opaque network)