Class: OsVm::MachineConfig::Network
- Inherits:
-
Object
- Object
- OsVm::MachineConfig::Network
show all
- Defined in:
- lib/osvm/machine_config.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(i, cfg) ⇒ Network
Returns a new instance of Network.
78
79
80
81
82
83
|
# File 'lib/osvm/machine_config.rb', line 78
def initialize(i, cfg)
@index = i
@type = cfg.fetch('type')
@opts = cfg.fetch('opts', default_opts)
@mac = resolve_mac_address(cfg)
end
|
Instance Attribute Details
#index ⇒ String, Integer
70
71
72
|
# File 'lib/osvm/machine_config.rb', line 70
def index
@index
end
|
#mac ⇒ String
76
77
78
|
# File 'lib/osvm/machine_config.rb', line 76
def mac
@mac
end
|
#type ⇒ String
73
74
75
|
# File 'lib/osvm/machine_config.rb', line 73
def type
@type
end
|
Class Method Details
.from_config(i, cfg) ⇒ Network
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/osvm/machine_config.rb', line 51
def self.from_config(i, cfg)
type = cfg.fetch('type')
klass =
case type
when 'user'
UserNetwork
when 'socket'
SocketNetwork
when 'bridge'
BridgeNetwork
else
raise ArgumentError, "unknown network type #{type.inspect}"
end
klass.new(i, cfg)
end
|
Instance Method Details
#default_opts ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/osvm/machine_config.rb', line 99
def default_opts
{
'network' => '10.0.2.0/24',
'host' => '10.0.2.2',
'dns' => '10.0.2.3'
}
end
|
#qemu_options ⇒ Object
85
86
87
|
# File 'lib/osvm/machine_config.rb', line 85
def qemu_options
raise NotImplementedError
end
|
#resolve_mac_address(cfg) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/osvm/machine_config.rb', line 91
def resolve_mac_address(cfg)
mac = cfg['macAddress'] || cfg['mac'] || @opts['macAddress'] || @opts['mac']
mac = mac.to_s.downcase unless mac.nil?
return MacAddressGenerator.register_mac(mac) if mac && !mac.empty?
MacAddressGenerator.next_mac
end
|