kloudlite-sdk 0.4.0 → 0.6.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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/kloudlite.rb +139 -85
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4149e80e442f99d0baff31b078c8eac9eaf115b01946d9041efe01f484de1f8
4
- data.tar.gz: b0f43efd307e9e954b5f194c6d6b8658a2b4764db836316921e6f73f64def1a9
3
+ metadata.gz: 1444a48a8efbf20d9ce0b50606e6e996bd9e368235bccbd457133e6f6b66d0c0
4
+ data.tar.gz: d8fab2bfc41b7cc8267e1cc42de33fb91b7f634ad80418b2a1edbd6f2ddb75a8
5
5
  SHA512:
6
- metadata.gz: 95ab59bf40a2169bfb963c7223705881b8b47efef23b6e2de186ecfc8a5cdca86868d5857cdf2cdff5ebaca2576ef4c97a5573cc28859b231cd45a7facbbaebe
7
- data.tar.gz: cba7c45cfbd9827cc30154c28a73d8190b8d92c36549c3029873a1a0778b96a621c9aeabd62bf4f3d91829cad931297aec0da8b77ff52bfd874adf4a488eafa7
6
+ metadata.gz: 8affaaf71c8542ff4ebc9a14841c6f42732e960eb57bd28f576088fade36be14cd4716e510433d0f33323c73b4c12260b7e44eb48f2fba3fa81feacfff3c7820
7
+ data.tar.gz: d27c5d7fa74b7761b52d614e0474019175f277e3dcd7c8fd6ba79bb8b2076a9271e82bb30756ea63d162950397dcb0cc4ab3b9e070070a11d38061d0b20e1e03
data/kloudlite.rb CHANGED
@@ -14,7 +14,7 @@
14
14
  # "no Kloudlite login: pass token=, set KLOUDLITE_TOKEN, or run kloudlite login".
15
15
  #
16
16
  # Every public method takes KEYWORD arguments, so no caller has to remember an order; a
17
- # resource is always the keyword named after it (workspace:, environment:, desk:,
17
+ # resource is always the keyword named after it (workspace:, environment:, netgroup:,
18
18
  # volume:, snapshot:, capsule:, run:), and a new object made from an existing one is to:.
19
19
 
20
20
  raise LoadError, "kloudlite.rb needs Ruby 3.0 or later, found #{RUBY_VERSION}" if RUBY_VERSION < "3.0"
@@ -25,7 +25,7 @@ require "timeout"
25
25
  require "uri"
26
26
 
27
27
  module Kloudlite
28
- VERSION = "0.4.0"
28
+ VERSION = "0.5.0"
29
29
  USER_AGENT = "kloudlite-sdk-ruby/#{VERSION}".freeze
30
30
  NO_LOGIN = "no Kloudlite login: pass token=, set KLOUDLITE_TOKEN, or run kloudlite login"
31
31
 
@@ -56,11 +56,11 @@ module Kloudlite
56
56
  # A client-side wait ran out. A ::Timeout::Error, so a generic rescue still catches it.
57
57
  class TimeoutError < ::Timeout::Error; end
58
58
 
59
- # The naming rules every module shares. Mixed in privately; never part of the public surface.
59
+ # The naming rules (and the push body) every module shares. Mixed in privately; never part of the public surface.
60
60
  module Names
61
61
  private
62
62
 
63
- # "name" → [nil, name]; "team/name" → [team, name]. Workspaces, environments and desks
63
+ # "name" → [nil, name]; "team/name" → [team, name]. Workspaces, environments and netgroups
64
64
  # send the pair as path segment +name+ plus ?owner=team, which the server folds back.
65
65
  def owned(s)
66
66
  s = s.to_s
@@ -75,10 +75,16 @@ module Kloudlite
75
75
  def seg(s)
76
76
  URI.encode_www_form_component(s.to_s).gsub("+", "%20")
77
77
  end
78
+
79
+ # The body of a workspace or environment push, shared so the two never drift apart.
80
+ def snapshot_body(message, volume, description, labels, tag, ttl_secs, never)
81
+ { message: message, volume: volume, description: description, labels: labels,
82
+ tag: tag, ttl_secs: ttl_secs, never: never }.compact
83
+ end
78
84
  end
