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

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.

Parameters:

  • machine (String)

    id or name.

  • network (String)


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).

Parameters:

  • name (String)


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.

Parameters:

  • machine (String)


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

.listArray<NetworkInfo>

List global networks and their member counts.

Returns:



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).

Parameters:

  • network (String)

Returns:



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.

Parameters:

  • names (String, Array<String>)
  • force (Boolean) (defaults to: false)


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

.sync(network) ⇒ void

This method returns an undefined value.

Refresh members' /etc/hosts so peers resolve by name (notably NetBSD).

Parameters:

  • network (String)


59
60
61
62
# File 'lib/bsdkrun/networks.rb', line 59

def sync(network)
  Process.run!(["network", "sync", network], label: "bsdkrun network sync")
  nil
end