Class: Clusterfuck::Machine
- Inherits:
-
Object
- Object
- Clusterfuck::Machine
- Defined in:
- lib/clusterfuck/machine.rb
Direct Known Subclasses
Defined Under Namespace
Classes: PortFactory
Instance Attribute Summary collapse
-
#cluster ⇒ Object
Returns the value of attribute cluster.
-
#gateway ⇒ Object
Returns the value of attribute gateway.
-
#ips ⇒ Object
Returns the value of attribute ips.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#routes ⇒ Object
Returns the value of attribute routes.
-
#ssh_port ⇒ Object
readonly
Returns the value of attribute ssh_port.
Instance Method Summary collapse
- #build(config) ⇒ Object
-
#initialize(name, **args) ⇒ Machine
constructor
A new instance of Machine.
- #ip_in_same_subnet(other) ⇒ Object
Constructor Details
#initialize(name, **args) ⇒ Machine
Returns a new instance of Machine.
6 7 8 9 10 11 12 |
# File 'lib/clusterfuck/machine.rb', line 6 def initialize(name, **args) @name = name @ips = [] @ssh_port = args[:ssh_port] || PortFactory.next @gateway = args[:gateway] @routes = args[:routes] end |
Instance Attribute Details
#cluster ⇒ Object
Returns the value of attribute cluster.
4 5 6 |
# File 'lib/clusterfuck/machine.rb', line 4 def cluster @cluster end |
#gateway ⇒ Object
Returns the value of attribute gateway.
4 5 6 |
# File 'lib/clusterfuck/machine.rb', line 4 def gateway @gateway end |
#ips ⇒ Object
Returns the value of attribute ips.
4 5 6 |
# File 'lib/clusterfuck/machine.rb', line 4 def ips @ips end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/clusterfuck/machine.rb', line 3 def name @name end |
#routes ⇒ Object
Returns the value of attribute routes.
4 5 6 |
# File 'lib/clusterfuck/machine.rb', line 4 def routes @routes end |
#ssh_port ⇒ Object (readonly)
Returns the value of attribute ssh_port.
3 4 5 |
# File 'lib/clusterfuck/machine.rb', line 3 def ssh_port @ssh_port end |
Instance Method Details
#build(config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/clusterfuck/machine.rb', line 18 def build(config) config.vm.define(name) do |box| box.vm.hostname = name # Set up SSH on a predictable port which allows us to hook into it # during tests. box.vm.network :forwarded_port, guest: 22, host: ssh_port, id: "ssh" ips.each do |ip| box.vm.network :private_network, ip: ip.addr, # TODO Troll Rubby people by using a refinement netmask: ip.netmask, # TODO Vagrant already provides an abstraction for declaring networks # so we should not need to duplicate this abstraction by creating # subclasses for each provider. This bullshit needs to be gone for # AWS/CI support. virtualbox__intnet: true end if gateway box.vm.provision :file, source: tmp_routes_file, destination: "/tmp/network-clusterfuck" box.vm.provision :shell, inline: <<-EOS mv /tmp/network-clusterfuck /etc/network/if-up.d/clusterfuck chmod +x /etc/network/if-up.d/clusterfuck ifdown eth1 ifup eth1 EOS end yield box if block_given? end end |
#ip_in_same_subnet(other) ⇒ Object
14 15 16 |
# File 'lib/clusterfuck/machine.rb', line 14 def ip_in_same_subnet(other) cluster.ip_in_same_subnet(self, other) end |