Class: Fog::Hyperv::Compute::Switch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize, #merge_attributes

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

#allow_management_osBoolean

Returns is the management OS allowed to use this switch.

Returns:

  • (Boolean)

    is the management OS allowed to use this switch



15
# File 'lib/fog/hyperv/compute/models/switch.rb', line 15

attribute :allow_management_os, type: :boolean

#computer_nameString (readonly)

Returns the name of the computer hosting this network switch.

Returns:

  • (String)

    the name of the computer hosting this network switch



11
# File 'lib/fog/hyperv/compute/models/switch.rb', line 11

attribute :computer_name

#default_flow_minimum_bandwidth_absoluteInteger

Returns the default minimum bandwidth allocation for VMs without specific allocations.

Returns:

  • (Integer)

    the default minimum bandwidth allocation for VMs without specific allocations



18
# File 'lib/fog/hyperv/compute/models/switch.rb', line 18

attribute :default_flow_minimum_bandwidth_absolute, type: :integer

#default_flow_minimum_bandwidth_weightInteger

Returns the default minimum bandwidth allocation for VMs without specific allocations, as a relative weight.

Returns:

  • (Integer)

    the default minimum bandwidth allocation for VMs without specific allocations, as a relative weight



21
# File 'lib/fog/hyperv/compute/models/switch.rb', line 21

attribute :default_flow_minimum_bandwidth_weight, type: :integer

#idString (readonly)

Returns the GUID of the network switch.

Returns:

  • (String)

    the GUID of the network switch



7
# File 'lib/fog/hyperv/compute/models/switch.rb', line 7

identity :id

#nameString

Returns the name of the network switch.

Returns:

  • (String)

    the name of the network switch



24
# File 'lib/fog/hyperv/compute/models/switch.rb', line 24

attribute :name

#net_adapter_interface_descriptionString (readonly)

Returns the network interface description this switch is attached to.

Returns:

  • (String)

    the network interface description this switch is attached to



27
# File 'lib/fog/hyperv/compute/models/switch.rb', line 27

attribute :net_adapter_interface_description

#net_adapter_nameString (readonly)

Returns the network interface name this switch is attached to.

Returns:

  • (String)

    the network interface name this switch is attached to



30
# File 'lib/fog/hyperv/compute/models/switch.rb', line 30

attribute :net_adapter_name

#notesString

Returns the user-specified notes for the network switch.

Returns:

  • (String)

    the user-specified notes for the network switch



33
# File 'lib/fog/hyperv/compute/models/switch.rb', line 33

attribute :notes

#resource_pool_nameString

Returns the resource pool the switch is part of.

Returns:

  • (String)

    the resource pool the switch is part of



36
# File 'lib/fog/hyperv/compute/models/switch.rb', line 36

attribute :resource_pool_name

#switch_type:Private, ... (readonly)

Returns the type of network switch.

Returns:

  • (:Private, :Internal, :External)

    the type of network switch



39
# File 'lib/fog/hyperv/compute/models/switch.rb', line 39

attribute :switch_type, type: :hypervenum, values: %i[Private Internal External]

Instance Method Details

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/hyperv/compute/models/switch.rb', line 41

def create
  requires :name
  requires_one :net_adapter_name, :net_adapter_interface_description, :switch_type

  merge_attributes(
    service.new_vm_switch(
      computer_name:,
      name:,

      allow_management_os:,
      net_adapter_interface_description:,
      net_adapter_name:,
      notes:,
      switch_type: !net_adapter_interface_description && switch_type,

      _return_fields: self.class.attributes
    )
  )
end

#destroyObject



95
96
97
98
99
100
101
102
103
# File 'lib/fog/hyperv/compute/models/switch.rb', line 95

def destroy
  requires :id

  service.remove_vm_switch(
    computer_name:,
    id:
  )
  true
end

#reloadObject



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fog/hyperv/compute/models/switch.rb', line 105

def reload
  requires :id

  data = service.get_vm_switch(
    computer_name:,
    id:
  )
  return unless data

  merge_attributes(data)
end

#updateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fog/hyperv/compute/models/switch.rb', line 61

def update
  requires :id

  if changed?(:name)
    service.rename_vm_switch(
      computer_name: old.computer_name,
      id: old.id,

      new_name: name
    )
    @old.name = name
  end

  changes = {
    allow_management_os: changed!(:allow_management_os),
    default_flow_minimum_bandwidth_absolute: changed!(:default_flow_minimum_bandwidth_absolute),
    default_flow_minimum_bandwidth_weight: changed!(:default_flow_minimum_bandwidth_weight)
  }.compact
  changes[:notes] = notes || '' if changed? :notes
  return self unless changes.any?

  merge_attributes(
    service.set_vm_switch(
      computer_name: old.computer_name,
      id: old.id,

      **changes,

      _always_include: changes.keys,
      _return_fields: self.class.attributes
    )
  )
end