2015-04-05 04:53:41 -04:00
|
|
|
/*
|
|
|
|
* Minimalist Object Storage, (C) 2015 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 donut
|
|
|
|
|
2015-06-24 23:34:20 -04:00
|
|
|
import (
|
2015-07-03 03:29:54 -04:00
|
|
|
"github.com/minio/minio/pkg/donut/disk"
|
2015-06-24 23:34:20 -04:00
|
|
|
"github.com/minio/minio/pkg/iodine"
|
|
|
|
)
|
2015-04-05 04:53:41 -04:00
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// node struct internal
|
2015-04-05 04:53:41 -04:00
|
|
|
type node struct {
|
|
|
|
hostname string
|
2015-06-24 23:34:20 -04:00
|
|
|
disks map[int]disk.Disk
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
|
2015-06-25 15:55:13 -04:00
|
|
|
// newNode - instantiates a new node
|
|
|
|
func newNode(hostname string) (node, error) {
|
2015-04-05 04:53:41 -04:00
|
|
|
if hostname == "" {
|
2015-06-25 15:55:13 -04:00
|
|
|
return node{}, iodine.New(InvalidArgument{}, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
2015-06-24 23:34:20 -04:00
|
|
|
disks := make(map[int]disk.Disk)
|
2015-04-05 04:53:41 -04:00
|
|
|
n := node{
|
|
|
|
hostname: hostname,
|
|
|
|
disks: disks,
|
|
|
|
}
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
2015-06-25 15:55:13 -04:00
|
|
|
// GetHostname - return hostname
|
|
|
|
func (n node) GetHostname() string {
|
2015-04-05 04:53:41 -04:00
|
|
|
return n.hostname
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// ListDisks - return number of disks
|
2015-06-24 23:34:20 -04:00
|
|
|
func (n node) ListDisks() (map[int]disk.Disk, error) {
|
2015-04-05 04:53:41 -04:00
|
|
|
return n.disks, nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// AttachDisk - attach a disk
|
2015-06-24 23:34:20 -04:00
|
|
|
func (n node) AttachDisk(disk disk.Disk, diskOrder int) error {
|
|
|
|
if diskOrder < 0 {
|
2015-06-23 14:44:32 -04:00
|
|
|
return iodine.New(InvalidArgument{}, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
2015-06-24 23:34:20 -04:00
|
|
|
n.disks[diskOrder] = disk
|
2015-04-05 04:53:41 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// DetachDisk - detach a disk
|
2015-06-24 23:34:20 -04:00
|
|
|
func (n node) DetachDisk(diskOrder int) error {
|
|
|
|
delete(n.disks, diskOrder)
|
2015-04-05 04:53:41 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// SaveConfig - save node configuration
|
2015-04-05 04:53:41 -04:00
|
|
|
func (n node) SaveConfig() error {
|
2015-06-23 14:44:32 -04:00
|
|
|
return iodine.New(NotImplemented{Function: "SaveConfig"}, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// LoadConfig - load node configuration from saved configs
|
2015-04-05 04:53:41 -04:00
|
|
|
func (n node) LoadConfig() error {
|
2015-06-23 14:44:32 -04:00
|
|
|
return iodine.New(NotImplemented{Function: "LoadConfig"}, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|