79
85
 
80
86
  class Client
81
- attr_reader :workspaces, :environments, :desks, :volumes,
87
+ attr_reader :workspaces, :environments, :netgroups, :volumes,
82
88
  :secrets, :connectors, :capsules, :pipelines
83
89
 
84
90
  def initialize(base_url: nil, token: nil, timeout: 30)
@@ -97,7 +103,7 @@ module Kloudlite
97
103
  @timeout = timeout
98
104
  @workspaces = Workspaces.new(self)
99
105
  @environments = Environments.new(self)
100
- @desks = Desks.new(self)
106
+ @netgroups = Netgroups.new(self)
101
107
  @volumes = Volumes.new(self)
102
108
  @secrets = Secrets.new(self)
103
109
  @connectors = Connectors.new(self)
@@ -217,9 +223,14 @@ module Kloudlite
217
223
  # Push a SNAPSHOT of the working copy — the one durable, restorable state (202). +volume+
218
224
  # names the volume and is required on its first push; +ttl_secs+ (3600..=31536000) or
219
225
  # never: true set its expiry. +push+ is the old name.
220
- def take_snapshot(workspace:, message: nil, volume: nil, ttl_secs: nil, never: nil)
226
+ # The push is a storage commit of the volume. +description+ and +labels+ describe the volume
227
+ # (a given one replaces the stored one). +tag+ puts that tag on the new snapshot, moving it
228
+ # from wherever it was; without it the snapshot is untagged (a volume's first is tagged
229
+ # "base"). The answer carries +tag+.
230
+ def take_snapshot(workspace:, message: nil, volume: nil, description: nil, labels: nil,
231
+ tag: nil, ttl_secs: nil, never: nil)
221
232
  at("POST", workspace, "/snapshots",
222
- body: { message: message, volume: volume, ttl_secs: ttl_secs, never: never }.compact)
233
+ body: snapshot_body(message, volume, description, labels, tag, ttl_secs, never))
223
234
  end
224
235
  alias_method :push, :take_snapshot
225
236
 
@@ -229,8 +240,9 @@ module Kloudlite
229
240
  at("POST", workspace, "/clone", body: { name: to, task: task })
230
241
  end
231
242
 
232
- # A new workspace +to+ grafted onto a PUSHED +snapshot+ (a volume name, "name@N" or a snapshot
233
- # id) — also one whose workspace is long gone. +team+ (or to: "team/name") is required for a
243
+ # A new workspace +to+ grafted onto a PUSHED +snapshot+ (a volume name — its snapshot tagged
244
+ # "base", else its newest — "name@N", "name@<tag>" or a snapshot id) — also one
245
+ # whose workspace is long gone. +team+ (or to: "team/name") is required for a
234
246
  # team's volume. Absent overrides mean "whatever the snapshot froze".
235
247
  def restore(snapshot:, to:, team: nil, image: nil, packages: nil, quota_gb: nil)
236
248
  owner, name = owned(to)
@@ -332,10 +344,10 @@ module Kloudlite
332
344
  context: context, ignore_case: ignore_case, max: max)
333
345
  end
334
346
 
335
- # commands and processes — detach: true answers {id}, passed back as +process+
336
- def exec(cmd:, cwd: nil, env: nil, timeout_ms: nil, head: nil, tail: nil, quiet: nil, detach: nil)
347
+ # commands and processes — background: true (formerly detach:, still read) answers {id}, passed back as +process+
348
+ def exec(cmd:, cwd: nil, env: nil, timeout_ms: nil, head: nil, tail: nil, quiet: nil, background: nil, detach: nil)
337
349
  call(tool: "exec", cmd: cmd, cwd: cwd, env: env, timeout_ms: timeout_ms,
338
- head: head, tail: tail, quiet: quiet, detach: detach)
350
+ head: head, tail: tail, quiet: quiet, background: background.nil? ? detach : background)
339
351
  end
340
352
 
341
353
  def process_list
@@ -461,11 +473,13 @@ module Kloudlite
461
473
  at("DELETE", environment)
