octaspace 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +93 -30
  3. data/LICENSE +21 -0
  4. data/README.md +104 -289
  5. data/lib/octaspace/client.rb +40 -23
  6. data/lib/octaspace/configuration.rb +73 -14
  7. data/lib/octaspace/errors.rb +70 -39
  8. data/lib/octaspace/json_null.rb +56 -0
  9. data/lib/octaspace/middleware/url_rotator.rb +3 -3
  10. data/lib/octaspace/model.rb +115 -0
  11. data/lib/octaspace/money.rb +69 -0
  12. data/lib/octaspace/railtie.rb +1 -2
  13. data/lib/octaspace/resources/accounts.rb +8 -20
  14. data/lib/octaspace/resources/base.rb +49 -2
  15. data/lib/octaspace/resources/compute.rb +123 -0
  16. data/lib/octaspace/resources/hosting.rb +107 -0
  17. data/lib/octaspace/resources/network.rb +24 -5
  18. data/lib/octaspace/resources/render.rb +46 -0
  19. data/lib/octaspace/resources/sessions.rb +125 -10
  20. data/lib/octaspace/resources/stats.rb +57 -0
  21. data/lib/octaspace/resources/vpn.rb +48 -0
  22. data/lib/octaspace/response.rb +62 -12
  23. data/lib/octaspace/transport/base.rb +30 -30
  24. data/lib/octaspace/transport/faraday_transport.rb +157 -91
  25. data/lib/octaspace/transport/persistent_transport.rb +23 -49
  26. data/lib/octaspace/types/account.rb +17 -4
  27. data/lib/octaspace/types/hosting.rb +116 -0
  28. data/lib/octaspace/types/machines.rb +158 -0
  29. data/lib/octaspace/types/network.rb +87 -0
  30. data/lib/octaspace/types/session.rb +173 -4
  31. data/lib/octaspace/types/stats.rb +143 -0
  32. data/lib/octaspace/version.rb +1 -1
  33. data/lib/octaspace.rb +21 -19
  34. metadata +30 -35
  35. data/MIT-LICENSE +0 -22
  36. data/lib/octaspace/payload_helpers.rb +0 -53
  37. data/lib/octaspace/resources/apps.rb +0 -19
  38. data/lib/octaspace/resources/idle_jobs.rb +0 -32
  39. data/lib/octaspace/resources/nodes.rb +0 -63
  40. data/lib/octaspace/resources/services/machine_rental.rb +0 -78
  41. data/lib/octaspace/resources/services/render.rb +0 -30
  42. data/lib/octaspace/resources/services/session_proxy.rb +0 -54
  43. data/lib/octaspace/resources/services/vpn.rb +0 -30
  44. data/lib/octaspace/resources/services.rb +0 -39
  45. data/lib/octaspace/types/balance.rb +0 -11
  46. data/lib/octaspace/types/node.rb +0 -12
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OctaSpace
4
+ module Types
5
+ # Price percentiles, micro-USD per GPU-hour; nil where there is no data
6
+ class PricePercentiles < Model
7
+ attribute :p10, :p25, :p50, :p75, :p90
8
+ end
9
+
10
+ # One GPU model on the market now
11
+ class GpuMarketModel < Model
12
+ # @!attribute [r] total
13
+ # @return [Integer] GPUs (not nodes) of this model
14
+ # @!attribute [r] usage
15
+ # @return [Float] percent rented now
16
+ # @!attribute [r] usage_30d
17
+ # @return [Float, nil] average percent rented over 30 days
18
+ # @!attribute [r] memory_mb
19
+ # @return [Integer, nil] memory of one GPU, MiB: the size most GPUs of
20
+ # the model have
21
+ attribute :model, :total, :available, :rented, :usage, :usage_30d, :memory_mb, :ai_score, :tflops, :tflops_per_dollar
22
+ attribute :available_price, :rented_price, model: PricePercentiles
23
+ end
24
+
25
+ # GPU market now (+GET /stats/gpu/current+), most common models first
26
+ class GpuMarket < Model
27
+ # @!attribute [r] at
28
+ # @return [Integer] snapshot time, Unix seconds
29
+ attribute :at
30
+ attribute :gpus, model: GpuMarketModel, many: true
31
+
32
+ # @return [Time, nil]
33
+ def time = at.is_a?(Numeric) ? Time.at(at) : nil
34
+ end
35
+
36
+ # Parallel arrays of GPU counts
37
+ class SupplyDemand < Model
38
+ attribute :total, :available, :rented
39
+ end
40
+
41
+ # Parallel arrays of price percentiles
42
+ class PriceSeries < Model
43
+ attribute :p10, :p25, :p50, :p75, :p90
44
+ end
45
+
46
+ # One point of a model's history, see {GpuHistory#points}
47
+ GpuHistoryPoint = Data.define(:ts, :total, :available, :rented, :available_price, :rented_price) do
48
+ # @return [Time]
49
+ def time = Time.at(ts)
50
+ end
51
+
52
+ # History of one GPU model (+GET /stats/gpu/history+): parallel arrays,
53
+ # one value per entry of {#timestamps}
54
+ class GpuHistory < Model
55
+ # @!attribute [r] timestamps
56
+ # @return [Array<Integer>] Unix seconds
57
+ attribute :timestamps, :tflops
58
+ attribute :supply_demand, model: SupplyDemand
59
+ attribute :available_price, :rented_price, model: PriceSeries
60
+
61
+ # Turns the parallel arrays into one point per timestamp, e.g. for a chart.
62
+ # @return [Array<GpuHistoryPoint>]
63
+ def points
64
+ Array(timestamps).each_with_index.map do |ts, i|
65
+ GpuHistoryPoint.new(
66
+ ts: ts,
67
+ total: series_at(supply_demand, :total, i),
68
+ available: series_at(supply_demand, :available, i),
69
+ rented: series_at(supply_demand, :rented, i),
70
+ available_price: percentiles_at(available_price, i),
71
+ rented_price: percentiles_at(rented_price, i)
72
+ )
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def series_at(model, key, i) = model&.public_send(key)&.at(i)
79
+
80
+ def percentiles_at(series, i)
81
+ PricePercentiles.new(%w[p10 p25 p50 p75 p90].to_h { |p| [p, series_at(series, p, i)] })
82
+ end
83
+ end
84
+
85
+ # GPUs of one model in one city (+GET /stats/gpu/locations+)
86
+ class GpuLocation < Model
87
+ # @!attribute [r] gpus
88
+ # @return [Integer] GPUs of this model in the city
89
+ # @!attribute [r] verified
90
+ # @return [Integer] of them on verified nodes
91
+ attribute :city, :country, :latitude, :longitude, :model, :gpus, :rented, :verified
92
+ end
93
+
94
+ # One miner, algorithm or pool of {MiningUsage}
95
+ class MiningRow < Model
96
+ # @!attribute [r] name
97
+ # @return [String] catalogue name, or "other"
98
+ # @!attribute [r] started
99
+ # @return [Integer] sessions that started (or restarted) with it
100
+ # @!attribute [r] gpu_hours
101
+ # @return [Float] hours times GPUs; 0 for the CPU role
102
+ # @!attribute [r] coins
103
+ # @return [Array<String>, nil] pools only
104
+ attribute :name, :label, :started, :hours, :gpu_hours, :coins
105
+ end
106
+
107
+ # Totals of {MiningUsage}
108
+ class MiningTotal < Model
109
+ attribute :started, :hours, :gpu_hours
110
+ end
111
+
112
+ # Miners per day of {MiningUsage}
113
+ class MiningDaily < Model
114
+ # @!attribute [r] dates
115
+ # @return [Array<String>] ISO dates
116
+ # @!attribute [r] miners
117
+ # @return [Hash{String=>Array<Float>}] one value of {MiningUsage#measure}
118
+ # per date, by miner name
119
+ attribute :dates, :miners
120
+ end
121
+
122
+ # What the platform's mining sessions run (+GET /stats/mining+), most used first
123
+ class MiningUsage < Model
124
+ # @!attribute [r] role
125
+ # @return [String] "gpu" or "cpu"
126
+ # @!attribute [r] from
127
+ # @return [String] first day, ISO date
128
+ # @!attribute [r] to
129
+ # @return [String] last day, ISO date
130
+ # @!attribute [r] measure
131
+ # @return [String] "gpu_hours" or "hours"
132
+ # @!attribute [r] at
133
+ # @return [Integer, nil] snapshot time, Unix seconds
134
+ attribute :role, :days, :from, :to, :measure, :at
135
+ attribute :total, model: MiningTotal
136
+ attribute :miners, :algorithms, :pools, model: MiningRow, many: true
137
+ attribute :daily, model: MiningDaily
138
+
139
+ # @return [Time, nil]
140
+ def time = at.is_a?(Numeric) ? Time.at(at) : nil
141
+ end
142
+ end
143
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OctaSpace
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/octaspace.rb CHANGED
@@ -1,33 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "octaspace/version"
4
+ require "octaspace/configuration"
4
5
  require "octaspace/errors"
