Class: LIBVIRT

Inherits:
Object
  • Object
show all
Defined in:
lib/libvirt.rb

Constant Summary collapse

CONF_FILE =
"/etc/libvirt/qemu/networks/pauper.xml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subnet) ⇒ LIBVIRT

Returns a new instance of LIBVIRT.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/libvirt.rb', line 7

def initialize(subnet)
  @subnet = subnet
  @ip = @subnet + '.1'
  @template = ERB.new <<EOF
<network>
<name>pauper</name>
<bridge name="pauperbr%d" />
<forward/>
<ip address="<%= ip %>" netmask="255.255.255.0">
  <dhcp>
    <range start="<%= subnet %>.100" end="<%= subnet %>.200" />
  </dhcp>
</ip>
</network>
EOF
end

Instance Attribute Details

#ipObject (readonly)

Returns the value of attribute ip.



3
4
5
# File 'lib/libvirt.rb', line 3

def ip
  @ip
end

#subnetObject (readonly)

Returns the value of attribute subnet.



2
3
4
# File 'lib/libvirt.rb', line 2

def subnet
  @subnet
end

Instance Method Details

#enableObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/libvirt.rb', line 24

def enable
  write_config
  unless active?
    unless loaded?
      load_config
    end
    start_network
    # The bridge needs a bit to settle
    sleep 3
  end
end

#interfaceObject



36
37
38
# File 'lib/libvirt.rb', line 36

def interface
  `sudo virsh net-info pauper | grep Bridge`.split(%r{\s+})[1]
end