462
474
  end
463
475
 
464
- # Push a SNAPSHOT of every service's data and the service list (202). +volume+ names the
465
- # volume and is required on its first push. +push+ is the old name.
466
- def take_snapshot(environment:, message: nil, volume: nil, ttl_secs: nil, never: nil)
476
+ # Push a SNAPSHOT of every service's data and the service list, a storage commit (202).
477
+ # +volume+ names the volume and is required on its first push; +description+, +labels+ and
478
+ # +tag+ are as in Workspaces#take_snapshot. +push+ is the old name.
479
+ def take_snapshot(environment:, message: nil, volume: nil, description: nil, labels: nil,
480
+ tag: nil, ttl_secs: nil, never: nil)
467
481
  at("POST", environment, "/snapshots",
468
- body: { message: message, volume: volume, ttl_secs: ttl_secs, never: never }.compact)
482
+ body: snapshot_body(message, volume, description, labels, tag, ttl_secs, never))
469
483
  end
470
484
  alias_method :push, :take_snapshot
471
485
 
@@ -500,96 +514,118 @@ module Kloudlite
500
514
  end
501
515
  end
502
516
 
503
- # Working desks, over /v1/desks: some of YOUR workspaces in one team, connected to one
504
- # environment. Many people's desks connect to the same environment and collaborate through
505
- # it; an intercept a desk takes is environment-wide, and the desk owns it — only it can
506
- # release it, and removing the workspace or deleting the desk releases it.
517
+ # Netgroups, over /v1/netgroups: some of YOUR workspaces in one team, joined to one
518
+ # environment, with one idle clock. Many people's netgroups connect to the same environment
519
+ # and collaborate through it; an intercept a netgroup takes is environment-wide, and the
520
+ # netgroup owns it — only it can release it, and a member leaving or the netgroup ending
521
+ # releases it.
507
522
  #
508
- # A desk is named like an environment — "name" (personal) or "team/name" — or by its id
509
- # ("desk-…"); a workspace by its id, name or "team/name", sent verbatim.
510
- class Desks
523
+ # A netgroup is named like an environment — "name" (personal) or "team/name" — or by its id;
524
+ # a workspace by its id, name or "team/name", sent verbatim.
525
+ class Netgroups
511
526
  include Names
512
527
 
513
528
  def initialize(client)
514
529
  @c = client
515
530
  end
516
531
 
517
- # +environment+, when given, must be the desk's team's: an id, a name or "team/name";
518
- # without one the desk connects to nothing until +connect+. +ttl_secs+ (600..=2592000)
519
- # deletes the desk after that long unused.
520
- def create(desk:, environment: nil, ttl_secs: nil)
521
- team, name = owned(desk)
522
- @c.request("POST", "/v1/desks", body: { name: name, team: team, environment: environment, ttl_secs: ttl_secs })
532
+ # +environment+, when given, must be the netgroup's team's: an id, a name or "team/name";
533
+ # without one it connects to nothing until +connect+. +ttl_secs+ (600..=2592000) deletes it
534
+ # after that long unused; +idle_secs+ (60..=1800) idle-stops its members after that long
535
+ # unused, in place of the region's window.
536
+ def create(netgroup:, environment: nil, ttl_secs: nil, idle_secs: nil)
537
+ team, name = owned(netgroup)
538
+ @c.request("POST", "/v1/netgroups",
539
+ body: { name: name, team: team, environment: environment, ttl_secs: ttl_secs,
540
+ idle_secs: idle_secs }.compact)
541
+ end
542
+
543
+ # Seconds unused before its members idle-stop (60..=1800); nil follows the region's window again.
544
+ def set_idle(netgroup:, secs:)
545
+ at("PUT", netgroup, "/idle", body: { idle_secs: secs })
523
546
  end
524
547
 
525
- # Seconds unused before the desk is deleted (600..=2592000); nil clears it.
526
- def set_ttl(desk:, ttl_secs:)
527
- at("PUT", desk, "/ttl", body: { ttl_secs: ttl_secs })
548
+ # Seconds unused before the netgroup is deleted (600..=2592000); nil clears it.
549
+ def set_ttl(netgroup:, ttl_secs:)
550
+ at("PUT", netgroup, "/ttl", body: { ttl_secs: ttl_secs })
528
551
  end