5
- require "octaspace/payload_helpers"
6
6
  require "octaspace/response"
7
- require "octaspace/configuration"
7
+ require "octaspace/json_null"
8
+ require "octaspace/money"
9
+ require "octaspace/model"
8
10
  require "octaspace/middleware/url_rotator"
9
11
  require "octaspace/transport/base"
10
12
  require "octaspace/transport/faraday_transport"
11
- require "octaspace/types/account"
12
- require "octaspace/types/balance"
13
- require "octaspace/types/node"
13
+ require "octaspace/types/machines"
14
14
  require "octaspace/types/session"
15
+ require "octaspace/types/account"
16
+ require "octaspace/types/network"
17
+ require "octaspace/types/hosting"
18
+ require "octaspace/types/stats"
15
19
  require "octaspace/resources/base"
16
20
  require "octaspace/resources/accounts"
17
- require "octaspace/resources/nodes"
18
- require "octaspace/resources/sessions"
19
- require "octaspace/resources/apps"
20
21
  require "octaspace/resources/network"
21
- require "octaspace/resources/services"
22
- require "octaspace/resources/idle_jobs"
22
+ require "octaspace/resources/stats"
23
+ require "octaspace/resources/compute"
24
+ require "octaspace/resources/render"
25
+ require "octaspace/resources/sessions"
26
+ require "octaspace/resources/hosting"
27
+ require "octaspace/resources/vpn"
23
28
  require "octaspace/client"
