kloudlite-sdk 0.5.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 +110 -93
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3cc583a7ea00949b98460f9f2a3eac30312baee4f1c98c29a9f9f7db9008615
4
- data.tar.gz: b728e4a16fcb7100d37feea60d4d742a9637e38488ebb92c9650bd545b5738e4
3
+ metadata.gz: 1444a48a8efbf20d9ce0b50606e6e996bd9e368235bccbd457133e6f6b66d0c0
4
+ data.tar.gz: d8fab2bfc41b7cc8267e1cc42de33fb91b7f634ad80418b2a1edbd6f2ddb75a8
5
5
  SHA512:
6
- metadata.gz: 8f60ad7c782fe168ccee264ae3d8589ad54fb07647a9adb85746ac35bea8ab55ac6f822480fc4900d536128a12ed966e977231f287921dc26e1085d921130a33
7
- data.tar.gz: 1b83d507f815ed688db12e664202a335a019eb3cc5f4da33140190426a15f283a58283188c6101e55fbda3205b0e93d4c0ebbd1102885efe713430fbf5eebe92
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"
@@ -60,7 +60,7 @@ module Kloudlite
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
@@ -77,14 +77,14 @@ module Kloudlite
77
77
  end
78
78
 
79
79
  # The body of a workspace or environment push, shared so the two never drift apart.
80
- def snapshot_body(message, volume, description, labels, branch, ttl_secs, never)
80
+ def snapshot_body(message, volume, description, labels, tag, ttl_secs, never)
81
81
  { message: message, volume: volume, description: description, labels: labels,
82
- branch: branch, ttl_secs: ttl_secs, never: never }.compact
82
+ tag: tag, ttl_secs: ttl_secs, never: never }.compact
83
83
  end
84
84
  end
85
85
 
86
86
  class Client
87
- attr_reader :workspaces, :environments, :desks, :volumes,
87
+ attr_reader :workspaces, :environments, :netgroups, :volumes,
88
88
  :secrets, :connectors, :capsules, :pipelines
89
89
 
90
90
  def initialize(base_url: nil, token: nil, timeout: 30)
@@ -103,7 +103,7 @@ module Kloudlite
103
103
  @timeout = timeout
104
104
  @workspaces = Workspaces.new(self)
105
105
  @environments = Environments.new(self)
106
- @desks = Desks.new(self)
106
+ @netgroups = Netgroups.new(self)
107
107
  @volumes = Volumes.new(self)
108
108
  @secrets = Secrets.new(self)
109
109
  @connectors = Connectors.new(self)
@@ -224,14 +224,13 @@ module Kloudlite
224
224
  # names the volume and is required on its first push; +ttl_secs+ (3600..=31536000) or
225
225
  # never: true set its expiry. +push+ is the old name.
226
226
  # The push is a storage commit of the volume. +description+ and +labels+ describe the volume
227
- # (a given one replaces the stored one). +branch+ creates that branch at the new commit or
228
- # moves it there, and the workspace then has it checked out; without it the checked-out branch
229
- # fast-forwards, and the answer carries +branch+ and, when the branch had moved meanwhile,
230
- # +detached+.
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+.
231
230
  def take_snapshot(workspace:, message: nil, volume: nil, description: nil, labels: nil,
232
- branch: nil, ttl_secs: nil, never: nil)
231
+ tag: nil, ttl_secs: nil, never: nil)
233
232
  at("POST", workspace, "/snapshots",
234
- body: snapshot_body(message, volume, description, labels, branch, ttl_secs, never))
233
+ body: snapshot_body(message, volume, description, labels, tag, ttl_secs, never))
235
234
  end
236
235
  alias_method :push, :take_snapshot
237
236
 
@@ -241,8 +240,8 @@ module Kloudlite
241
240
  at("POST", workspace, "/clone", body: { name: to, task: task })
242
241
  end
243
242
 
