Skip to content

Commit

Permalink
add suspend and resume
Browse files Browse the repository at this point in the history
  • Loading branch information
will committed May 19, 2022
1 parent f3340a7 commit cafea1e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
<<<<<<< HEAD
- `cb backup list` shows current backups for a cluster.
=======
- `cb suspend` and `resume` to temporarily stop running a cluster.
>>>>>>> cafe0ec (add suspend and resume)
## [2.0.0] - 2022-05-17
### Added
Expand Down
2 changes: 1 addition & 1 deletion spec/cb/completion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe CB::Completion do
result.any?(&.starts_with?("login")).should be_true
end

%w[info rename destroy logs].each do |cmd|
%w[info rename destroy logs suspend resume].each do |cmd|
it "#{cmd} is included in top level suggestions" do
result = parse("cb ")
result.any?(&.starts_with?(cmd)).should be_true
Expand Down
2 changes: 1 addition & 1 deletion src/cb/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class CB::Client
exec "POST", path, body
end

def put(path, body)
def put(path, body = nil)
exec "PUT", path, body
end

Expand Down
23 changes: 23 additions & 0 deletions src/cb/cluster_suspend_resume.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "./action"

module CB
class ClusterSuspend < Action
eid_setter cluster_id

def run
client.put "clusters/#{cluster_id}/actions/suspend"
c = client.get_cluster cluster_id
output << "suspended cluster " << c.name.colorize.t_name << "\n"
end
end

class ClusterResume < Action
eid_setter cluster_id

def run
client.put "clusters/#{cluster_id}/actions/resume"
c = client.get_cluster cluster_id
output << "resumed cluster " << c.name.colorize.t_name << "\n"
end
end
end
4 changes: 3 additions & 1 deletion src/cb/completion.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CB::Completion
top_level
else
case args.first
when "info", "destroy", "rename", "logs"
when "info", "destroy", "rename", "logs", "suspend", "resume"
single_cluster_suggestion
when "create"
create
Expand Down Expand Up @@ -105,6 +105,8 @@ class CB::Completion
"logdest\tManage log destinations",
"scope\tRun diagnostic queries",
"logs\tView live cluster logs",
"suspend\tTemporarily turn off a cluster",
"resume\tTurn on a suspended cluster",
]
if @client
options
Expand Down
12 changes: 12 additions & 0 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ op = OptionParser.new do |parser|
end
end

parser.on("suspend", "Temporarily turn off a cluster") do
parser.banner = "cb suspend <cluster id>"
suspend = set_action ClusterSuspend
parser.unknown_args { |args| suspend.cluster_id = get_id_arg.call(args) }
end

parser.on("resume", "Turn on a previously suspended cluster") do
parser.banner = "cb resume <cluster id>"
resume = set_action ClusterResume
parser.unknown_args { |args| resume.cluster_id = get_id_arg.call(args) }
end

parser.on("teamcert", "Show public TLS cert for a team") do
parser.banner = "cb teamcert <team id>"
teamcert = set_action TeamCert
Expand Down

0 comments on commit cafea1e

Please sign in to comment.