func run(c *cli.Context) { log.Info("Running GoSupervise!") port, err := osExpandAndVerifyGlobal(c, "port") if err != nil { fail(err) } command, err := osExpandAndVerify(c, "command") if err != nil { fail(err) } host, err := osExpandAndVerify(c, "host") if err != nil { fail(err) } user, err := osExpandAndVerify(c, "user") if err != nil { fail(err) } useWinRM := c.Bool("winrm") if useWinRM { password, err := osExpandAndVerify(c, "password") if err != nil { fail(err) } err = winrm.RemoteWinRmCommand(user, password, host, port, command) } else { privatekey, err := osExpandAndVerify(c, "privatekey") if err != nil { fail(err) } hostPort := host + ":" + port err = ssh.RemoteSshCommand(user, privatekey, hostPort, command) } if err != nil { log.Err("Failed: %v", err) } }
func runAnsiblePod(c *cli.Context) { args := c.Args() if len(args) < 2 { log.Die("Expected at least 2 arguments!") } hosts := args[0] command := strings.Join(args[1:], " ") log.Info("running command on a host from %s and command `%s`", hosts, command) f := cmdutil.NewFactory(nil) if f == nil { log.Die("Failed to create Kuberentes client factory!") } kubeclient, _ := f.Client() if kubeclient == nil { log.Die("Failed to create Kuberentes client!") } ns, _, _ := f.DefaultNamespace() if len(ns) == 0 { ns = "default" } rcFile, err := osExpandAndVerify(c, "rc") if err != nil { fail(err) } port, err := osExpandAndVerifyGlobal(c, "port") if err != nil { fail(err) } inventory, err := osExpandAndVerify(c, "inventory") if err != nil { fail(err) } rc, err := k8s.ReadReplicationControllerFromFile(rcFile) if err != nil { fail(err) } rcName := rc.ObjectMeta.Name if len(rcName) == 0 { log.Die("No ReplicationController name in the yaml file %s", rcFile) } hostEntry, err := ansible.ChooseHostAndPrivateKey(inventory, hosts, kubeclient, ns, rcName) if err != nil { fail(err) } host := hostEntry.Host user := hostEntry.User useWinRM := c.Bool("winrm") || hostEntry.UseWinRM if useWinRM { log.Info("Using WinRM to connect to the hosts %s", hosts) password, err := osExpandAndVerify(c, "password") if err != nil { fail(err) } err = winrm.RemoteWinRmCommand(user, password, host, port, command) } else { privatekey := hostEntry.PrivateKey hostPort := host + ":" + port err = ssh.RemoteSshCommand(user, privatekey, hostPort, command) } if err != nil { log.Err("Failed: %v", err) } }