244
- # A new workspace +to+ grafted onto a PUSHED +snapshot+ (a volume name — its "base" branch,
245
- # else its newest storage commit — "name@N", "name@<branch>" or a snapshot id) — also one
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
246
245
  # whose workspace is long gone. +team+ (or to: "team/name") is required for a
247
246
  # team's volume. Absent overrides mean "whatever the snapshot froze".
248
247
  def restore(snapshot:, to:, team: nil, image: nil, packages: nil, quota_gb: nil)
@@ -345,10 +344,10 @@ module Kloudlite
345
344
  context: context, ignore_case: ignore_case, max: max)
346
345
  end
347
346
 
348
- # commands and processes — detach: true answers {id}, passed back as +process+
349
- 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)
350
349
  call(tool: "exec", cmd: cmd, cwd: cwd, env: env, timeout_ms: timeout_ms,
351
- head: head, tail: tail, quiet: quiet, detach: detach)
350
+ head: head, tail: tail, quiet: quiet, background: background.nil? ? detach : background)
352
351
  end
353
352
 
354
353
  def process_list
@@ -476,11 +475,11 @@ module Kloudlite
476
475
 
477
476
  # Push a SNAPSHOT of every service's data and the service list, a storage commit (202).
478
477
  # +volume+ names the volume and is required on its first push; +description+, +labels+ and
479
- # +branch+ are as in Workspaces#take_snapshot. +push+ is the old name.
478
+ # +tag+ are as in Workspaces#take_snapshot. +push+ is the old name.
480
479
  def take_snapshot(environment:, message: nil, volume: nil, description: nil, labels: nil,
481
- branch: nil, ttl_secs: nil, never: nil)
480
+ tag: nil, ttl_secs: nil, never: nil)
482
481
  at("POST", environment, "/snapshots",
483
- body: snapshot_body(message, volume, description, labels, branch, ttl_secs, never))
482
+ body: snapshot_body(message, volume, description, labels, tag, ttl_secs, never))
484
483
  end
485
484
  alias_method :push, :take_snapshot
486
485
 
@@ -515,96 +514,118 @@ module Kloudlite
515
514
  end
516
515
  end
517
516
 
518
- # Working desks, over /v1/desks: some of YOUR workspaces in one team, connected to one
519
- # environment. Many people's desks connect to the same environment and collaborate through
520
- # it; an intercept a desk takes is environment-wide, and the desk owns it — only it can
521
- # 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.
522
522
  #
523
- # A desk is named like an environment — "name" (personal) or "team/name" — or by its id
524
- # ("desk-…"); a workspace by its id, name or "team/name", sent verbatim.
525
- 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
526
526
  include Names
527
527
 
528
528
  def initialize(client)
529
529
  @c = client
530
530
  end
531
531
 
532
- # +environment+, when given, must be the desk's team's: an id, a name or "team/name";
533
- # without one the desk connects to nothing until +connect+. +ttl_secs+ (600..=2592000)
534
- # deletes the desk after that long unused.
535
- def create(desk:, environment: nil, ttl_secs: nil)
536
- team, name = owned(desk)
537
- @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)
538
541
  end
539
542
 
540
- # Seconds unused before the desk is deleted (600..=2592000); nil clears it.
541
- def set_ttl(desk:, ttl_secs:)
542
- at("PUT", desk, "/ttl", body: { ttl_secs: ttl_secs })
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 })
546
+ end
547
+
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 })
543
551
  end
544
552
 
545
553
  def list(team: nil)
546
- @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)
547
560
  end
548
561
 
549
- # The desk with its +workspaces+ and the +intercepts+ it holds.
550
- def get(desk:)
551
- at("GET", desk)
562
+ # Releases its intercepts, deletes the workspaces made in it and lets the joined ones go.
563
+ def delete(netgroup:)
564
+ at("DELETE", netgroup)
552
565
  end
553
566
 
