Ejemplo n.º 1
0
// hostannouncecmd is the handler for the command `siac host announce`.
// Announces yourself as a host to the network. Optionally takes an address to
// announce as.
func hostannouncecmd(cmd *cobra.Command, args []string) {
	var err error
	switch len(args) {
	case 0:
		err = post("/host/announce", "")
	case 1:
		err = post("/host/announce", "netaddress="+args[0])
	default:
		cmd.UsageFunc()(cmd)
		os.Exit(exitCodeUsage)
	}
	if err != nil {
		die("Could not announce host:", err)
	}
	fmt.Println("Host announcement submitted to network.")

	// start accepting contracts
	err = post("/host", "acceptingcontracts=true")
	if err != nil {
		die("Could not configure host to accept contracts:", err)
	}
	fmt.Println(`
The host has also been configured to accept contracts.
To revert this, run:
	siac host config acceptingcontracts false
`)
}
Ejemplo n.º 2
0
// CommandFor returns the appropriate command for this base name,
// or the OpenShift CLI command.
func CommandFor(basename string) *cobra.Command {
	var cmd *cobra.Command

	out := os.Stdout

	// Make case-insensitive and strip executable suffix if present
	if runtime.GOOS == "windows" {
		basename = strings.ToLower(basename)
		basename = strings.TrimSuffix(basename, ".exe")
	}

	switch basename {
	case "kubectl":
		cmd = NewCmdKubectl(basename, out)
	default:
		cmd = NewCommandCLI(basename, basename, out)
	}

	if cmd.UsageFunc() == nil {
		templates.ActsAsRootCommand(cmd)
	}
	flagtypes.GLog(cmd.PersistentFlags())

	return cmd
}
Ejemplo n.º 3
0
func delete(cmd *cobra.Command, args []string) {
	url := cmd.Flag("registry").Value.String()

	if len(args) != 1 {
		cmd.UsageFunc()(cmd)
		return
	}

	delimg := args[0]

	conn, err := connect(cmd)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	images, err := catalog(conn, url)

	for _, name := range images {
		tags, err := tags(conn, url, name)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			continue
		}

		for _, tag := range tags {
			if strings.Compare(delimg, name+":"+tag) == 0 {
				digest, _, err := manifest(conn, url, name, tag)
				if err != nil {
					fmt.Fprintf(os.Stderr, "manifest: %v\n", err)
					return
				}

				err = deleteImage(conn, url, name, digest)
				if err != nil {
					fmt.Fprintf(os.Stderr, "delete: %v\n", err)
					return
				}

				fmt.Printf("deleted %s:%s\n", name, tag)

				return
			}
		}
	}
}
Ejemplo n.º 4
0
// CommandFor returns the appropriate command for this base name,
// or the global OpenShift command
func CommandFor(basename string) *cobra.Command {
	var cmd *cobra.Command

	in, out, errout := os.Stdin, os.Stdout, os.Stderr

	// Make case-insensitive and strip executable suffix if present
	if runtime.GOOS == "windows" {
		basename = strings.ToLower(basename)
		basename = strings.TrimSuffix(basename, ".exe")
	}

	switch basename {
	case "openshift-router":
		cmd = irouter.NewCommandTemplateRouter(basename)
	case "openshift-f5-router":
		cmd = irouter.NewCommandF5Router(basename)
	case "openshift-deploy":
		cmd = deployer.NewCommandDeployer(basename)
	case "openshift-recycle":
		cmd = recycle.NewCommandRecycle(basename, out)
	case "openshift-sti-build":
		cmd = builder.NewCommandSTIBuilder(basename)
	case "openshift-docker-build":
		cmd = builder.NewCommandDockerBuilder(basename)
	case "oc", "osc":
		cmd = cli.NewCommandCLI(basename, basename, in, out, errout)
	case "oadm", "osadm":
		cmd = admin.NewCommandAdmin(basename, basename, out, errout)
	case "kubectl":
		cmd = cli.NewCmdKubectl(basename, out)
	case "kube-apiserver":
		cmd = kubernetes.NewAPIServerCommand(basename, basename, out)
	case "kube-controller-manager":
		cmd = kubernetes.NewControllersCommand(basename, basename, out)
	case "kubelet":
		cmd = kubernetes.NewKubeletCommand(basename, basename, out)
	case "kube-proxy":
		cmd = kubernetes.NewProxyCommand(basename, basename, out)
	case "kube-scheduler":
		cmd = kubernetes.NewSchedulerCommand(basename, basename, out)
	case "kubernetes":
		cmd = kubernetes.NewCommand(basename, basename, out)
	case "origin", "atomic-enterprise":
		cmd = NewCommandOpenShift(basename)
	default:
		cmd = NewCommandOpenShift("openshift")
	}

	if cmd.UsageFunc() == nil {
		templates.ActsAsRootCommand(cmd, []string{"options"})
	}
	flagtypes.GLog(cmd.PersistentFlags())

	return cmd
}
Ejemplo n.º 5
0
// CommandFor returns the appropriate command for this base name,
// or the global OpenShift command
func CommandFor(basename string) *cobra.Command {
	var cmd *cobra.Command

	out := os.Stdout

	// Make case-insensitive and strip executable suffix if present
	if runtime.GOOS == "windows" {
		basename = strings.ToLower(basename)
		basename = strings.TrimSuffix(basename, ".exe")
	}

	switch basename {
	case "atomic-enterprise-router":
		cmd = irouter.NewCommandTemplateRouter(basename)
	case "atomic-enterprise-deploy":
		cmd = deployer.NewCommandDeployer(basename)
	case "atomic-enterprise-gitserver":
		cmd = gitserver.NewCommandGitServer(basename)
	case "oc", "osc":
		cmd = cli.NewCommandCLI(basename, basename)
	case "oadm", "osadm":
		cmd = admin.NewCommandAdmin(basename, basename, out)
	case "kubectl":
		cmd = cli.NewCmdKubectl(basename, out)
	case "kube-apiserver":
		cmd = kubernetes.NewAPIServerCommand(basename, basename, out)
	case "kube-controller-manager":
		cmd = kubernetes.NewControllersCommand(basename, basename, out)
	case "kubelet":
		cmd = kubernetes.NewKubeletCommand(basename, basename, out)
	case "kube-proxy":
		cmd = kubernetes.NewProxyCommand(basename, basename, out)
	case "kube-scheduler":
		cmd = kubernetes.NewSchedulerCommand(basename, basename, out)
	case "kubernetes":
		cmd = kubernetes.NewCommand(basename, basename, out)
	case "origin":
		cmd = NewCommandAtomicEnterprise("origin")
	default:
		cmd = NewCommandAtomicEnterprise("atomic-enterprise")
	}

	if cmd.UsageFunc() == nil {
		templates.ActsAsRootCommand(cmd)
	}
	flagtypes.GLog(cmd.PersistentFlags())

	return cmd
}
Ejemplo n.º 6
0
func Usage(c *cobra.Command) func() error {

	return func() error {
		return c.UsageFunc()(c)
	}
}
Ejemplo n.º 7
0
func ConsoleErr(cmd *cobra.Command, str string) {
	cmd.Printf(str)
	cmd.Println("")
	cmd.UsageFunc()(cmd)
	os.Exit(1)
}