24
29
 
25
- # OctaSpace Ruby SDK
26
- #
27
- # Official Ruby client for the OctaSpace API.
28
- # Supports standard and keep-alive (persistent) connection modes,
29
- # automatic URL rotation/failover, retry with exponential backoff,
30
- # and optional Rails integration.
30
+ # The official Ruby library for the OctaSpace API: rent compute machines,
31
+ # render nodes and VPN, manage sessions and the nodes you host, and read
32
+ # platform, GPU market and mining statistics.
31
33
  #
32
34
  # @example Quick start
33
35
  # OctaSpace.configure do |config|
@@ -35,10 +37,10 @@ require "octaspace/client"
35
37
  # end
36
38
  #
37
39
  # client = OctaSpace.client
38
- # client.nodes.list
40
+ # client.compute.list
39
41
  # client.accounts.balance
40
42
  #
41
- # @see https://api.octa.space/api-docs
43
+ # @see https://github.com/octaspace/ruby-sdk#readme Guides
42
44
  module OctaSpace
43
45
  class << self
44
46
  # Global configuration object
@@ -60,7 +62,7 @@ module OctaSpace
60
62
  yield configuration
61
63
  end
62
64
 
63
- # Reset global configuration to defaults (useful in tests)
65
+ # Resets the global configuration to its defaults and drops the shared client.
64
66
  def reset_configuration!
65
67
  @configuration = Configuration.new
66
68
  @shared_client = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octaspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OctaSpace Team
@@ -13,32 +13,25 @@ dependencies:
13
13
  name: faraday
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '2.9'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
18
+ version: 2.14.3
19
+ - - "<"
24
20
  - !ruby/object:Gem::Version
25
- version: '2.9'
26
- - !ruby/object:Gem::Dependency
27
- name: faraday-retry
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '2.2'
21
+ version: '3'
33
22
  type: :runtime