529
552
 
530
553
  def list(team: nil)
531
- @c.request("GET", "/v1/desks", query: { team: team })
554
+ @c.request("GET", "/v1/netgroups", query: { team: team })
555
+ end
556
+
557
+ # The netgroup with its +workspaces+ and the +intercepts+ it holds.
558
+ def get(netgroup:)
559
+ at("GET", netgroup)
560
+ end
561
+
562
+ # Releases its intercepts, deletes the workspaces made in it and lets the joined ones go.
563
+ def delete(netgroup:)
564
+ at("DELETE", netgroup)
532
565
  end
533
566
 
534
- # The desk with its +workspaces+ and the +intercepts+ it holds.
535
- def get(desk:)
536
- at("GET", desk)
567
+ # Sets, switches or (nil) clears the netgroup's environment. Its intercepts in the old
568
+ # environment are released first.
569
+ def connect(netgroup:, environment:)
570
+ at("PUT", netgroup, "/environment", body: { environment: environment })
537
571
  end
538
572
 
539
- # Releases its intercepts and lets its workspaces go — never deletes a workspace.
540
- def delete(desk:)
541
- at("DELETE", desk)
573
+ # Stop every workspace in the netgroup (202, {"stopped" => [ids]}).
574
+ def stop(netgroup:)
575
+ at("POST", netgroup, "/stop")
542
576
  end
543
577
 
544
- # Sets, switches or (nil) clears the desk's environment. Its intercepts in the old
545
- # environment are released first; deleting an environment disconnects its desks the same way.
546
- def connect(desk:, environment:)
547
- at("PUT", desk, "/environment", body: { environment: environment })
578
+ # Start the netgroup's environment and every workspace in it.
579
+ def start(netgroup:)
580
+ at("POST", netgroup, "/start")
548
581
  end
549
582
 
550
- # Stop the desk and every workspace in it (202, {"stopped" => [ids]}); capsules and the
551
- # environment are untouched.
552
- def stop(desk:)
553
- at("POST", desk, "/stop")
583
+ # Create a workspace +workspace+ (a bare name) in the netgroup, in its team (201); it is
584
+ # deleted with the netgroup. +cpu+ (1..=8) and +memory_gb+ (1..=32) size it.
585
+ def create_workspace(netgroup:, workspace:, image: nil, packages: nil, ttl_secs: nil, env: nil, cpu: nil, memory_gb: nil)
586
+ at("POST", netgroup, "/workspaces",
587
+ body: { name: workspace, image: image, packages: packages, ttl_secs: ttl_secs, env: env,
588
+ cpu: cpu, memory_gb: memory_gb }.compact)
554
589
  end
555
590
 
556
- # Create a workspace +workspace+ (a bare name) managed by the desk, in its team (201). The
557
- # desk controls it from then on; it takes the inputs of Workspaces#create.
558
- def create_workspace(desk:, workspace:, quota_gb:, image: nil, packages: nil, ttl_secs: nil, env: nil)
559
- at("POST", desk, "/workspaces",
560
- body: { name: workspace, quota_gb: quota_gb, image: image, packages: packages,
561
- ttl_secs: ttl_secs, env: env }.compact)
591
+ # A standalone workspace of yours (a device one too) joins: it follows the netgroup's idle
592
+ # clock and reaches its environment.
593
+ def join(netgroup:, workspace:)
594
+ at("POST", netgroup, "/workspaces", body: { workspace: workspace })
562
595
  end
563
596
 
564
- # Delete a workspace the desk manages, releasing its intercepts first (204); snapshots stay.
565
- def delete_workspace(desk:, workspace:)
566
- at("DELETE", desk, "/workspaces/#{seg(workspace)}")
597
+ # The workspace leaves and is standalone again, its intercepts released; +delete+ deletes it
598
+ # instead (a capsule, or a workspace made in the netgroup).
599
+ def leave(netgroup:, workspace:, delete: false)
600
+ owner, name = owned(netgroup)
601
+ @c.request("DELETE", "/v1/netgroups/#{seg(name)}/workspaces/#{seg(workspace)}",
602
+ query: { owner: owner, delete: delete ? "true" : nil })
567
603
  end
