本文整理汇总了Golang中github.com/litl/galaxy/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: stackTemplate
// Print a Cloudformation template to stdout.
func stackTemplate(c *cli.Context) {
stackName := c.Args().First()
if c.String("region") != "" {
stack.Region = c.String("region")
}
if stackName == "" {
os.Stdout.Write(stack.DefaultGalaxyTemplate())
return
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
stackTmpl, err := stack.GetTemplate(stackName)
if err != nil {
if err, ok := err.(*aws.Error); ok {
if err.Code == "ValidationError" && strings.Contains(err.Message, "does not exist") {
log.Fatalf("ERROR: Stack '%s' does not exist", stackName)
}
}
log.Fatal(err)
}
if _, err := os.Stdout.Write(stackTmpl); err != nil {
log.Fatal(err)
}
}
开发者ID:zombor,项目名称:galaxy,代码行数:30,代码来源:stacks.go
示例2: waitAndDelete
// wait until a stack is in a final state, then delete it
func waitAndDelete(name string) {
log.Println("Attempting to delete stack:", name)
// we need to get the StackID in order to lookup DELETE events
desc, err := stack.DescribeStacks(name)
if err != nil {
log.Fatalf("ERROR: %s", err)
} else if len(desc.Stacks) == 0 {
log.Fatal("ERROR: could not describe stack:", name)
}
stackId := desc.Stacks[0].Id
err = stack.WaitForComplete(stackId, 5*time.Minute)
if err != nil {
log.Fatal(err)
}
_, err = stack.Delete(name)
if err != nil {
log.Fatal(err)
}
// wait
err = stack.WaitForComplete(stackId, 5*time.Minute)
if err != nil {
log.Fatal(err)
}
log.Println("Deleted stack:", name)
}
开发者ID:zombor,项目名称:galaxy,代码行数:30,代码来源:stacks.go
示例3: appBackup
// Backup app config to a file or STDOUT
func appBackup(c *cli.Context) {
initStore(c)
env := utils.GalaxyEnv(c)
if env == "" {
log.Fatal("ERROR: env is required. Pass --env or set GALAXY_ENV")
}
backup := &backupData{
Time: time.Now(),
}
toBackup := c.Args()
if len(toBackup) == 0 {
appList, err := configStore.ListApps(env)
if err != nil {
log.Fatalf("ERROR: %s\n", err)
}
for _, app := range appList {
toBackup = append(toBackup, app.Name())
}
}
errCount := 0
for _, app := range toBackup {
data, err := getAppBackup(app, env)
if err != nil {
// log errors and continue
log.Errorf("ERROR: %s [%s]", err, app)
errCount++
continue
}
backup.Apps = append(backup.Apps, data)
}
if errCount > 0 {
fmt.Printf("WARNING: backup completed with %d errors\n", errCount)
defer os.Exit(errCount)
}
j, err := json.MarshalIndent(backup, "", " ")
if err != nil {
log.Fatal(err)
}
fileName := c.String("file")
if fileName != "" {
if err := ioutil.WriteFile(fileName, j, 0666); err != nil {
log.Fatal(err)
}
return
}
os.Stdout.Write(j)
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:58,代码来源:backup.go
示例4: cfgDir
// Return the path for the config directory, and create it if it doesn't exist
func cfgDir() string {
homeDir := utils.HomeDir()
if homeDir == "" {
log.Fatal("ERROR: Unable to determine current home dir. Set $HOME.")
}
configDir := filepath.Join(homeDir, ".galaxy")
_, err := os.Stat(configDir)
if err != nil && os.IsNotExist(err) {
err = os.Mkdir(configDir, 0700)
if err != nil {
log.Fatal("ERROR: cannot create config directory:", err)
}
}
return configDir
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:17,代码来源:galaxy.go
示例5: DefaultGalaxyTemplate
// Return a default template to create our base stack.
func DefaultGalaxyTemplate() []byte {
azResp, err := DescribeAvailabilityZones("")
if err != nil {
log.Warn(err)
return nil
}
p := &GalaxyTmplParams{
Name: "galaxy",
VPCCIDR: "10.24.0.1/16",
}
for i, az := range azResp.AvailabilityZones {
s := &SubnetTmplParams{
Name: fmt.Sprintf("galaxySubnet%d", i+1),
Subnet: fmt.Sprintf("10.24.%d.0/24", i+1),
AZ: az.Name,
}
p.Subnets = append(p.Subnets, s)
}
tmpl, err := GalaxyTemplate(p)
if err != nil {
// TODO
log.Fatal(err)
}
return tmpl
}
开发者ID:zombor,项目名称:galaxy,代码行数:30,代码来源:cloudformation.go
示例6: pgPsql
func pgPsql(c *cli.Context) {
ensureEnvArg(c)
initStore(c)
app := ensureAppParam(c, "pg:psql")
appCfg, err := configStore.GetApp(app, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: Unable to run command: %s.", err)
return
}
database_url := appCfg.Env()["DATABASE_URL"]
if database_url == "" {
log.Printf("No DATABASE_URL configured. Set one with config:set first.")
return
}
if !strings.HasPrefix(database_url, "postgres://") {
log.Printf("DATABASE_URL is not a postgres database.")
return
}
cmd := exec.Command("psql", database_url)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// Ignore SIGINT while the process is running
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
defer func() {
signal.Stop(ch)
close(ch)
}()
go func() {
for {
_, ok := <-ch
if !ok {
break
}
}
}()
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v\n", err)
}
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:56,代码来源:galaxy.go
示例7: getBase
// return --base, or try to find a base cloudformation stack
func getBase(c *cli.Context) string {
errNoBase := fmt.Errorf("could not identify a unique base stack")
base := c.String("base")
if base != "" {
return base
}
descResp, err := stack.DescribeStacks("")
if err != nil {
log.Fatal(err)
}
for _, stack := range descResp.Stacks {
// first check for galaxy:base tag
baseTag := false
for _, t := range stack.Tags {
if t.Key == "galaxy" && t.Value == "base" {
baseTag = true
}
}
if baseTag {
if base != "" {
err = errNoBase
}
base = stack.Name
continue
}
parts := strings.Split(stack.Name, "-")
// check for "-base" in the name
if parts[len(parts)-1] == "base" {
if base != "" {
err = errNoBase
}
base = stack.Name
continue
}
// the best we can do for now is look for a stack with a single word
if len(parts) == 1 {
if base != "" {
err = errNoBase
}
base = stack.Name
log.Printf("Warning: guessing base stack: %s", base)
}
}
if err != nil {
log.Fatalf("%s: %s", err, "use --base")
}
return base
}
开发者ID:zombor,项目名称:galaxy,代码行数:57,代码来源:stacks.go
示例8: stackInit
// create our base stack
func stackInit(c *cli.Context) {
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
exists, err := stack.Exists(stackName)
if exists {
log.Fatalf("ERROR: stack %s already exists", stackName)
} else if err != nil {
fmt.Println("EXISTS ERROR")
log.Fatal(err)
}
params := getInitOpts(c)
stackTmpl, err := stack.GalaxyTemplate(params)
if err != nil {
log.Fatalf("ERROR: %s", err)
}
if c.Bool("print") {
fmt.Println(string(stackTmpl))
return
}
opts := make(map[string]string)
opts["tag.galaxy"] = "base"
_, err = stack.Create(stackName, stackTmpl, opts)
if err != nil {
log.Fatalf("ERROR: %s", err)
}
log.Println("Initializing stack", stackName)
}
开发者ID:zombor,项目名称:galaxy,代码行数:39,代码来源:stacks.go
示例9: stackListEvents
// List recent events for a stack
// Shows up to 20 events, or 24 hours of events.
func stackListEvents(c *cli.Context) {
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
resp, err := stack.DescribeStackEvents(stackName)
if err != nil {
log.Fatal(err)
}
if len(resp.Events) == 0 {
log.Println("no events for", stackName)
return
}
firstTS := resp.Events[0].Timestamp.Add(-24 * time.Hour)
lines := []string{"TIMESTAMP | Logical ID | STATUS | REASON"}
format := "%s | %s | %s | %s"
for i, e := range resp.Events {
if i > 20 || e.Timestamp.Before(firstTS) {
break
}
displayTime := e.Timestamp.Format(time.Stamp)
line := fmt.Sprintf(format, displayTime, e.LogicalResourceId, e.ResourceStatus, e.ResourceStatusReason)
lines = append(lines, line)
}
output, _ := columnize.SimpleFormat(lines)
log.Println(output)
}
开发者ID:zombor,项目名称:galaxy,代码行数:40,代码来源:stacks.go
示例10: stackDelete
// delete a pool
func stackDelete(c *cli.Context) {
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
ok := c.Bool("y")
if !ok {
switch strings.ToLower(promptValue(fmt.Sprintf("\nDelete Stack '%s'?", stackName), "n")) {
case "y", "yes":
ok = true
}
}
if !ok {
log.Fatal("aborted")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
waitAndDelete(stackName)
}
开发者ID:zombor,项目名称:galaxy,代码行数:24,代码来源:stacks.go
示例11: appCreate
func appCreate(c *cli.Context) {
ensureEnvArg(c)
initStore(c)
app := c.Args().First()
if app == "" {
cli.ShowCommandHelp(c, "app:create")
log.Fatal("ERROR: app name missing")
}
err := commander.AppCreate(configStore, app, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:15,代码来源:galaxy.go
示例12: poolUnassign
func poolUnassign(c *cli.Context) {
ensureEnvArg(c)
ensurePoolArg(c)
initStore(c)
app := c.Args().First()
if app == "" {
cli.ShowCommandHelp(c, "pool:assign")
log.Fatal("ERROR: app name missing")
}
err := commander.AppUnassign(configStore, app, utils.GalaxyEnv(c), utils.GalaxyPool(c))
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:16,代码来源:galaxy.go
示例13: ensureAppParam
func ensureAppParam(c *cli.Context, command string) string {
app := c.Args().First()
if app == "" {
cli.ShowCommandHelp(c, command)
log.Fatal("ERROR: app name missing")
}
exists, err := appExists(app, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: can't deteremine if %s exists: %s", app, err)
}
if !exists {
log.Fatalf("ERROR: %s does not exist. Create it first.", app)
}
return app
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:18,代码来源:galaxy.go
示例14: setCPUAutoScale
// seto autoscaling options for a pool
func setCPUAutoScale(c *cli.Context, pool *stack.Pool) {
scaleAdj := c.Int("scale-adj")
scaleUpDel := c.Int("scale-up-delay")
scaleDownDel := c.Int("scale-down-delay")
scaleUpCPU := c.Int("scale-up-cpu")
scaleDownCPU := c.Int("scale-down-cpu")
asgName := pool.ASG().Name
if asgName == "" {
log.Fatal("Error: missing ASG Name")
}
// Any options set to 0 will use template defaults.
// Don't autoscale if no options are set.
if scaleAdj != 0 || scaleUpDel != 0 || scaleDownDel != 0 || scaleUpCPU != 0 || scaleDownCPU != 0 {
pool.SetCPUAutoScaling(asgName, scaleAdj, scaleUpCPU, scaleUpDel, scaleDownCPU, scaleDownDel)
}
}
开发者ID:zombor,项目名称:galaxy,代码行数:19,代码来源:stacks.go
示例15: SSHCmd
func SSHCmd(host string, command string, background bool, debug bool) {
port := "22"
hostPort := strings.SplitN(host, ":", 2)
if len(hostPort) > 1 {
host, port = hostPort[0], hostPort[1]
}
cmd := exec.Command("/usr/bin/ssh",
"-o", "RequestTTY=yes",
host,
"-p", port,
"-C", "/bin/sh", "-i", "-l", "-c", "'"+command+"'")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
var b []byte
buf := bytes.NewBuffer(b)
cmd.Stderr = buf
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
if err := cmd.Wait(); err != nil {
log.Error(buf.String())
if exiterr, ok := err.(*exec.ExitError); ok {
// The program has exited with an exit code != 0
// This works on both Unix and Windows. Although package
// syscall is generally platform dependent, WaitStatus is
// defined for both Unix and Windows and in both cases has
// an ExitStatus() method with the same signature.
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
fmt.Fprintf(os.Stderr, "Command finished with error: %v\n", err)
os.Exit(status.ExitStatus())
}
} else {
fmt.Fprintf(os.Stderr, "Command finished with error: %v\n", err)
os.Exit(1)
}
}
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:43,代码来源:ssh.go
示例16: stackList
func stackList(c *cli.Context) {
if c.String("region") != "" {
stack.Region = c.String("region")
}
descResp, err := stack.DescribeStacks("")
if err != nil {
log.Fatal(err)
}
stacks := []string{"STACK | STATUS | "}
for _, stack := range descResp.Stacks {
s := fmt.Sprintf("%s | %s | %s", stack.Name, stack.Status, stack.StatusReason)
stacks = append(stacks, s)
}
output, _ := columnize.SimpleFormat(stacks)
log.Println(output)
}
开发者ID:zombor,项目名称:galaxy,代码行数:20,代码来源:stacks.go
示例17: sharedResources
func sharedResources(c *cli.Context, baseStack string) stack.SharedResources {
// get the resources we need from the base stack
resources, err := stack.GetSharedResources(baseStack)
if err != nil {
log.Fatal(err)
}
keyName := c.String("keyname")
if keyName != "" {
resources.Parameters["KeyName"] = keyName
}
amiID := c.String("ami")
if amiID != "" {
resources.Parameters["PoolImageId"] = amiID
}
instanceType := c.String("instance-type")
if instanceType != "" {
resources.Parameters["PoolInstanceType"] = instanceType
}
return resources
}
开发者ID:zombor,项目名称:galaxy,代码行数:24,代码来源:stacks.go
示例18: ensurePoolArg
func ensurePoolArg(c *cli.Context) {
if utils.GalaxyPool(c) == "" {
log.Fatal("ERROR: pool is required. Pass --pool or set GALAXY_POOL")
}
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:5,代码来源:galaxy.go
示例19: ensureEnvArg
func ensureEnvArg(c *cli.Context) {
if utils.GalaxyEnv(c) == "" {
log.Fatal("ERROR: env is required. Pass --env or set GALAXY_ENV")
}
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:5,代码来源:galaxy.go
示例20: stackUpdate
// update the base stack
func stackUpdate(c *cli.Context) {
var stackTmpl []byte
var err error
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
params := make(map[string]string)
if p := c.String("parameters"); p != "" {
paramJSON, err := jsonFromArg(p)
if err != nil {
log.Fatal("ERROR: decoding parameters:", err)
}
err = json.Unmarshal(paramJSON, ¶ms)
if err != nil {
log.Fatal(err)
}
}
template := c.String("template")
if template != "" {
stackTmpl, err = jsonFromArg(template)
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
if policy := c.String("policy"); policy != "" {
policyJSON, err := jsonFromArg(policy)
if err != nil {
log.Fatal("policy error:", err)
}
params["StackPolicyDuringUpdateBody"] = string(policyJSON)
}
if len(stackTmpl) == 0 {
// get the current running template
stackTmpl, err = stack.GetTemplate(stackName)
if err != nil {
log.Fatal(err)
}
}
// this reads the Parameters supplied for our current stack for us
shared := sharedResources(c, stackName)
// add any missing parameters to our
for key, val := range shared.Parameters {
if params[key] == "" {
params[key] = val
}
}
p, _ := json.MarshalIndent(params, "", " ")
ok := promptValue(fmt.Sprintf("\nUpdate the [%s] stack with:\n%s\nAccept?", stackName, string(p)), "n")
switch strings.ToLower(ok) {
case "y", "yes":
_, err = stack.Update(stackName, stackTmpl, params)
if err != nil {
log.Fatal(err)
}
log.Println("Updating stack:", stackName)
default:
log.Fatal("aborted")
}
}
开发者ID:zombor,项目名称:galaxy,代码行数:75,代码来源:stacks.go
注:本文中的github.com/litl/galaxy/log.Fatal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论