Class: Construqt::Flavour::Ubuntu::Device
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Construqt::Flavour::Ubuntu::Device
- Defined in:
- lib/construqt/flavour/ubuntu/flavour_ubuntu.rb
Overview
end
Class Method Summary collapse
- .add_address(host, ifname, iface, lines, writer) ⇒ Object
- .add_services(host, ifname, iface, writer) ⇒ Object
- .build_config(host, iface) ⇒ Object
Instance Method Summary collapse
- #build_config(host, iface) ⇒ Object
-
#initialize(cfg) ⇒ Device
constructor
A new instance of Device.
Constructor Details
#initialize(cfg) ⇒ Device
Returns a new instance of Device.
32 33 34 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 32 def initialize(cfg) super(cfg) end |
Class Method Details
.add_address(host, ifname, iface, lines, writer) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 36 def self.add_address(host, ifname, iface, lines, writer) if iface.address.nil? Firewall.create(host, ifname, iface) return end writer.header.mode(EtcNetworkInterfaces::Entry::Header::MODE_DHCP) if iface.address.dhcpv4? writer.header.mode(EtcNetworkInterfaces::Entry::Header::MODE_LOOPBACK) if iface.address.loopback? lines.add(iface.flavour) if iface.flavour iface.address.ips.each do |ip| lines.up("ip addr add #{ip.to_string} dev #{ifname}") lines.down("ip addr del #{ip.to_string} dev #{ifname}") end iface.address.routes.each do |route| if route.metric metric = " metric #{route.metric}" else metric = "" end lines.up("ip route add #{route.dst.to_string} via #{route.via.to_s}#{metric}") lines.down("ip route del #{route.dst.to_string} via #{route.via.to_s}#{metric}") end Firewall.create(host, ifname, iface) end |
.add_services(host, ifname, iface, writer) ⇒ Object
67 68 69 70 71 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 67 def self.add_services(host, ifname, iface, writer) iface.services && iface.services.each do |service| Services.get_renderer(service).interfaces(host, ifname, iface, writer) end end |
.build_config(host, iface) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 73 def self.build_config(host, iface) # binding.pry writer = host.result.etc_network_interfaces.get(iface) writer.header.protocol(EtcNetworkInterfaces::Entry::Header::PROTO_INET4) #binding.pry #unless iface.delegate writer.lines.add(iface.delegate.flavour) if iface.delegate.flavour ifname = writer.header.get_interface_name # ifaces.header.mode(Result::EtcNetworkInterfaces::Entry::Header::MODE_DHCP4) if iface.address.dhcpv4? # ifaces.header.mode(Result::EtcNetworkInterfaces::Entry::Header::MODE_LOOOPBACK) if iface.address.loopback? writer.lines.up("ip link set mtu #{iface.delegate.mtu} dev #{ifname} up") writer.lines.down("ip link set dev #{ifname} down") add_address(host, ifname, iface.delegate, writer.lines, writer) #unless iface.address.nil? || iface.address.ips.empty? add_services(host, ifname, iface.delegate, writer) end |
Instance Method Details
#build_config(host, iface) ⇒ Object
63 64 65 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 63 def build_config(host, iface) self.class.build_config(host, iface) end |