2018-02-20 15:21:12 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
2018-02-20 15:21:12 -05:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package nas
|
|
|
|
|
|
|
|
import (
|
2019-01-24 08:44:05 -05:00
|
|
|
"context"
|
|
|
|
|
2018-02-20 15:21:12 -05:00
|
|
|
"github.com/minio/cli"
|
|
|
|
minio "github.com/minio/minio/cmd"
|
|
|
|
"github.com/minio/minio/pkg/auth"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
nasBackend = "nas"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
const nasGatewayTemplate = `NAME:
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
{{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} PATH
|
|
|
|
{{if .VisibleFlags}}
|
|
|
|
FLAGS:
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
{{end}}{{end}}
|
|
|
|
PATH:
|
2019-12-16 23:30:57 -05:00
|
|
|
path to NAS mount point
|
2018-03-28 17:14:06 -04:00
|
|
|
|
2018-02-20 15:21:12 -05:00
|
|
|
EXAMPLES:
|
2019-12-16 23:30:57 -05:00
|
|
|
1. Start minio gateway server for NAS backend
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ACCESS_KEY{{.AssignmentOperator}}accesskey
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_SECRET_KEY{{.AssignmentOperator}}secretkey
|
|
|
|
{{.Prompt}} {{.HelpName}} /shared/nasvol
|
2018-06-01 18:45:11 -04:00
|
|
|
|
2019-12-16 23:30:57 -05:00
|
|
|
2. Start minio gateway server for NAS with edge caching enabled
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ACCESS_KEY{{.AssignmentOperator}}accesskey
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_SECRET_KEY{{.AssignmentOperator}}secretkey
|
2019-11-20 18:10:24 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_DRIVES{{.AssignmentOperator}}"/mnt/drive1,/mnt/drive2,/mnt/drive3,/mnt/drive4"
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_EXCLUDE{{.AssignmentOperator}}"bucket1/*,*.png"
|
2020-02-23 08:33:39 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_QUOTA{{.AssignmentOperator}}90
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_AFTER{{.AssignmentOperator}}3
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_LOW{{.AssignmentOperator}}75
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_HIGH{{.AssignmentOperator}}85
|
|
|
|
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.HelpName}} /shared/nasvol
|
2018-02-20 15:21:12 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
minio.RegisterGatewayCommand(cli.Command{
|
|
|
|
Name: nasBackend,
|
2018-11-20 20:35:33 -05:00
|
|
|
Usage: "Network-attached storage (NAS)",
|
2018-02-20 15:21:12 -05:00
|
|
|
Action: nasGatewayMain,
|
|
|
|
CustomHelpTemplate: nasGatewayTemplate,
|
|
|
|
HideHelpCommand: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handler for 'minio gateway nas' command line.
|
|
|
|
func nasGatewayMain(ctx *cli.Context) {
|
|
|
|
// Validate gateway arguments.
|
2018-06-01 18:45:11 -04:00
|
|
|
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
2018-03-14 21:36:54 -04:00
|
|
|
cli.ShowCommandHelpAndExit(ctx, nasBackend, 1)
|
2018-02-20 15:21:12 -05:00
|
|
|
}
|
2018-06-01 18:45:11 -04:00
|
|
|
|
|
|
|
minio.StartGateway(ctx, &NAS{ctx.Args().First()})
|
2018-02-20 15:21:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NAS implements Gateway.
|
|
|
|
type NAS struct {
|
2018-06-01 18:45:11 -04:00
|
|
|
path string
|
2018-02-20 15:21:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name implements Gateway interface.
|
|
|
|
func (g *NAS) Name() string {
|
|
|
|
return nasBackend
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGatewayLayer returns nas gatewaylayer.
|
|
|
|
func (g *NAS) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) {
|
|
|
|
var err error
|
2018-06-01 18:45:11 -04:00
|
|
|
newObject, err := minio.NewFSObjectLayer(g.path)
|
2018-02-20 15:21:12 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-12-03 03:32:14 -05:00
|
|
|
return &nasObjects{newObject}, nil
|
2018-02-20 15:21:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Production - nas gateway is production ready.
|
|
|
|
func (g *NAS) Production() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-12-05 17:03:42 -05:00
|
|
|
// IsListenBucketSupported returns whether listen bucket notification is applicable for this gateway.
|
2018-12-11 19:16:09 -05:00
|
|
|
func (n *nasObjects) IsListenBucketSupported() bool {
|
2018-12-05 17:03:42 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-05-28 16:03:04 -04:00
|
|
|
func (n *nasObjects) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
|
|
|
si, errs := n.ObjectLayer.StorageInfo(ctx, false)
|
|
|
|
si.Backend.GatewayOnline = si.Backend.Type == minio.BackendFS
|
|
|
|
si.Backend.Type = minio.BackendGateway
|
|
|
|
return si, errs
|
2019-01-24 08:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-04-09 14:39:42 -04:00
|
|
|
// nasObjects implements gateway for MinIO and S3 compatible object storage servers.
|
2018-02-20 15:21:12 -05:00
|
|
|
type nasObjects struct {
|
2018-12-03 03:32:14 -05:00
|
|
|
minio.ObjectLayer
|
2018-09-27 23:36:17 -04:00
|
|
|
}
|
2019-12-28 11:54:43 -05:00
|
|
|
|
|
|
|
// IsReady returns whether the layer is ready to take requests.
|
|
|
|
func (n *nasObjects) IsReady(ctx context.Context) bool {
|
2020-05-28 16:03:04 -04:00
|
|
|
si, _ := n.StorageInfo(ctx, false)
|
|
|
|
return si.Backend.GatewayOnline
|
2019-12-28 11:54:43 -05:00
|
|
|
}
|
2020-05-23 14:09:35 -04:00
|
|
|
|
|
|
|
func (n *nasObjects) IsTaggingSupported() bool {
|
|
|
|
return true
|
|
|
|
}
|