2018-02-20 15:21:12 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2018 Minio, Inc.
|
|
|
|
*
|
|
|
|
* 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 (
|
|
|
|
"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:
|
2018-05-21 14:11:57 -04:00
|
|
|
Path to NAS mount point.
|
2018-02-20 15:21:12 -05:00
|
|
|
|
|
|
|
ENVIRONMENT VARIABLES:
|
|
|
|
ACCESS:
|
|
|
|
MINIO_ACCESS_KEY: Username or access key of minimum 3 characters in length.
|
|
|
|
MINIO_SECRET_KEY: Password or secret key of minimum 8 characters in length.
|
|
|
|
|
|
|
|
BROWSER:
|
|
|
|
MINIO_BROWSER: To disable web browser access, set this value to "off".
|
|
|
|
|
2018-05-21 14:11:57 -04:00
|
|
|
DOMAIN:
|
|
|
|
MINIO_DOMAIN: To enable virtual-host-style requests, set this value to Minio host domain name.
|
|
|
|
|
2018-03-28 17:14:06 -04:00
|
|
|
CACHE:
|
2018-04-02 00:55:09 -04:00
|
|
|
MINIO_CACHE_DRIVES: List of mounted drives or directories delimited by ";".
|
2018-03-29 16:29:21 -04:00
|
|
|
MINIO_CACHE_EXCLUDE: List of cache exclusion patterns delimited by ";".
|
|
|
|
MINIO_CACHE_EXPIRY: Cache expiry duration in days.
|
2018-06-25 13:24:12 -04:00
|
|
|
MINIO_CACHE_MAXUSE: Maximum permitted usage of the cache in percentage (0-100).
|
2018-03-28 17:14:06 -04:00
|
|
|
|
2018-02-20 15:21:12 -05:00
|
|
|
EXAMPLES:
|
|
|
|
1. Start minio gateway server for NAS backend.
|
2018-05-21 14:11:57 -04:00
|
|
|
$ export MINIO_ACCESS_KEY=accesskey
|
|
|
|
$ export MINIO_SECRET_KEY=secretkey
|
|
|
|
$ {{.HelpName}} /shared/nasvol
|
2018-06-01 18:45:11 -04:00
|
|
|
|
2018-03-28 17:14:06 -04:00
|
|
|
2. Start minio gateway server for NAS with edge caching enabled.
|
2018-05-21 14:11:57 -04:00
|
|
|
$ export MINIO_ACCESS_KEY=accesskey
|
|
|
|
$ export MINIO_SECRET_KEY=secretkey
|
|
|
|
$ export MINIO_CACHE_DRIVES="/mnt/drive1;/mnt/drive2;/mnt/drive3;/mnt/drive4"
|
|
|
|
$ export MINIO_CACHE_EXCLUDE="bucket1/*;*.png"
|
|
|
|
$ export MINIO_CACHE_EXPIRY=40
|
2018-06-25 13:24:12 -04:00
|
|
|
$ export MINIO_CACHE_MAXUSE=80
|
2018-05-21 14:11:57 -04:00
|
|
|
$ {{.HelpName}} /shared/nasvol
|
2018-02-20 15:21:12 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
minio.RegisterGatewayCommand(cli.Command{
|
|
|
|
Name: nasBackend,
|
|
|
|
Usage: "Network-attached storage (NAS).",
|
|
|
|
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
|
|
|
|
}
|
|
|
|
return &nasObjects{newObject.(*minio.FSObjects)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Production - nas gateway is production ready.
|
|
|
|
func (g *NAS) Production() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// nasObjects implements gateway for Minio and S3 compatible object storage servers.
|
|
|
|
type nasObjects struct {
|
|
|
|
*minio.FSObjects
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsNotificationSupported returns whether notifications are applicable for this layer.
|
|
|
|
func (l *nasObjects) IsNotificationSupported() bool {
|
|
|
|
return false
|
|
|
|
}
|
2018-09-27 23:36:17 -04:00
|
|
|
|
|
|
|
// IsCompressionSupported returns whether compression is applicable for this layer.
|
|
|
|
func (l *nasObjects) IsCompressionSupported() bool {
|
|
|
|
return false
|
|
|
|
}
|