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, #mac, #model, #type

Instance Method Summary collapse

Methods inherited from Network

#default_opts, from_config, #resolve_mac_address, #resolve_model

Constructor Details

#initialize(_i, cfg) ⇒ SocketNetwork

Returns a new instance of SocketNetwork.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/osvm/machine_config.rb', line 136

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)


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

def mcast_address
  @mcast_address
end

#mcast_portInteger (readonly)

Returns:

  • (Integer)


134
135
136
# File 'lib/osvm/machine_config.rb', line 134

def mcast_port
  @mcast_port
end

Instance Method Details

#qemu_optionsObject



156
157
158
159
160
161
# File 'lib/osvm/machine_config.rb', line 156

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