Class: Bsdkrun::SandboxInfo
- Inherits:
-
Data
- Object
- Data
- Bsdkrun::SandboxInfo
- Defined in:
- lib/bsdkrun/types.rb
Overview
A machine as reported by bsdkrun ps --json.
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#cpus ⇒ Object
readonly
Returns the value of attribute cpus.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#detached ⇒ Object
readonly
Returns the value of attribute detached.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
- #id ⇒ String readonly
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#mem ⇒ Object
readonly
Returns the value of attribute mem.
-
#name ⇒ String?
readonly
DNS name on a network, or nil if unnamed.
-
#net_ip ⇒ Object
readonly
Returns the value of attribute net_ip.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#ports ⇒ Array<PortForward>
readonly
Host<->guest TCP port forwards.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#state_dir ⇒ Object
readonly
Returns the value of attribute state_dir.
-
#status ⇒ String
readonly
"running" or "exited" (derived from
running). -
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Class Method Summary collapse
-
.from_graphql(m) ⇒ SandboxInfo
Map a GraphQL
Machineobject (String keys, camelCase — it comes fromJSON.parseon the daemon's response, not the CLI) to a typed instance. -
.from_row(row) ⇒ SandboxInfo
Map a
ps --jsonrow (String keys) to a typed instance. - .to_i_or_nil(value) ⇒ Object
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def command @command end |
#cpus ⇒ Object (readonly)
Returns the value of attribute cpus
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def cpus @cpus end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def created_at @created_at end |
#detached ⇒ Object (readonly)
Returns the value of attribute detached
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def detached @detached end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def exit_code @exit_code end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def finished_at @finished_at end |
#id ⇒ String (readonly)
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 |
#image ⇒ Object (readonly)
Returns the value of attribute image
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def image @image end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def kind @kind end |
#mem ⇒ Object (readonly)
Returns the value of attribute mem
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def mem @mem end |
#name ⇒ String? (readonly)
Returns 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_ip ⇒ Object (readonly)
Returns the value of attribute net_ip
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def net_ip @net_ip end |
#network ⇒ Object (readonly)
Returns the value of attribute network
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def network @network end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def pid @pid end |
#ports ⇒ Array<PortForward> (readonly)
Returns 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 |
#running ⇒ Object (readonly)
Returns the value of attribute running
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def running @running end |
#state_dir ⇒ Object (readonly)
Returns the value of attribute state_dir
34 35 36 |
# File 'lib/bsdkrun/types.rb', line 34 def state_dir @state_dir end |
#status ⇒ String (readonly)
Returns "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 |
#volume ⇒ Object (readonly)
Returns the value of attribute 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.
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.
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 |