568
604
 
569
- # Create a capsule managed by the desk (202), in its team and reaching its environment.
570
- # Same inputs as Capsules#create (+team+ must be the desk's).
571
- def create_capsule(desk:, cmd:, **options)
572
- Capsule.new(@c, at("POST", desk, "/capsules", body: Capsules.body(cmd: cmd, **options)))
605
+ # Create a capsule in the netgroup (202), in its team and reaching its environment.
606
+ # Same inputs as Capsules#create (+team+ must be the netgroup's).
607
+ def create_capsule(netgroup:, cmd:, **options)
608
+ Capsule.new(@c, at("POST", netgroup, "/capsules", body: Capsules.body(cmd: cmd, **options)))
573
609
  end
574
610
 
575
611
  # Send everything that calls +service+ in the environment to +workspace+ (a member), +ports+
576
612
  # mapping each service port to the workspace port that answers it ({ 8080 => 3000 }); an
577
613
  # unmapped port answers on the same number.
578
- def intercept(desk:, service:, workspace:, ports: nil)
579
- at("POST", desk, "/intercepts",
614
+ def intercept(netgroup:, service:, workspace:, ports: nil)
615
+ at("POST", netgroup, "/intercepts",
580
616
  body: { service: service, workspace: workspace,
581
617
  ports: (ports || {}).map { |s, w| { service: Integer(s), workspace: Integer(w) } } })
582
618
  end
583
619
 
584
- def release(desk:, service:)
585
- at("DELETE", desk, "/intercepts/#{seg(service)}")
620
+ def release(netgroup:, service:)
621
+ at("DELETE", netgroup, "/intercepts/#{seg(service)}")
586
622
  end
587
623
 
588
624
  private
589
625
 
590
- def at(method, desk, tail = "", body: nil)
591
- owner, name = owned(desk)
592
- @c.request(method, "/v1/desks/#{seg(name)}#{tail}", body: body, query: { owner: owner })
626
+ def at(method, netgroup, tail = "", body: nil)
627
+ owner, name = owned(netgroup)
628
+ @c.request(method, "/v1/netgroups/#{seg(name)}#{tail}", body: body, query: { owner: owner })
593
629
  end
594
630
  end
595
631
 
@@ -648,7 +684,7 @@ module Kloudlite
648
684
  end
649
685
  end
650
686
 
651
- # The btrfs volumes behind workspaces and environments: snapshot history, restore targets, and
687
+ # The btrfs volumes behind workspaces and environments: their snapshots, restore targets, and
652
688
  # the deletes — over /v1/volumes.
653
689
  class Volumes
654
690
  include Names
@@ -657,18 +693,15 @@ module Kloudlite
657
693
  @c = client
658
694
  end
659
695
 
660
- # +kind+ is "workspace" or "environment"; +owner+ a handle or team slug.
661
- def list(kind: nil, owner: nil)
662
- @c.request("GET", "/v1/volumes", query: { kind: kind, owner: owner })
696
+ # +kind+ is "workspace" or "environment"; +owner+ a handle or team slug; +label+ keeps the
697
+ # volumes that carry it.
698
+ def list(kind: nil, owner: nil, label: nil)
699
+ @c.request("GET", "/v1/volumes", query: { kind: kind, owner: owner, label: label })
663
700
  end
664
701
 
665
- # The chain of PUSHED snapshots, newest first — each row a restore target.
666
- def history(volume:)
667
- @c.request("GET", "/v1/volumes/#{seg(volume)}/history")
668
- end
669
-
670
- def refs(volume:)
671
- @c.request("GET", "/v1/volumes/#{seg(volume)}/refs")
702
+ # A volume by its id, named or not: its disks and its snapshots, newest first.
703
+ def get_by_id(volume:)
704
+ @c.request("GET", "/v1/volumes/#{seg(volume)}")
672
705
  end
673
706
 
674
707
  # Refused (409) for a sync point or a running worktree's base; deleting a detached volume's
@@ -682,12 +715,32 @@ module Kloudlite
682
715
  @c.request("DELETE", "/v1/volumes/#{seg(volume)}")
683
716
  end
684
717
 
685
- # One named volume; +owner+ is your handle or a team slug.
718
+ # One named volume; +owner+ is your handle or a team slug. It carries +description+,
719
+ # +labels+ and +tags+ (each tag with the number of the snapshot it is on).
686
720
  def get(owner:, name:)
687
721
  @c.request("GET", named(owner, name))
688
722
  end
689
723
 
690
- # The versions of a named volume, newest first.
724
+ # Set or clear the description and the labels; nil leaves a field as it is, "" removes the
725
+ # description and [] the labels. Answers the volume.
726
+ def describe(owner:, name:, description: nil, labels: nil)
727
+ @c.request("PATCH", named(owner, name),
728
+ body: { description: description, labels: labels }.compact)
729
+ end
730
+
731
+ # Put +tag+ on a snapshot, or move it there: give +version+ (the snapshot number) or
732
+ # +snapshot+ (a snapshot id), not both. Answers the volume.
733
+ def set_tag(owner:, name:, tag:, version: nil, snapshot: nil)
734
+ @c.request("PUT", named(owner, name, "/tags/#{seg(tag)}"),
735
+ body: { version: version, snapshot: snapshot }.compact)
736
+ end
737
+
738
+ # Remove a tag (204); its snapshot stays.
739
+ def delete_tag(owner:, name:, tag:)
740
+ @c.request("DELETE", named(owner, name, "/tags/#{seg(tag)}"))
741
+ end
742
+
743
+ # The storage commits of a named volume, newest first; each row carries the +tags+ on it.
691
744
  def versions(owner:, name:)
692
745
  @c.request("GET", named(owner, name, "/versions"))
693
746
  end
@@ -697,7 +750,8 @@ module Kloudlite
697
750
  @c.request("DELETE", named(owner, name))
698
751
  end
699
752
 
700
- # Delete version +n+ (204); deleting the last one deletes the volume.
753
+ # Delete storage commit +n+ (204); deleting the last one deletes the volume. A tagged
754
+ # snapshot is refused (409).
701
755
  def delete_version(owner:, name:, n:)
702
756
  @c.request("DELETE", named(owner, name, "/versions/#{Integer(n)}"))
703
757
  end
@@ -721,7 +775,7 @@ module Kloudlite
721
775
  include Names
722
776
 
723
777
  # The POST /v1/capsules body; refuses a missing +cmd+ before anything is sent. Shared with
724
- # Desks#create_capsule — not public surface.
778
+ # Netgroups#create_capsule — not public surface.
725
779
  def self.body(cmd:, image: nil, packages: nil, from_workspace: nil, from_snapshot: nil, team: nil,
726
780
  tty: nil, stdin: nil, timeout_s: nil, network: nil, env: nil, cpu: nil,
727
781
  memory_gb: nil, disk_gb: nil)
@@ -742,8 +796,8 @@ module Kloudlite
742
796
  # is the program then its arguments. +tty+ runs it on a pty; +stdin+ keeps input open for
743
797
  # attach. +timeout_s+ is 10..=86400. +from_workspace+ is an id, "name" or "team/name";
744
798
  # +from_snapshot+ a volume name, "name@N" or snapshot id (exclusive with it). +network+ is
745
- # "internet" or "none"; +cpu+ 1..=8, +memory_gb+ 1..=32. A desk's capsule is made with
746
- # Desks#create_capsule. Unset keywords are omitted, so the server's defaults apply.
799
+ # "internet" or "none"; +cpu+ 1..=8, +memory_gb+ 1..=32. A netgroup's capsule is made with
800
+ # Netgroups#create_capsule. Unset keywords are omitted, so the server's defaults apply.
747
801
  def create(cmd:, **options)
748
802
  Capsule.new(@c, @c.request("POST", "/v1/capsules", body: Capsules.body(cmd: cmd, **options)))
749
803
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kloudlite-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kloudlite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-09 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: