Class: NSXDriver::NSXTLogicalPort

Inherits:
LogicalPort show all
Defined in:
lib/nsxt_logical_port.rb

Overview

Class NSXTLogicalPort

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from LogicalPort

#lp_id, new_child

Constructor Details

#initialize(nsx_client, id = nil, data = nil) ⇒ NSXTLogicalPort

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
# File 'lib/nsxt_logical_port.rb', line 30

def initialize(nsx_client, id = nil, data = nil)
    super(nsx_client)
    # lpid can be:
    #   - 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

Instance Attribute Details

#idObject (readonly)

ATTRIBUTES



22
23
24
# File 'lib/nsxt_logical_port.rb', line 22

def id
  @id
end

#nameObject (readonly)

ATTRIBUTES



22
23
24
# File 'lib/nsxt_logical_port.rb', line 22

def name
  @name
end

#typeObject (readonly)

ATTRIBUTES



22
23
24
# File 'lib/nsxt_logical_port.rb', line 22

def type
  @type
end

#urlObject (readonly)

ATTRIBUTES



22
23
24
# File 'lib/nsxt_logical_port.rb', line 22

def url
  @url
end

Instance Method Details

#initialize_with_id(id) ⇒ Object

Creates a NSXTLogicalPort from its id



57
58
59
60
61
62
63
64
65
# File 'lib/nsxt_logical_port.rb', line 57

def initialize_with_id(id)
    @id = lp_with_attachid(id)
    # Construct URL of the created logical switch
    @url = NSXConstants::NSXT_LP_BASE + @id
    return unless lp?

    @name = lp_name
    @type = lp_type
end

#lp?Boolean

Check if logical port exists

Returns:

  • (Boolean)


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

def lp?
    @nsx_client.get(@url)
end

#lp_nameObject

# Get logical port display name



81
82
83
84
# File 'lib/nsxt_logical_port.rb', line 81

def lp_name
    lp = @nsx_client.get(@url)
    lp['display_name']
end

#lp_typeObject

# Get resource type



87
88
89
90
# File 'lib/nsxt_logical_port.rb', line 87

def lp_type
    lp = @nsx_client.get(@url)
    lp['resource_type']
end

#lp_with_attachid(attach_id) ⇒ Object

Get logical port id from attach id



73
74
75
76
77
78
# File 'lib/nsxt_logical_port.rb', line 73

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