commands

package
v2.1.0-rc.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2016 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegisterSelfCommand = cli.Command{
	Name:        "register-self",
	Usage:       "register-self [options]",
	Description: "Registers virtual instance that calls this script to iCE.",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "api-endpoint",
			Usage: "The iCE REST API endpoint URL",
		},
		cli.StringFlag{
			Name:  "session-id",
			Usage: "The session id",
		},
	},

	Action: func(ctx *cli.Context) error {
		apiEndpoint := ctx.String("api-endpoint")
		sessionID := ctx.String("session-id")

		inst := ice.Instance{
			SessionID: sessionID,
		}

		// SSH
		var err error
		inst.SSHUsername, err = ssh.Username(context.TODO())
		if err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}
		inst.SSHAuthorizedFingerprint, err = ssh.AuthorizedFingerprint(
			context.TODO(), inst.SSHUsername,
		)
		if err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}

		iceClient := ice.NewClient(apiEndpoint)

		inst.Networks, err = network.Networks(context.TODO())
		if err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}
		inst.PublicIPAddr, err = iceClient.MyIP(context.TODO())
		if err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}
		inst.PublicReverseDNS, err = network.ReverseDNS(
			context.TODO(), inst.PublicIPAddr.String(),
		)
		if err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}

		instID, err := iceClient.StoreInstance(context.TODO(), inst)
		if err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}

		if err := state.WriteInstanceID(context.TODO(), instID); err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}

		inst.ID = instID
		if err := json.NewEncoder(os.Stdout).Encode(inst); err != nil {
			return cli.NewExitError(fmt.Sprintf("ERROR: %s", err), 1)
		}

		return nil
	},
}

RegisterSelfCommand implements the register-self subcommand of the agent.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL