示例#1
0
// NewApp creates a new cli app
func NewApp(eh *ErrorHandler) *cli.App {
	app := cli.NewApp()
	app.Version = VERSION
	app.Name = "cfops"
	app.Usage = "Cloud Foundry Operations Tool"
	app.Commands = []cli.Command{
		cli.Command{
			Name:  "version",
			Usage: "shows the application version currently in use",
			Action: func(c *cli.Context) {
				cli.ShowVersion(c)
			},
		},
		cli.Command{
			Name:  "list-tiles",
			Usage: "shows a list of available backup/restore target tiles",
			Action: func(c *cli.Context) {
				fmt.Println("Available Tiles:")
				for n, _ := range tileregistry.GetRegistry() {
					fmt.Println(n)
				}
			},
		},
		CreateBURACliCommand("backup", "creates a backup archive of the target tile", eh),
		CreateBURACliCommand("restore", "restores from an archive to the target tile", eh),
	}
	return app
}
示例#2
0
func getTileFromRegistry(fs *flagSet, commandName string) (tile tileregistry.Tile, err error) {
	lo.G.Debug("checking registry for '%s' tile", fs.Tile())

	if tileBuilder, ok := tileregistry.GetRegistry()[fs.Tile()]; ok {
		lo.G.Debug("found tile in registry")

		if hasValidBackupRestoreFlags(fs) {
			lo.G.Debug("we have all required flags and a proper builder")
			tile, err = tileBuilder.New(tileregistry.TileSpec{
				OpsManagerHost:   fs.Host(),
				AdminUser:        fs.AdminUser(),
				AdminPass:        fs.AdminPass(),
				OpsManagerUser:   fs.OpsManagerUser(),
				OpsManagerPass:   fs.OpsManagerPass(),
				ArchiveDirectory: fs.Dest(),
			})
			if err != nil {
				return nil, fmt.Errorf("failure to connect to ops manager host: %s", err.Error())
			}

		} else {
			err = ErrInvalidFlagArgs
		}

	} else {
		lo.G.Errorf("tile '%s' not found", fs.Tile())
		err = ErrInvalidTileSelection
	}
	return
}
示例#3
0
func getTileFromRegistry(fs *flagSet, commandName string) (err error) {
	var tile tileregistry.Tile
	lo.G.Debug("checking registry for available tile")
	lo.G.Error(fs.Tile())

	if tileBuilder, ok := tileregistry.GetRegistry()[fs.Tile()]; ok {
		lo.G.Debug("found tile in registry")

		if hasValidBackupRestoreFlags(fs) {
			lo.G.Debug("we have all required flags and a proper builder: ", tileBuilder)
			tile, err = tileBuilder.New(tileregistry.TileSpec{
				OpsManagerHost:   fs.Host(),
				AdminUser:        fs.AdminUser(),
				AdminPass:        fs.AdminPass(),
				OpsManagerUser:   fs.OpsManagerUser(),
				OpsManagerPass:   fs.OpsManagerPass(),
				ArchiveDirectory: fs.Dest(),
			})
			err = runTileAction(commandName, tile)

		} else {
			err = ErrInvalidFlagArgs
		}

	} else {
		err = ErrInvalidTileSelection
	}
	return
}