34
23
  prerelease: false
35
24
  version_requirements: !ruby/object:Gem::Requirement
36
25
  requirements:
37
- - - "~>"
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 2.14.3
29
+ - - "<"
38
30
  - !ruby/object:Gem::Version
39
- version: '2.2'
40
- description: Official Ruby client for OctaSpace. Keep-alive connections, URL failover,
41
- retry with backoff, Rails integration.
31
+ version: '3'
32
+ description: Rent compute machines, render nodes and VPN, manage sessions and the
33
+ nodes you host, and read platform, GPU market and mining statistics on OctaSpace
34
+ from Ruby code.
42
35
  email:
43
36
  - dev@octa.space
44
37
  executables: []
@@ -46,41 +39,43 @@ extensions: []
46
39
  extra_rdoc_files: []
47
40
  files:
48
41
  - CHANGELOG.md
49
- - MIT-LICENSE
42
+ - LICENSE
50
43
  - README.md
51
44
  - lib/octaspace.rb
52
45
  - lib/octaspace/client.rb
53
46
  - lib/octaspace/configuration.rb
54
47
  - lib/octaspace/errors.rb
48
+ - lib/octaspace/json_null.rb
55
49
  - lib/octaspace/middleware/url_rotator.rb
56
- - lib/octaspace/payload_helpers.rb
50
+ - lib/octaspace/model.rb
51
+ - lib/octaspace/money.rb
57
52
  - lib/octaspace/railtie.rb
58
53
  - lib/octaspace/resources/accounts.rb
59
- - lib/octaspace/resources/apps.rb
60
54
  - lib/octaspace/resources/base.rb
61
- - lib/octaspace/resources/idle_jobs.rb
55
+ - lib/octaspace/resources/compute.rb
56
+ - lib/octaspace/resources/hosting.rb
62
57
  - lib/octaspace/resources/network.rb
63
- - lib/octaspace/resources/nodes.rb
64
- - lib/octaspace/resources/services.rb
65
- - lib/octaspace/resources/services/machine_rental.rb
66
- - lib/octaspace/resources/services/render.rb
67
- - lib/octaspace/resources/services/session_proxy.rb
68
- - lib/octaspace/resources/services/vpn.rb
58
+ - lib/octaspace/resources/render.rb
69
59
  - lib/octaspace/resources/sessions.rb
60
+ - lib/octaspace/resources/stats.rb
61
+ - lib/octaspace/resources/vpn.rb
70
62
  - lib/octaspace/response.rb
71
63
  - lib/octaspace/transport/base.rb
72
64
  - lib/octaspace/transport/faraday_transport.rb
73
65
  - lib/octaspace/transport/persistent_transport.rb
74
66
  - lib/octaspace/types/account.rb
75
- - lib/octaspace/types/balance.rb
76
- - lib/octaspace/types/node.rb
67
+ - lib/octaspace/types/hosting.rb
68
+ - lib/octaspace/types/machines.rb
69
+ - lib/octaspace/types/network.rb
77
70
  - lib/octaspace/types/session.rb
71
+ - lib/octaspace/types/stats.rb
78
72
  - lib/octaspace/version.rb
79
73
  homepage: https://github.com/octaspace/ruby-sdk
80
74
  licenses:
81
75
  - MIT
82
76
  metadata:
83
- changelog_uri: https://github.com/octaspace/ruby-sdk/blob/main/CHANGELOG.md
77
+ changelog_uri: https://github.com/octaspace/ruby-sdk/blob/v0.3.0/CHANGELOG.md
78
+ documentation_uri: https://rubydoc.info/gems/octaspace/0.3.0
84
79
  source_code_uri: https://github.com/octaspace/ruby-sdk
85
80
  bug_tracker_uri: https://github.com/octaspace/ruby-sdk/issues
86
81
  rubygems_mfa_required: 'true'
@@ -91,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
86
  requirements:
92
87
  - - ">="
93
88
  - !ruby/object:Gem::Version
94
- version: 3.2.0
89
+ version: 3.3.0
95
90
  required_rubygems_version: !ruby/object:Gem::Requirement
96
91
  requirements:
97
92
  - - ">="
