Class: Fog::Hyperv::Compute::NetworkAdapterVlan

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/hyperv/compute/models/network_adapter_vlan.rb

Constant Summary collapse

VLAN_OPERATION_MODE =
Note:

Defined by Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanMode

VLAN mode

%i[
  Untagged Access Trunk Private
].freeze
PRIVATE_VLAN_MODE =
Note:

Defined by Microsoft.HyperV.PowerShell.VMNetworkAdapterPrivateVlanMode

Extended mode for Private VLANs

%i[
  Unknown Isolated Community Promiscuous
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize

Methods included from ModelExtends

#collection

Methods included from ModelIncludes

#cluster, #computer, #dirty, #dirty?, #vm

Constructor Details

This class inherits a constructor from Fog::Hyperv::Model

Instance Attribute Details

#access_vlan_idInteger

Returns the VLAN ID to use for operation_mode :Access.

Returns:

  • (Integer)

    the VLAN ID to use for operation_mode :Access



25
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 25

attribute :access_vlan_id, type: :integer

#allowed_vlan_id_listArray<Integer>

Returns the list of allowed VLAN IDs to use for operation_mode :Trunk.

Returns:

  • (Array<Integer>)

    the list of allowed VLAN IDs to use for operation_mode :Trunk



28
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 28

attribute :allowed_vlan_id_list

#native_vlan_idInteger

Returns the native VLAN ID to use for operation_mode :Trunk.

Returns:

  • (Integer)

    the native VLAN ID to use for operation_mode :Trunk



31
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 31

attribute :native_vlan_id, type: :integer

#operation_mode:Untagged, ...

Returns the active VLAN mode.

Returns:

  • (:Untagged, :Access, :Trunk, :Private)

    the active VLAN mode



19
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 19

attribute :operation_mode, type: :hypervenum, default: :Untagged, values: VLAN_OPERATION_MODE

#parent_adapterNetworkAdapter Also known as: identity

Returns the network adapter this VLAN configuration applies to.

Returns:

  • (NetworkAdapter)

    the network adapter this VLAN configuration applies to



44
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 44

has_one :parent_adapter, :network_adapters

#primary_vlan_idInteger

Returns the primary VLAN ID to use for operation_mode :Private.

Returns:

  • (Integer)

    the primary VLAN ID to use for operation_mode :Private



34
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 34

attribute :primary_vlan_id, type: :integer

#private_vlan_mode:Isolated, ...

Returns the type of private VLAN mode to use.

Returns:

  • (:Isolated, :Community, :Promiscuous)

    the type of private VLAN mode to use



22
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 22

attribute :private_vlan_mode, type: :hypervenum, default: :Isolated, values: PRIVATE_VLAN_MODE

#secondary_vlan_idInteger

Returns the secondary VLAN ID to use for private_vlan_mode :Isolated or :Community.

Returns:

  • (Integer)

    the secondary VLAN ID to use for private_vlan_mode :Isolated or :Community



37
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 37

attribute :secondary_vlan_id, type: :integer

#secondary_vlan_id_listArray<Integer>

Returns the list of secondary VLAN IDs to use for private_vlan_mode :Promiscuous.

Returns:

  • (Array<Integer>)

    the list of secondary VLAN IDs to use for private_vlan_mode :Promiscuous



40
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 40

attribute :secondary_vlan_id_list

Class Method Details

.render_vlan_list(list) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 83

def self.render_vlan_list(list)
  ret = []
  list = list.map(&:to_i).reject(&:zero?).sort.uniq

  render_tuple = proc do |from, to|
    next from if from == to

    "#{from}-#{to}"
  end

  rangeend = rangestart = list.first
  list.each do |vlan|
    if vlan > rangeend + 1
      ret << render_tuple.call(rangestart, rangeend)
      rangestart = rangeend = vlan
    else
      rangeend = vlan
    end
  end
  ret << render_tuple.call(rangestart, rangeend)

  ret.join ','
end

Instance Method Details

#reloadObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 68

def reload
  requires :parent_adapter

  data = service.get_vm_network_adapter_vlan(
    computer_name: parent_adapter.computer_name,
    vm_id: parent_adapter.vm_id,
    id: parent_adapter.id,

    _return_fields: self.class.attributes
  )
  return unless data

  merge_attributes(data)
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/hyperv/compute/models/network_adapter_vlan.rb', line 48

def update
  requires :parent_adapter

  changes = build_changelist
  return self unless changes.any?

  merge_attributes(
    service.set_vm_network_adapter_vlan(
      computer_name: parent_adapter.computer_name,
      vm_id: parent_adapter.vm_id,
      id: parent_adapter.id,

      **changes,

      _always_include: changes.keys,
      _return_fields: self.class.attributes
    ) || {} # Unmodified object returns nothing
  )
end