Class: NSXDriver::NSXVLogicalPort
- Inherits:
-
LogicalPort
- Object
- NSXComponent
- LogicalPort
- NSXDriver::NSXVLogicalPort
- Defined in:
- lib/nsxv_logical_port.rb
Overview
The NSXVLogicalPort class represents a LogicalPort in NSXv
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
ATTRIBUTES.
-
#name ⇒ Object
readonly
ATTRIBUTES.
-
#type ⇒ Object
readonly
ATTRIBUTES.
-
#url ⇒ Object
readonly
ATTRIBUTES.
Instance Method Summary collapse
-
#initialize(nsx_client, id = nil, data = nil) ⇒ NSXVLogicalPort
constructor
CONSTRUCTOR Logical port class variables:.
-
#initialize_with_id(id) ⇒ Object
Creates a NSXTLogicalPort from its id.
-
#lp? ⇒ Boolean
Check if logical port exists.
-
#lp_name ⇒ Object
Get logical port display name.
-
#lp_type ⇒ Object
Get resource type.
-
#lp_with_attachid(attach_id) ⇒ Object
Get logical port id from attach id.
Methods inherited from LogicalPort
Constructor Details
#initialize(nsx_client, id = nil, data = nil) ⇒ NSXVLogicalPort
CONSTRUCTOR Logical port class variables:
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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.}" 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 |
Instance Attribute Details
#id ⇒ Object (readonly)
ATTRIBUTES
22 23 24 |
# File 'lib/nsxv_logical_port.rb', line 22 def id @id end |
#name ⇒ Object (readonly)
ATTRIBUTES
22 23 24 |
# File 'lib/nsxv_logical_port.rb', line 22 def name @name end |
#type ⇒ Object (readonly)
ATTRIBUTES
22 23 24 |
# File 'lib/nsxv_logical_port.rb', line 22 def type @type end |
#url ⇒ Object (readonly)
ATTRIBUTES
22 23 24 |
# File 'lib/nsxv_logical_port.rb', line 22 def url @url end |
Instance Method Details
#initialize_with_id(id) ⇒ Object
Creates a NSXTLogicalPort from its id
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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? ⇒ Boolean
Check if logical port exists
83 84 85 |
# File 'lib/nsxv_logical_port.rb', line 83 def lp? @nsx_client.get(@url) ? true : false end |
#lp_name ⇒ Object
Get logical port display name
96 97 98 |
# File 'lib/nsxv_logical_port.rb', line 96 def lp_name @nsx_client.get(@url)['display_name'] end |
#lp_type ⇒ Object
Get resource type
101 102 103 |
# File 'lib/nsxv_logical_port.rb', line 101 def lp_type @nsx_client.get(@url)['resource_type'] end |
#lp_with_attachid(attach_id) ⇒ Object
Get logical port id from attach id
88 89 90 91 92 93 |
# 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 |