Class: OsVm::MachineConfig::SocketNetwork

Inherits:
Network
  • Object
show all
Defined in:
lib/osvm/machine_config.rb

Instance Attribute Summary collapse

Attributes inherited from Network

#index, #type

Instance Method Summary collapse

Methods inherited from Network

from_config

Constructor Details

#initialize(_i, cfg) ⇒ SocketNetwork

Returns a new instance of SocketNetwork.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/osvm/machine_config.rb', line 108

def initialize(_i, cfg)
  super

  mcast = cfg.fetch('mcast', {})

  @mcast_address = mcast.fetch('address', '230.0.0.1')

  mcast_port = mcast.fetch('port', 'net1')

  @mcast_port =
    case mcast_port
    when String
      PortReservation.get_port(key: "mcast:#{mcast_port}")
    when Integer
      mcast_port
    else
      raise "Invalid mcast port value #{mcast_port.inspect} (expected string or a number)"
    end
end

Instance Attribute Details

#mcast_addressString (readonly)

Returns:

  • (String)


103
104
105
# File 'lib/osvm/machine_config.rb', line 103

def mcast_address
  @mcast_address
end

#mcast_portInteger (readonly)

Returns:

  • (Integer)


106
107
108
# File 'lib/osvm/machine_config.rb', line 106

def mcast_port
  @mcast_port
end

Instance Method Details

#qemu_optionsObject



128
129
130
131
132
133
# File 'lib/osvm/machine_config.rb', line 128

def qemu_options
  [
    '-device', "virtio-net,netdev=net#{index}",
    '-netdev', "socket,id=net#{index},mcast=#{mcast_address}:#{mcast_port}"
  ]
end