Class: NSXDriver::OpaqueNetwork
- Inherits:
-
LogicalSwitch
- Object
- NSXComponent
- LogicalSwitch
- NSXDriver::OpaqueNetwork
- Defined in:
- lib/opaque_network.rb
Overview
Class Opaque Network NSX-T Network
Instance Attribute Summary
Attributes inherited from LogicalSwitch
#description, #display_name, #ls_id, #replication_mode, #tz_id
Class Method Summary collapse
-
.new_from_name(nsx_client, ls_name) ⇒ Object
Creates a OpaqueNetwork from its name.
Instance Method Summary collapse
-
#delete_logical_switch ⇒ Object
Delete a logical switch.
-
#initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil) ⇒ OpaqueNetwork
constructor
CONSTRUCTOR.
-
#initialize_with_id(ls_id) ⇒ Object
Creates a OpaqueNetwork from its id.
-
#ls? ⇒ Boolean
METHODS Check if logical switch exists.
-
#ls_id_from_name(nsx_client, name) ⇒ Object
Get the logical switch id from its name.
-
#ls_name ⇒ Object
Get logical switch’s name.
-
#ls_tz ⇒ Object
Get the Transport Zone of the logical switch.
-
#ls_vni ⇒ Object
Get logical switch’s vni.
-
#new_logical_switch(ls_data) ⇒ Object
Create a new logical switch (NSX-T: opaque network).
Methods inherited from LogicalSwitch
nsx_nics, #update_logical_switch
Constructor Details
#initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil) ⇒ OpaqueNetwork
CONSTRUCTOR
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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.}" 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 |
Class Method Details
.new_from_name(nsx_client, ls_name) ⇒ Object
Creates a OpaqueNetwork from its name
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 |
Instance Method Details
#delete_logical_switch ⇒ Object
Delete a logical switch
128 129 130 |
# File 'lib/opaque_network.rb', line 128 def delete_logical_switch @nsx_client.delete(@url_ls) end |
#initialize_with_id(ls_id) ⇒ Object
Creates a OpaqueNetwork from its id
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 |
#ls? ⇒ Boolean
METHODS Check if logical switch exists
103 104 105 |
# File 'lib/opaque_network.rb', line 103 def ls? @nsx_client.get(@url_ls) ? true : false end |
#ls_id_from_name(nsx_client, name) ⇒ Object
Get the logical switch id from its name
88 89 90 91 92 93 94 95 96 97 98 99 |
# 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 |
#ls_name ⇒ Object
Get logical switch’s name
108 109 110 |
# File 'lib/opaque_network.rb', line 108 def ls_name @nsx_client.get(@url_ls)['display_name'] end |
#ls_tz ⇒ Object
Get the Transport Zone of the logical switch
118 119 120 |
# File 'lib/opaque_network.rb', line 118 def ls_tz @nsx_client.get(@url_ls)['transport_zone_id'] end |
#ls_vni ⇒ Object
Get logical switch’s vni
113 114 115 |
# File 'lib/opaque_network.rb', line 113 def ls_vni @nsx_client.get(@url_ls)['vni'] end |
#new_logical_switch(ls_data) ⇒ Object
Create a new logical switch (NSX-T: opaque network)
123 124 125 |
# File 'lib/opaque_network.rb', line 123 def new_logical_switch(ls_data) @nsx_client.post(NSXConstants::NSXT_LS_SECTION, ls_data) end |