Module: Bsdkrun::Networks
- Defined in:
- lib/bsdkrun/networks.rb
Overview
Global-network operations — shared subnets where members reach each other by IP and by name.
Class Method Summary collapse
-
.connect(machine, network) ⇒ void
Join or switch a machine to a network.
-
.create(name) ⇒ void
Create a global network (starts its shared switch).
-
.disconnect(machine) ⇒ void
Detach a machine from its network.
-
.list ⇒ Array<NetworkInfo>
List global networks and their member counts.
-
.members(network) ⇒ Array<SandboxInfo>
The machines currently attached to
network(running or stopped). -
.remove(names, force: false) ⇒ void
Remove one or more networks.
-
.sync(network) ⇒ void
Refresh members'
/etc/hostsso peers resolve by name (notably NetBSD).
Class Method Details
.connect(machine, network) ⇒ void
This method returns an undefined value.
Join or switch a machine to a network. Applies on the machine's next start.
43 44 45 46 |
# File 'lib/bsdkrun/networks.rb', line 43 def connect(machine, network) Process.run!(["network", "connect", machine, network], label: "bsdkrun network connect") nil end |
.create(name) ⇒ void
This method returns an undefined value.
Create a global network (starts its shared switch).
22 23 24 25 |
# File 'lib/bsdkrun/networks.rb', line 22 def create(name) Process.run!(["network", "create", name], label: "bsdkrun network create") nil end |
.disconnect(machine) ⇒ void
This method returns an undefined value.
Detach a machine from its network. Applies on its next start.
51 52 53 54 |
# File 'lib/bsdkrun/networks.rb', line 51 def disconnect(machine) Process.run!(["network", "disconnect", machine], label: "bsdkrun network disconnect") nil end |
.list ⇒ Array<NetworkInfo>
List global networks and their member counts.
13 14 15 16 17 |
# File 'lib/bsdkrun/networks.rb', line 13 def list res = Process.run!(["network", "ls", "--json"], label: "bsdkrun network ls") rows = JSON.parse(res.stdout.empty? ? "[]" : res.stdout) rows.map { |row| NetworkInfo.from_row(row) } end |
.members(network) ⇒ Array<SandboxInfo>
The machines currently attached to network (running or stopped).
67 68 69 |
# File 'lib/bsdkrun/networks.rb', line 67 def members(network) Sandbox.list(all: true).select { |m| m.network == network } end |
.remove(names, force: false) ⇒ void
This method returns an undefined value.
Remove one or more networks. force allows removal with running members.
31 32 33 34 35 36 37 |
# File 'lib/bsdkrun/networks.rb', line 31 def remove(names, force: false) args = ["network", "rm"] args << "--force" if force args.concat(Array(names)) Process.run!(args, label: "bsdkrun network rm") nil end |