Class: Bsdkrun::SandboxInfo

Inherits:
Data
  • Object
show all
Defined in:
lib/bsdkrun/types.rb

Overview

A machine as reported by bsdkrun ps --json.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def command
  @command
end

#cpusObject (readonly)

Returns the value of attribute cpus

Returns:

  • (Object)

    the current value of cpus



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def cpus
  @cpus
end

#created_atObject (readonly)

Returns the value of attribute created_at

Returns:

  • (Object)

    the current value of created_at



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def created_at
  @created_at
end

#detachedObject (readonly)

Returns the value of attribute detached

Returns:

  • (Object)

    the current value of detached



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def detached
  @detached
end

#exit_codeObject (readonly)

Returns the value of attribute exit_code

Returns:

  • (Object)

    the current value of exit_code



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def exit_code
  @exit_code
end

#finished_atObject (readonly)

Returns the value of attribute finished_at

Returns:

  • (Object)

    the current value of finished_at



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def finished_at
  @finished_at
end

#idString (readonly)

Returns:

  • (String)


34
35
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bsdkrun/types.rb', line 34

SandboxInfo = Data.define(
  :id, :name, :image, :kind, :command, :status, :running, :exit_code,
  :pid, :detached, :cpus, :mem, :volume, :state_dir, :network, :net_ip,
  :created_at, :finished_at, :ports
) do
  # Map a +ps --json+ row (String keys) to a typed instance.
  # @param row [Hash]
  # @return [SandboxInfo]
  def self.from_row(row)
    running = !!row["running"]
    new(
      id: row["id"].to_s,
      name: row["name"],
      image: row["image"].to_s,
      kind: row["kind"].to_s,
      command: (row["command"] || "").to_s,
      status: running ? "running" : "exited",
      running: running,
      exit_code: to_i_or_nil(row["exit_code"]),
      pid: to_i_or_nil(row["pid"]),
      detached: !!row["detached"],
      cpus: row["cpus"].to_i,
      mem: row["mem"].to_i,
      volume: row["volume"],
      state_dir: row["state_dir"].to_s,
      network: row["network"],
      net_ip: row["net_ip"],
      created_at: row["created_at"].to_i,
      finished_at: to_i_or_nil(row["finished_at"]),
      ports: (row["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end

  def self.to_i_or_nil(value)
    value.nil? ? nil : value.to_i
  end

  # Map a GraphQL +Machine+ object (String keys, camelCase — it comes from
  # +JSON.parse+ on the daemon's response, not the CLI) to a typed instance.
  # Sibling to {from_row}; same fields, different source and casing.
  #
  # @param m [Hash] a +MACHINE_FIELDS+-shaped hash, e.g. from
  #   {Bsdkrun::Client#list} / {Bsdkrun::Client#get}.
  # @return [SandboxInfo]
  def self.from_graphql(m)
    running = !!m["running"]
    new(
      id: m["id"].to_s,
      name: m["name"],
      image: m["image"].to_s,
      kind: m["kind"].to_s,
      command: (m["command"] || "").to_s,
      status: m["status"].to_s,
      running: running,
      exit_code: to_i_or_nil(m["exitCode"]),
      pid: to_i_or_nil(m["pid"]),
      detached: !!m["detached"],
      cpus: m["cpus"].to_i,
      mem: m["mem"].to_i,
      volume: m["volume"],
      state_dir: m["stateDir"].to_s,
      network: m["network"],
      net_ip: m["netIp"],
      created_at: m["createdAt"].to_i,
      finished_at: to_i_or_nil(m["finishedAt"]),
      ports: (m["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end
end

#imageObject (readonly)

Returns the value of attribute image

Returns:

  • (Object)

    the current value of image



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def image
  @image
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def kind
  @kind
end

#memObject (readonly)

Returns the value of attribute mem

Returns:

  • (Object)

    the current value of mem



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def mem
  @mem
end

#nameString? (readonly)

Returns DNS name on a network, or nil if unnamed.

Returns:

  • (String, nil)

    DNS name on a network, or nil if unnamed.



34
35
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bsdkrun/types.rb', line 34

SandboxInfo = Data.define(
  :id, :name, :image, :kind, :command, :status, :running, :exit_code,
  :pid, :detached, :cpus, :mem, :volume, :state_dir, :network, :net_ip,
  :created_at, :finished_at, :ports
) do
  # Map a +ps --json+ row (String keys) to a typed instance.
  # @param row [Hash]
  # @return [SandboxInfo]
  def self.from_row(row)
    running = !!row["running"]
    new(
      id: row["id"].to_s,
      name: row["name"],
      image: row["image"].to_s,
      kind: row["kind"].to_s,
      command: (row["command"] || "").to_s,
      status: running ? "running" : "exited",
      running: running,
      exit_code: to_i_or_nil(row["exit_code"]),
      pid: to_i_or_nil(row["pid"]),
      detached: !!row["detached"],
      cpus: row["cpus"].to_i,
      mem: row["mem"].to_i,
      volume: row["volume"],
      state_dir: row["state_dir"].to_s,
      network: row["network"],
      net_ip: row["net_ip"],
      created_at: row["created_at"].to_i,
      finished_at: to_i_or_nil(row["finished_at"]),
      ports: (row["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end

  def self.to_i_or_nil(value)
    value.nil? ? nil : value.to_i
  end

  # Map a GraphQL +Machine+ object (String keys, camelCase — it comes from
  # +JSON.parse+ on the daemon's response, not the CLI) to a typed instance.
  # Sibling to {from_row}; same fields, different source and casing.
  #
  # @param m [Hash] a +MACHINE_FIELDS+-shaped hash, e.g. from
  #   {Bsdkrun::Client#list} / {Bsdkrun::Client#get}.
  # @return [SandboxInfo]
  def self.from_graphql(m)
    running = !!m["running"]
    new(
      id: m["id"].to_s,
      name: m["name"],
      image: m["image"].to_s,
      kind: m["kind"].to_s,
      command: (m["command"] || "").to_s,
      status: m["status"].to_s,
      running: running,
      exit_code: to_i_or_nil(m["exitCode"]),
      pid: to_i_or_nil(m["pid"]),
      detached: !!m["detached"],
      cpus: m["cpus"].to_i,
      mem: m["mem"].to_i,
      volume: m["volume"],
      state_dir: m["stateDir"].to_s,
      network: m["network"],
      net_ip: m["netIp"],
      created_at: m["createdAt"].to_i,
      finished_at: to_i_or_nil(m["finishedAt"]),
      ports: (m["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end
end

#net_ipObject (readonly)

Returns the value of attribute net_ip

Returns:

  • (Object)

    the current value of net_ip



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def net_ip
  @net_ip
end

#networkObject (readonly)

Returns the value of attribute network

Returns:

  • (Object)

    the current value of network



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def network
  @network
end

#pidObject (readonly)

Returns the value of attribute pid

Returns:

  • (Object)

    the current value of pid



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def pid
  @pid
end

#portsArray<PortForward> (readonly)

Returns host<->guest TCP port forwards.

Returns:

  • (Array<PortForward>)

    host<->guest TCP port forwards.



34
35
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bsdkrun/types.rb', line 34

SandboxInfo = Data.define(
  :id, :name, :image, :kind, :command, :status, :running, :exit_code,
  :pid, :detached, :cpus, :mem, :volume, :state_dir, :network, :net_ip,
  :created_at, :finished_at, :ports
) do
  # Map a +ps --json+ row (String keys) to a typed instance.
  # @param row [Hash]
  # @return [SandboxInfo]
  def self.from_row(row)
    running = !!row["running"]
    new(
      id: row["id"].to_s,
      name: row["name"],
      image: row["image"].to_s,
      kind: row["kind"].to_s,
      command: (row["command"] || "").to_s,
      status: running ? "running" : "exited",
      running: running,
      exit_code: to_i_or_nil(row["exit_code"]),
      pid: to_i_or_nil(row["pid"]),
      detached: !!row["detached"],
      cpus: row["cpus"].to_i,
      mem: row["mem"].to_i,
      volume: row["volume"],
      state_dir: row["state_dir"].to_s,
      network: row["network"],
      net_ip: row["net_ip"],
      created_at: row["created_at"].to_i,
      finished_at: to_i_or_nil(row["finished_at"]),
      ports: (row["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end

  def self.to_i_or_nil(value)
    value.nil? ? nil : value.to_i
  end

  # Map a GraphQL +Machine+ object (String keys, camelCase — it comes from
  # +JSON.parse+ on the daemon's response, not the CLI) to a typed instance.
  # Sibling to {from_row}; same fields, different source and casing.
  #
  # @param m [Hash] a +MACHINE_FIELDS+-shaped hash, e.g. from
  #   {Bsdkrun::Client#list} / {Bsdkrun::Client#get}.
  # @return [SandboxInfo]
  def self.from_graphql(m)
    running = !!m["running"]
    new(
      id: m["id"].to_s,
      name: m["name"],
      image: m["image"].to_s,
      kind: m["kind"].to_s,
      command: (m["command"] || "").to_s,
      status: m["status"].to_s,
      running: running,
      exit_code: to_i_or_nil(m["exitCode"]),
      pid: to_i_or_nil(m["pid"]),
      detached: !!m["detached"],
      cpus: m["cpus"].to_i,
      mem: m["mem"].to_i,
      volume: m["volume"],
      state_dir: m["stateDir"].to_s,
      network: m["network"],
      net_ip: m["netIp"],
      created_at: m["createdAt"].to_i,
      finished_at: to_i_or_nil(m["finishedAt"]),
      ports: (m["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end
end

#runningObject (readonly)

Returns the value of attribute running

Returns:

  • (Object)

    the current value of running



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def running
  @running
end

#state_dirObject (readonly)

Returns the value of attribute state_dir

Returns:

  • (Object)

    the current value of state_dir



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def state_dir
  @state_dir
end

#statusString (readonly)

Returns "running" or "exited" (derived from running).

Returns:

  • (String)

    "running" or "exited" (derived from running).



34
35
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bsdkrun/types.rb', line 34

SandboxInfo = Data.define(
  :id, :name, :image, :kind, :command, :status, :running, :exit_code,
  :pid, :detached, :cpus, :mem, :volume, :state_dir, :network, :net_ip,
  :created_at, :finished_at, :ports
) do
  # Map a +ps --json+ row (String keys) to a typed instance.
  # @param row [Hash]
  # @return [SandboxInfo]
  def self.from_row(row)
    running = !!row["running"]
    new(
      id: row["id"].to_s,
      name: row["name"],
      image: row["image"].to_s,
      kind: row["kind"].to_s,
      command: (row["command"] || "").to_s,
      status: running ? "running" : "exited",
      running: running,
      exit_code: to_i_or_nil(row["exit_code"]),
      pid: to_i_or_nil(row["pid"]),
      detached: !!row["detached"],
      cpus: row["cpus"].to_i,
      mem: row["mem"].to_i,
      volume: row["volume"],
      state_dir: row["state_dir"].to_s,
      network: row["network"],
      net_ip: row["net_ip"],
      created_at: row["created_at"].to_i,
      finished_at: to_i_or_nil(row["finished_at"]),
      ports: (row["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end

  def self.to_i_or_nil(value)
    value.nil? ? nil : value.to_i
  end

  # Map a GraphQL +Machine+ object (String keys, camelCase — it comes from
  # +JSON.parse+ on the daemon's response, not the CLI) to a typed instance.
  # Sibling to {from_row}; same fields, different source and casing.
  #
  # @param m [Hash] a +MACHINE_FIELDS+-shaped hash, e.g. from
  #   {Bsdkrun::Client#list} / {Bsdkrun::Client#get}.
  # @return [SandboxInfo]
  def self.from_graphql(m)
    running = !!m["running"]
    new(
      id: m["id"].to_s,
      name: m["name"],
      image: m["image"].to_s,
      kind: m["kind"].to_s,
      command: (m["command"] || "").to_s,
      status: m["status"].to_s,
      running: running,
      exit_code: to_i_or_nil(m["exitCode"]),
      pid: to_i_or_nil(m["pid"]),
      detached: !!m["detached"],
      cpus: m["cpus"].to_i,
      mem: m["mem"].to_i,
      volume: m["volume"],
      state_dir: m["stateDir"].to_s,
      network: m["network"],
      net_ip: m["netIp"],
      created_at: m["createdAt"].to_i,
      finished_at: to_i_or_nil(m["finishedAt"]),
      ports: (m["ports"] || []).map { |p| PortForward.from_row(p) }
    )
  end
end

#volumeObject (readonly)

Returns the value of attribute volume

Returns:

  • (Object)

    the current value of volume



34
35
36
# File 'lib/bsdkrun/types.rb', line 34

def volume
  @volume
end

Class Method Details

.from_graphql(m) ⇒ SandboxInfo

Map a GraphQL Machine object (String keys, camelCase — it comes from JSON.parse on the daemon's response, not the CLI) to a typed instance. Sibling to from_row; same fields, different source and casing.

Parameters:

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bsdkrun/types.rb', line 78

def self.from_graphql(m)
  running = !!m["running"]
  new(
    id: m["id"].to_s,
    name: m["name"],
    image: m["image"].to_s,
    kind: m["kind"].to_s,
    command: (m["command"] || "").to_s,
    status: m["status"].to_s,
    running: running,
    exit_code: to_i_or_nil(m["exitCode"]),
    pid: to_i_or_nil(m["pid"]),
    detached: !!m["detached"],
    cpus: m["cpus"].to_i,
    mem: m["mem"].to_i,
    volume: m["volume"],
    state_dir: m["stateDir"].to_s,
    network: m["network"],
    net_ip: m["netIp"],
    created_at: m["createdAt"].to_i,
    finished_at: to_i_or_nil(m["finishedAt"]),
    ports: (m["ports"] || []).map { |p| PortForward.from_row(p) }
  )
end

.from_row(row) ⇒ SandboxInfo

Map a ps --json row (String keys) to a typed instance.

Parameters:

  • row (Hash)

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bsdkrun/types.rb', line 42

def self.from_row(row)
  running = !!row["running"]
  new(
    id: row["id"].to_s,
    name: row["name"],
    image: row["image"].to_s,
    kind: row["kind"].to_s,
    command: (row["command"] || "").to_s,
    status: running ? "running" : "exited",
    running: running,
    exit_code: to_i_or_nil(row["exit_code"]),
    pid: to_i_or_nil(row["pid"]),
    detached: !!row["detached"],
    cpus: row["cpus"].to_i,
    mem: row["mem"].to_i,
    volume: row["volume"],
    state_dir: row["state_dir"].to_s,
    network: row["network"],
    net_ip: row["net_ip"],
    created_at: row["created_at"].to_i,
    finished_at: to_i_or_nil(row["finished_at"]),
    ports: (row["ports"] || []).map { |p| PortForward.from_row(p) }
  )
end

.to_i_or_nil(value) ⇒ Object



67
68
69
# File 'lib/bsdkrun/types.rb', line 67

def self.to_i_or_nil(value)
  value.nil? ? nil : value.to_i
end