本文整理匯總了Golang中github.com/marcosnils/cmt/cmd.Cmd.Run方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cmd.Run方法的具體用法?Golang Cmd.Run怎麽用?Golang Cmd.Run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/marcosnils/cmt/cmd.Cmd
的用法示例。
在下文中一共展示了Cmd.Run方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkCPUCompat
func checkCPUCompat(srcCmd, dstCmd cmd.Cmd) error {
// Dump
_, _, err := srcCmd.Run("sudo", "criu", "cpuinfo", "dump")
if _, ok := err.(*ssh.ExitError); ok {
return fmt.Errorf("Error dumping CPU info")
} else if _, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("Error dumping CPU info")
} else if err != nil {
return fmt.Errorf("Connection error: %s ", err)
}
// Copy
err = cmd.Scp(srcCmd.URL("./cpuinfo.img"), dstCmd.URL("."))
if _, ok := err.(*ssh.ExitError); ok {
return fmt.Errorf("Error copying dump image")
} else if _, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("Error copying dump image")
} else if err != nil {
return fmt.Errorf("Connection error: %s ", err)
}
// Check
_, _, err = srcCmd.Run("sudo", "criu", "cpuinfo", "check")
if _, ok := err.(*ssh.ExitError); ok {
return fmt.Errorf("Error checking CPU info")
} else if _, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("Error checking CPU info")
} else if err != nil {
return fmt.Errorf("Connection error: %s ", err)
}
return nil
}
示例2: getIPTables
func getIPTables(host cmd.Cmd) (string, error) {
rules, _, err := host.Run("sudo", "iptables-save")
if err != nil {
return "", err
}
return rules, nil
}
示例3: isRunning
func isRunning(containerId string, dstCmd cmd.Cmd) bool {
_, _, err := dstCmd.Run("stat", fmt.Sprintf("/var/run/opencontainer/containers/%s", containerId))
if err != nil {
return true
}
return false
}
示例4: getVersion
func getVersion(command cmd.Cmd, name string) (string, error) {
version, _, err := command.Run("sudo", name, "--version")
if _, ok := err.(*ssh.ExitError); ok {
return "", fmt.Errorf("Error %s does not exist", name)
} else if _, ok := err.(*exec.ExitError); ok {
return "", fmt.Errorf("Error %s does not exist", name)
} else if err != nil {
return "", fmt.Errorf("Connection error: %s ", err)
}
return version, nil
}
示例5: checkKernelCap
func checkKernelCap(c cmd.Cmd) error {
_, _, err := c.Run("sudo", "criu", "check", "--ms")
if _, ok := err.(*ssh.ExitError); ok {
return fmt.Errorf("Error criu checks do not pass")
} else if _, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("Error criu checks do not pass")
} else if err != nil {
return fmt.Errorf("Connection error: %s ", err)
}
return err
}
示例6: applyIPTablesRules
func applyIPTablesRules(host cmd.Cmd, rules []string) error {
for _, rule := range rules {
args := []string{"iptables"}
args = append(args, strings.Fields(rule)...)
_, _, err := host.Run("sudo", args...)
if err != nil {
return err
}
}
return nil
}
示例7: unpackTar
func unpackTar(cmd cmd.Cmd, tarFile, workDir string) {
log.Println("Preparing image at destination host")
_, _, err := cmd.Run("sudo", "tar", "-C", workDir, "-xvzf", tarFile)
if err != nil {
log.Fatal("Error uncompressing image in destination:", err)
}
}
示例8: checkpoint
func checkpoint(cmd cmd.Cmd, containerId, imagesPath string, predump bool) {
log.Printf("Performing the checkpoint predump = %t\n", predump)
args := []string{"runc", "--id", containerId, "checkpoint", "--track-mem", "--image-path", imagesPath}
if predump {
args = append(args, "--pre-dump")
}
_, _, err := cmd.Run("sudo", args...)
if err != nil {
log.Fatal("Error performing checkpoint:", err)
}
}
示例9: prepareDir
func prepareDir(cmd cmd.Cmd, path string) {
_, _, err := cmd.Run("mkdir", "-p", path)
if err != nil {
log.Fatal("Error preparing pre-dump dir:", err)
}
}
示例10: prepareTar
func prepareTar(cmd cmd.Cmd, tarFile, workDir string) {
_, _, err := cmd.Run("sudo", "tar", "-czf", tarFile, "-C", fmt.Sprintf("%s/", workDir), ".")
if err != nil {
log.Fatal("Error compressing image in source:", err)
}
}