class NSXDriver::NSXVLogicalPort
The NSXVLogicalPort
class represents a LogicalPort
in NSXv
Attributes
id[R]
ATTRIBUTES
name[R]
ATTRIBUTES
type[R]
ATTRIBUTES
url[R]
ATTRIBUTES
Public Class Methods
new(nsx_client, id = nil, data = nil)
click to toggle source
CONSTRUCTOR Logical port class variables: @lp_id @url_lp @lp_name @lp_type
Calls superclass method
# File lib/nsxv_logical_port.rb, line 30 def initialize(nsx_client, id = nil, data = nil) super(nsx_client) # lpid can be: # - Logical port ID # - Logical port attach ID if id initialize_with_id(id) else if data begin @id = new_logical_port(data) rescue NSXError::IncorrectResponseCodeError => e raise 'Logical Port not created in ' \ "NSX Manager: #{e.message}" end unless @id raise 'Logical Port not created in NSX Manager: '\ 'generic error' end # Construct logical port class variables @url = NSXConstants::NSXT_LP_BASE + @id @name = lp_name @type = lp_type end end end
Public Instance Methods
initialize_with_id(id)
click to toggle source
Creates a NSXTLogicalPort
from its id
# File lib/nsxv_logical_port.rb, line 58 def initialize_with_id(id) # First try lpid as logical port id @id = id # Construct URL of the created logical switch @url = NSXConstants::NSXV_LP_BASE + @id if lp? @name = lp_name @type = lp_type else # Second try with lpid as logical port attach id @id = lp_with_attachid(id) if @id.nil? error_msg = "Logical port with id: #{id} not found" error = NSXError::ObjectNotFound .new(error_msg) raise error else @url = NSXConstants::NSXT_LP_BASE + @id @name = lp_name @type = lp_type end end end
lp?()
click to toggle source
Check if logical port exists
# File lib/nsxv_logical_port.rb, line 83 def lp? @nsx_client.get(@url) ? true : false end
lp_name()
click to toggle source
Get logical port display name
# File lib/nsxv_logical_port.rb, line 96 def lp_name @nsx_client.get(@url)['display_name'] end
lp_type()
click to toggle source
Get resource type
# File lib/nsxv_logical_port.rb, line 101 def lp_type @nsx_client.get(@url)['resource_type'] end
lp_with_attachid(attach_id)
click to toggle source
Get logical port id from attach id
# File lib/nsxv_logical_port.rb, line 88 def lp_with_attachid(attach_id) lps = @nsx_client.get(NSXConstants::NSXT_LP_BASE) lps['results'].each do |lp| return lp['id'] if lp['attachment']['id'] == attach_id end end