554
- # Releases its intercepts and lets its workspaces go — never deletes a workspace.
555
- def delete(desk:)
556
- at("DELETE", 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 })
557
571
  end
558
572
 
559
- # Sets, switches or (nil) clears the desk's environment. Its intercepts in the old
560
- # environment are released first; deleting an environment disconnects its desks the same way.
561
- def connect(desk:, environment:)
562
- at("PUT", desk, "/environment", body: { environment: environment })
573
+ # Stop every workspace in the netgroup (202, {"stopped" => [ids]}).
574
+ def stop(netgroup:)
575
+ at("POST", netgroup, "/stop")
563
576
  end
564
577
 
565
- # Stop the desk and every workspace in it (202, {"stopped" => [ids]}); capsules and the
566
- # environment are untouched.
567
- def stop(desk:)
568
- at("POST", desk, "/stop")
578
+ # Start the netgroup's environment and every workspace in it.
579
+ def start(netgroup:)
580
+ at("POST", netgroup, "/start")
569
581
  end
570
582
 
571
- # Create a workspace +workspace+ (a bare name) managed by the desk, in its team (201). The
572
- # desk controls it from then on; it takes the inputs of Workspaces#create.
573
- def create_workspace(desk:, workspace:, quota_gb:, image: nil, packages: nil, ttl_secs: nil, env: nil)
574
- at("POST", desk, "/workspaces",
575
- body: { name: workspace, quota_gb: quota_gb, image: image, packages: packages,
576
- ttl_secs: ttl_secs, env: env }.compact)
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)
577
589
  end
578
590
 
579
- # Delete a workspace the desk manages, releasing its intercepts first (204); snapshots stay.
580
- def delete_workspace(desk:, workspace:)
581
- at("DELETE", desk, "/workspaces/#{seg(workspace)}")
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 })
582
595
  end
583
596
 
584
- # Create a capsule managed by the desk (202), in its team and reaching its environment.
585
- # Same inputs as Capsules#create (+team+ must be the desk's).
586
- def create_capsule(desk:, cmd:, **options)
587
- Capsule.new(@c, at("POST", desk, "/capsules", body: Capsules.body(cmd: cmd, **options)))
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 })
603
+ end
604
+
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)))
588
609
  end
589
610
 
590
611
  # Send everything that calls +service+ in the environment to +workspace+ (a member), +ports+
591
612
  # mapping each service port to the workspace port that answers it ({ 8080 => 3000 }); an
592
613
  # unmapped port answers on the same number.
593
- def intercept(desk:, service:, workspace:, ports: nil)
594
- at("POST", desk, "/intercepts",
614
+ def intercept(netgroup:, service:, workspace:, ports: nil)
615
+ at("POST", netgroup, "/intercepts",
595
616
  body: { service: service, workspace: workspace,
596
617
  ports: (ports || {}).map { |s, w| { service: Integer(s), workspace: Integer(w) } } })
597
618
  end
598
619
 
599
- def release(desk:, service:)
600
- at("DELETE", desk, "/intercepts/#{seg(service)}")
620
+ def release(netgroup:, service:)
621
+ at("DELETE", netgroup, "/intercepts/#{seg(service)}")
601
622
  end
602
623
 
603
624
  private
604
625
 
605
- def at(method, desk, tail = "", body: nil)
606
- owner, name = owned(desk)
607
- @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 })
608
629
  end
609
630
  end
610
631
 
@@ -663,7 +684,7 @@ module Kloudlite
663
684
  end
664
685
  end
665
686
 
666
- # 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
667
688
  # the deletes — over /v1/volumes.
668
689
  class Volumes
669
690
  include Names
@@ -678,13 +699,9 @@ module Kloudlite
678
699
  @c.request("GET", "/v1/volumes", query: { kind: kind, owner: owner, label: label })
679
700
  end
680
701
 