@@ -100,5 +95,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
95
  requirements: []
101
96
  rubygems_version: 3.6.9
102
97
  specification_version: 4
103
- summary: Ruby SDK for the OctaSpace API
98
+ summary: Official Ruby library for the OctaSpace API
104
99
  test_files: []
data/MIT-LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2024-present OctaSpace
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included
14
- in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "json"
4
-
5
- module OctaSpace
6
- module PayloadHelpers
7
- module_function
8
-
9
- def parse_port_list(value)
10
- case value
11
- when nil
12
- []
13
- when Array
14
- value
15
- when String
16
- parse_stringified_port_list(value)
17
- else
18
- Array(value)
19
- end
20
- end
21
-
22
- def normalize_marketplace_bandwidth(value)
23
- numeric =
24
- case value
25
- when nil
26
- return nil
27
- when Numeric
28
- value.to_f
29
- when String
30
- Float(value)
31
- else
32
- return value
33
- end
34
-
35
- return numeric unless numeric > 100_000
36
-
37
- numeric / 125_000.0
38
- rescue ArgumentError, TypeError
39
- value
40
- end
41
-
42
- def parse_stringified_port_list(value)
43
- stripped = value.strip
44
- return [] if stripped.empty?
45
-
46
- parsed = JSON.parse(stripped)
47
- parsed.is_a?(Array) ? parsed : []
48
- rescue JSON::ParserError
49
- []
50
- end
51
- private_class_method :parse_stringified_port_list
52
- end
53
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OctaSpace
4
- module Resources
5
- # Apps API endpoint
6
- #
7
- # @example
8
- # client.apps.list
9
- class Apps < Base
10
- # List available apps
11
- # GET /apps
12
- # @param params [Hash] optional filter params
13
- # @return [OctaSpace::Response]
14
- def list(**params)
15
- get("/apps", params:)
16
- end
17
- end
18
- end
19
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OctaSpace
4
- module Resources
5
- # Idle Jobs API endpoints
6
- #
7
- # Each idle job is identified by both a node ID and a job ID.
8
- #
9
- # @example
10
- # client.idle_jobs.find(node_id: 69, job_id: 42)
11
- # client.idle_jobs.logs(node_id: 69, job_id: 42)
12
- class IdleJobs < Base
13
- # Fetch a single idle job status
14
- # GET /idle_jobs/:node_id/:job_id
15
- # @param node_id [Integer, String]
16
- # @param job_id [Integer, String]
17
- # @return [OctaSpace::Response]
18
- def find(node_id:, job_id:)
19
- get("/idle_jobs/#{encode(node_id)}/#{encode(job_id)}")
20
- end
21
-
22
- # Fetch idle job logs
23
- # GET /idle_jobs/:node_id/:job_id/logs
24
- # @param node_id [Integer, String]
25
- # @param job_id [Integer, String]
26
- # @return [OctaSpace::Response]
27
- def logs(node_id:, job_id:)
28
- get("/idle_jobs/#{encode(node_id)}/#{encode(job_id)}/logs")
29
- end
30
- end
31
- end
32
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OctaSpace
4
- module Resources
5
- # Node-related API endpoints
6
- #
7
- # @example
8
- # client.nodes.list
9
- # client.nodes.find(123)
10
- # client.nodes.reboot(123)
11
- # client.nodes.update_prices(123, gpu_hour: 0.5, cpu_hour: 0.1)
12
- class Nodes < Base
13
- # List all nodes
14
- # GET /nodes
15
- # @param params [Hash] optional filter/pagination params
16
- # @return [OctaSpace::Response]
17
- def list(**params)
18
- get("/nodes", params:)
19
- end
20
-
21
- # Fetch a single node by ID
22
- # GET /nodes/:id
23
- # @param id [Integer, String]
24
- # @return [OctaSpace::Response]
25
- def find(id)
26
- get("/nodes/#{encode(id)}")
27
- end
28
-
29
- # Download node identity file (binary response)
30
- # GET /nodes/:id/ident
31
- # @param id [Integer, String]
32
- # @return [OctaSpace::Response]
33
- def download_ident(id)
34
- get("/nodes/#{encode(id)}/ident")
35
- end
36
-
37
- # Download node logs (binary response)
38
- # GET /nodes/:id/logs
39
- # @param id [Integer, String]
40
- # @return [OctaSpace::Response]
41
- def download_logs(id)
42
- get("/nodes/#{encode(id)}/logs")
43
- end
44
-
45
- # Update node pricing
46
- # PATCH /nodes/:id/prices
47
- # @param id [Integer, String]
48
- # @param prices [Hash] e.g. { gpu_hour: 0.5, cpu_hour: 0.1 }
49
- # @return [OctaSpace::Response]
50
- def update_prices(id, **prices)
51
- patch("/nodes/#{encode(id)}/prices", body: prices)
52
- end
53
-
54
- # Reboot a node
55
- # GET /nodes/:id/reboot
56
- # @param id [Integer, String]
57
- # @return [OctaSpace::Response]
58
- def reboot(id)
59
- get("/nodes/#{encode(id)}/reboot")
60
- end
61
- end
62
- end
63
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OctaSpace
4
- module Resources
5
- class Services
6
- # Machine Rental (MR) service endpoints
7
- #
8
- # @example
9
- # client.services.mr.list
10
- # client.services.mr.create(
11
- # node_id: 123,
12
- # disk_size: 10,
13
- # image: "ubuntu:24.04",
14
- # app: "249b4cb3-3db1-4c06-98a4-772ba88cd81c"
15
- # )
16
- class MachineRental < Base
17
- # List available marketplace machines for rent
18
- # GET /services/mr
19
- # @param params [Hash] optional filter params
20
- # @return [OctaSpace::Response]
21
- def list(**params)
22
- get("/services/mr", params:)
23
- end
24
-
25
- # Create (start) a machine rental
26
- # POST /services/mr
27
- # @param attrs [Hash] rental parameters
28
- # @return [OctaSpace::Response]
29
- def create(**attrs)
30
- item = {
31
- id: 0,
32
- node_id: attrs.fetch(:node_id),
33
- disk_size: attrs.fetch(:disk_size),
34
- image: attrs.fetch(:image),
35
- app: attrs[:app].to_s,
36
- envs: attrs[:envs] || {},
37
- ports: attrs[:ports] || [],
38
- http_ports: attrs[:http_ports] || [],
39
- start_command: attrs[:start_command].to_s,
40
- entrypoint: attrs[:entrypoint].to_s
41
- }
42
-
43
- item[:organization_id] = attrs[:organization_id] if attrs.key?(:organization_id)
44
- item[:project_id] = attrs[:project_id] if attrs.key?(:project_id)
45
-
46
- response = post("/services/mr", body: [item])
47
- raise_if_rejected!(response)
48
- response
49
- end
50
-
51
- private
52
-
53
- def raise_if_rejected!(response)
54
- rejections = extract_rejections(response.data)
55
- return if rejections.empty?
56
-
57
- raise OctaSpace::ProvisionRejectedError.new(response: response, rejections: rejections)
58
- end
59
-
60
- def extract_rejections(data)
61
- return [] unless data.is_a?(Array)
62
-
63
- data.filter_map do |item|
64
- next unless item.is_a?(Hash)
65
-
66
- reason = item["reason"] || item[:reason]
67
- status = item["status"] || item[:status]
68
- uuid = item["uuid"] || item[:uuid]
69
- next if uuid
70
- next unless reason || status.to_i.positive?
71
-
72
- item
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OctaSpace
4
- module Resources
5
- class Services
6
- # Render service endpoints
7
- #
8
- # @example
9
- # client.services.render.list
10
- # client.services.render.create(node_id: 123, disk_size: 100)
11
- class Render < Base
12
- # List render jobs
13
- # GET /services/render
14
- # @param params [Hash] optional filter params
15
- # @return [OctaSpace::Response]
16
- def list(**params)
17
- get("/services/render", params:)
18
- end
19
-
20
- # Create (start) a render job
21
- # POST /services/render
22
- # @param attrs [Hash] render job parameters
23
- # @return [OctaSpace::Response]
24
- def create(**attrs)
25
- post("/services/render", body: attrs)
26
- end
27
- end
28
- end
29
- end
30
- end