Class: OsVm::MachineConfig::BridgeNetwork

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

Instance Attribute Summary collapse

Attributes inherited from Network

#mode

Instance Method Summary collapse

Methods inherited from Network

from_config

Constructor Details

#initialize(cfg) ⇒ BridgeNetwork

Returns a new instance of BridgeNetwork.



98
99
100
101
102
# File 'lib/osvm/machine_config.rb', line 98

def initialize(cfg)
  super
  @link = @opts.fetch(:link)
  @mac = gen_mac_address
end

Instance Attribute Details

Returns:

  • (String)


93
94
95
# File 'lib/osvm/machine_config.rb', line 93

def link
  @link
end

#macString (readonly)

Returns:

  • (String)


96
97
98
# File 'lib/osvm/machine_config.rb', line 96

def mac
  @mac
end

Instance Method Details

#gen_mac_addressObject (protected)



113
114
115
# File 'lib/osvm/machine_config.rb', line 113

def gen_mac_address
  "00:60:2f:#{SecureRandom.hex(3).chars.each_slice(2).map(&:join).join(':')}"
end

#qemu_optionsObject



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

def qemu_options
  [
    '-device', "virtio-net,netdev=net1,mac=#{@mac}",
    '-netdev', "bridge,id=net1,br=#{link}"
  ]
end