681
- # The chain of PUSHED snapshots, newest first — each row a restore target.
682
- def history(volume:)
683
- @c.request("GET", "/v1/volumes/#{seg(volume)}/history")
684
- end
685
-
686
- def refs(volume:)
687
- @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)}")
688
705
  end
689
706
 
690
707
  # Refused (409) for a sync point or a running worktree's base; deleting a detached volume's
@@ -699,7 +716,7 @@ module Kloudlite
699
716
  end
700
717
 
701
718
  # One named volume; +owner+ is your handle or a team slug. It carries +description+,
702
- # +labels+ and +branches+ (each branch with the storage commit number it points at).
719
+ # +labels+ and +tags+ (each tag with the number of the snapshot it is on).
703
720
  def get(owner:, name:)
704
721
  @c.request("GET", named(owner, name))
705
722
  end
@@ -711,19 +728,19 @@ module Kloudlite
711
728
  body: { description: description, labels: labels }.compact)
712
729
  end
713
730
 
714
- # Create +branch+ on a storage commit, or move it there (like git branch -f): give +version+
715
- # (the commit number) or +snapshot+ (a snapshot id), not both. Answers the volume.
716
- def set_branch(owner:, name:, branch:, version: nil, snapshot: nil)
717
- @c.request("PUT", named(owner, name, "/branches/#{seg(branch)}"),
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)}"),
718
735
  body: { version: version, snapshot: snapshot }.compact)
719
736
  end
720
737
 
721
- # Remove a branch (204); its storage commit stays.
722
- def delete_branch(owner:, name:, branch:)
723
- @c.request("DELETE", named(owner, name, "/branches/#{seg(branch)}"))
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)}"))
724
741
  end
725
742
 
726
- # The storage commits of a named volume, newest first; each row carries the +branches+ on it.
743
+ # The storage commits of a named volume, newest first; each row carries the +tags+ on it.
727
744
  def versions(owner:, name:)
728
745
  @c.request("GET", named(owner, name, "/versions"))
729
746
  end
@@ -733,8 +750,8 @@ module Kloudlite
733
750
  @c.request("DELETE", named(owner, name))
734
751
  end
735
752
 
736
- # Delete storage commit +n+ (204); deleting the last one deletes the volume. A branch's
737
- # commit is refused (409).
753
+ # Delete storage commit +n+ (204); deleting the last one deletes the volume. A tagged
754
+ # snapshot is refused (409).
738
755
  def delete_version(owner:, name:, n:)
739
756
  @c.request("DELETE", named(owner, name, "/versions/#{Integer(n)}"))
740
757
  end
@@ -758,7 +775,7 @@ module Kloudlite
758
775
  include Names
759
776
 
760
777
  # The POST /v1/capsules body; refuses a missing +cmd+ before anything is sent. Shared with
761
- # Desks#create_capsule — not public surface.
778
+ # Netgroups#create_capsule — not public surface.
762
779
  def self.body(cmd:, image: nil, packages: nil, from_workspace: nil, from_snapshot: nil, team: nil,
763
780
  tty: nil, stdin: nil, timeout_s: nil, network: nil, env: nil, cpu: nil,
764
781
  memory_gb: nil, disk_gb: nil)
@@ -779,8 +796,8 @@ module Kloudlite
779
796
  # is the program then its arguments. +tty+ runs it on a pty; +stdin+ keeps input open for
780
797
  # attach. +timeout_s+ is 10..=86400. +from_workspace+ is an id, "name" or "team/name";
781
798
  # +from_snapshot+ a volume name, "name@N" or snapshot id (exclusive with it). +network+ is
782
- # "internet" or "none"; +cpu+ 1..=8, +memory_gb+ 1..=32. A desk's capsule is made with
783
- # 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.
784
801
  def create(cmd:, **options)
785
802
  Capsule.new(@c, @c.request("POST", "/v1/capsules", body: Capsules.body(cmd: cmd, **options)))
786
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.5.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-16 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: