-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for suspend/resume engines
- Loading branch information
1 parent
f07f73f
commit 3c7249c
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 RelationalAI, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/jessevdk/go-flags" | ||
"github.com/relationalai/rai-sdk-go/rai" | ||
) | ||
|
||
type Options struct { | ||
Engine string `short:"e" long:"engine" required:"true" description:"engine name"` | ||
Profile string `long:"profile" default:"default" description:"config profile"` | ||
} | ||
|
||
func run(opts *Options) error { | ||
client, err := rai.NewClientFromConfig(opts.Profile) | ||
if err != nil { | ||
return err | ||
} | ||
rsp, err := client.GetEngine(opts.Engine) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch rsp.State { | ||
case "PROVISIONED": | ||
err := client.SuspendEngine(opts.Engine) | ||
if err != nil { | ||
return err | ||
} | ||
case "SUSPENDED": | ||
err := client.ResumeEngine(opts.Engine) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
var opts Options | ||
if _, err := flags.ParseArgs(&opts, os.Args); err != nil { | ||
os.Exit(1) | ||
} | ||
if err := run(&opts); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters