本文整理匯總了Golang中github.com/docker/machine/log.Fatal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fatal函數的具體用法?Golang Fatal怎麽用?Golang Fatal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fatal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: cmdScp
func cmdScp(c *cli.Context) {
args := c.Args()
if len(args) != 2 {
cli.ShowCommandHelp(c, "scp")
log.Fatal("Improper number of arguments.")
}
// TODO: Check that "-3" flag is available in user's version of scp.
// It is on every system I've checked, but the manual mentioned it's "newer"
sshArgs := append(baseSSHArgs, "-3")
if c.Bool("recursive") {
sshArgs = append(sshArgs, "-r")
}
src := args[0]
dest := args[1]
provider := getDefaultProvider(c)
cmd, err := getScpCmd(src, dest, sshArgs, *provider)
if err != nil {
log.Fatal(err)
}
if err := runCmdWithStdIo(*cmd); err != nil {
log.Fatal(err)
}
}
示例2: cmdInspect
func cmdInspect(c *cli.Context) {
tmplString := c.String("format")
if tmplString != "" {
var tmpl *template.Template
var err error
if tmpl, err = template.New("").Funcs(funcMap).Parse(tmplString); err != nil {
log.Fatalf("Template parsing error: %v\n", err)
}
jsonHost, err := json.Marshal(getHost(c))
if err != nil {
log.Fatal(err)
}
obj := make(map[string]interface{})
if err := json.Unmarshal(jsonHost, &obj); err != nil {
log.Fatal(err)
}
if err := tmpl.Execute(os.Stderr, obj); err != nil {
log.Fatal(err)
}
os.Stderr.Write([]byte{'\n'})
} else {
prettyJSON, err := json.MarshalIndent(getHost(c), "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(prettyJSON))
}
}
示例3: cmdActive
func cmdActive(c *cli.Context) {
if len(c.Args()) > 0 {
log.Fatal("Error: Too many arguments given.")
}
certInfo := getCertPathInfo(c)
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
certInfo.CaCertPath,
certInfo.CaKeyPath,
)
if err != nil {
log.Fatal(err)
}
mcn, err := newMcn(defaultStore)
if err != nil {
log.Fatal(err)
}
host, err := mcn.GetActive()
if err != nil {
log.Fatalf("Error getting active host: %s", err)
}
if host != nil {
fmt.Println(host.Name)
}
}
示例4: setupCertificates
func setupCertificates(caCertPath, caKeyPath, clientCertPath, clientKeyPath string) error {
org := utils.GetUsername()
bits := 2048
if _, err := os.Stat(utils.GetMachineCertDir()); err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(utils.GetMachineCertDir(), 0700); err != nil {
log.Fatalf("Error creating machine config dir: %s", err)
}
} else {
log.Fatal(err)
}
}
if _, err := os.Stat(caCertPath); os.IsNotExist(err) {
log.Infof("Creating CA: %s", caCertPath)
// check if the key path exists; if so, error
if _, err := os.Stat(caKeyPath); err == nil {
log.Fatalf("The CA key already exists. Please remove it or specify a different key/cert.")
}
if err := utils.GenerateCACertificate(caCertPath, caKeyPath, org, bits); err != nil {
log.Infof("Error generating CA certificate: %s", err)
}
}
if _, err := os.Stat(clientCertPath); os.IsNotExist(err) {
log.Infof("Creating client certificate: %s", clientCertPath)
if _, err := os.Stat(utils.GetMachineCertDir()); err != nil {
if os.IsNotExist(err) {
if err := os.Mkdir(utils.GetMachineCertDir(), 0700); err != nil {
log.Fatalf("Error creating machine client cert dir: %s", err)
}
} else {
log.Fatal(err)
}
}
// check if the key path exists; if so, error
if _, err := os.Stat(clientKeyPath); err == nil {
log.Fatalf("The client key already exists. Please remove it or specify a different key/cert.")
}
if err := utils.GenerateCert([]string{""}, clientCertPath, clientKeyPath, caCertPath, caKeyPath, org, bits); err != nil {
log.Fatalf("Error generating client certificate: %s", err)
}
}
return nil
}
示例5: getMachineConfig
func getMachineConfig(c *cli.Context) (*machineConfig, error) {
name := c.Args().First()
certInfo := getCertPathInfo(c)
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
certInfo.CaCertPath,
certInfo.CaKeyPath,
)
if err != nil {
log.Fatal(err)
}
provider, err := newProvider(defaultStore)
if err != nil {
log.Fatal(err)
}
m, err := provider.Get(name)
if err != nil {
return nil, err
}
machineDir := filepath.Join(utils.GetMachineDir(), m.Name)
caCert := filepath.Join(machineDir, "ca.pem")
caKey := filepath.Join(utils.GetMachineCertDir(), "ca-key.pem")
clientCert := filepath.Join(machineDir, "cert.pem")
clientKey := filepath.Join(machineDir, "key.pem")
serverCert := filepath.Join(machineDir, "server.pem")
serverKey := filepath.Join(machineDir, "server-key.pem")
machineUrl, err := m.GetURL()
if err != nil {
if err == drivers.ErrHostIsNotRunning {
machineUrl = ""
} else {
return nil, fmt.Errorf("Unexpected error getting machine url: %s", err)
}
}
return &machineConfig{
machineName: name,
machineDir: machineDir,
machineUrl: machineUrl,
clientKeyPath: clientKey,
clientCertPath: clientCert,
serverCertPath: serverCert,
caKeyPath: caKey,
caCertPath: caCert,
serverKeyPath: serverKey,
AuthOptions: *m.HostOptions.AuthOptions,
SwarmOptions: *m.HostOptions.SwarmOptions,
}, nil
}
示例6: cmdUrl
func cmdUrl(c *cli.Context) {
url, err := getHost(c).GetURL()
if err != nil {
log.Fatal(err)
}
fmt.Println(url)
}
示例7: DumpVal
func DumpVal(vals ...interface{}) {
for _, val := range vals {
prettyJSON, err := json.MarshalIndent(val, "", " ")
if err != nil {
log.Fatal(err)
}
log.Debug(string(prettyJSON))
}
}
示例8: getDefaultProvider
func getDefaultProvider(c *cli.Context) *libmachine.Provider {
certInfo := getCertPathInfo(c)
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
certInfo.CaCertPath,
certInfo.CaKeyPath,
)
if err != nil {
log.Fatal(err)
}
provider, err := newProvider(defaultStore)
if err != nil {
log.Fatal(err)
}
return provider
}
示例9: cmdRegenerateCerts
func cmdRegenerateCerts(c *cli.Context) {
force := c.Bool("force")
if force || confirmInput("Regenerate TLS machine certs? Warning: this is irreversible.") {
log.Infof("Regenerating TLS certificates")
if err := runActionWithContext("configureAuth", c); err != nil {
log.Fatal(err)
}
}
}
示例10: getDefaultMcn
func getDefaultMcn(c *cli.Context) *libmachine.Machine {
certInfo := getCertPathInfo(c)
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
certInfo.CaCertPath,
certInfo.CaKeyPath,
)
if err != nil {
log.Fatal(err)
}
mcn, err := newMcn(defaultStore)
if err != nil {
log.Fatal(err)
}
return mcn
}
示例11: runCmdWithStdIo
func runCmdWithStdIo(cmd exec.Cmd) error {
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
return nil
}
示例12: runActionWithContext
func runActionWithContext(actionName string, c *cli.Context) error {
machines, err := getHosts(c)
if err != nil {
return err
}
if len(machines) == 0 {
log.Fatal(ErrNoMachineSpecified)
}
runActionForeachMachine(actionName, machines)
return nil
}
示例13: getHost
func getHost(c *cli.Context) *libmachine.Host {
name := c.Args().First()
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
c.GlobalString("tls-ca-cert"),
c.GlobalString("tls-ca-key"),
)
if err != nil {
log.Fatal(err)
}
provider, err := newProvider(defaultStore)
if err != nil {
log.Fatal(err)
}
host, err := provider.Get(name)
if err != nil {
log.Fatalf("unable to load host: %v", err)
}
return host
}
示例14: loadMachine
func loadMachine(name string, c *cli.Context) (*libmachine.Host, error) {
certInfo := getCertPathInfo(c)
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
certInfo.CaCertPath,
certInfo.CaKeyPath,
)
if err != nil {
log.Fatal(err)
}
provider, err := newProvider(defaultStore)
if err != nil {
log.Fatal(err)
}
host, err := provider.Get(name)
if err != nil {
return nil, err
}
return host, nil
}
示例15: cmdSsh
func cmdSsh(c *cli.Context) {
args := c.Args()
name := args.First()
if name == "" {
log.Fatal("Error: Please specify a machine name.")
}
certInfo := getCertPathInfo(c)
defaultStore, err := getDefaultStore(
c.GlobalString("storage-path"),
certInfo.CaCertPath,
certInfo.CaKeyPath,
)
if err != nil {
log.Fatal(err)
}
provider, err := newProvider(defaultStore)
if err != nil {
log.Fatal(err)
}
host, err := provider.Get(name)
if err != nil {
log.Fatal(err)
}
currentState, err := host.Driver.GetState()
if err != nil {
log.Fatal(err)
}
if currentState != state.Running {
log.Fatalf("Error: Cannot run SSH command: Host %q is not running", host.Name)
}
if len(c.Args()) == 1 {
err := host.CreateSSHShell()
if err != nil {
log.Fatal(err)
}
} else {
output, err := host.RunSSHCommand(strings.Join(c.Args().Tail(), " "))
if err != nil {
log.Fatal(err)
}
fmt.Print(output)
}
}