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
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2015-04-07 18:55:44 -04:00
|
|
|
|
|
|
|
"github.com/minio-io/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
|
|
|
|
disks map[string]Disk
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewNode - instantiates a new node
|
|
|
|
func NewNode(hostname string) (Node, error) {
|
|
|
|
if hostname == "" {
|
2015-04-07 18:55:44 -04:00
|
|
|
return nil, iodine.New(errors.New("invalid argument"), nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
disks := make(map[string]Disk)
|
|
|
|
n := node{
|
|
|
|
hostname: hostname,
|
|
|
|
disks: disks,
|
|
|
|
}
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// GetNodeName - return hostname
|
2015-04-05 04:53:41 -04:00
|
|
|
func (n node) GetNodeName() string {
|
|
|
|
return n.hostname
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// ListDisks - return number of disks
|
2015-04-05 04:53:41 -04:00
|
|
|
func (n node) ListDisks() (map[string]Disk, error) {
|
|
|
|
return n.disks, nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// AttachDisk - attach a disk
|
2015-04-05 04:53:41 -04:00
|
|
|
func (n node) AttachDisk(disk Disk) error {
|
|
|
|
if disk == nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(errors.New("Invalid argument"), nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
n.disks[disk.GetPath()] = disk
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// DetachDisk - detach a disk
|
2015-04-05 04:53:41 -04:00
|
|
|
func (n node) DetachDisk(disk Disk) error {
|
|
|
|
delete(n.disks, disk.GetPath())
|
|
|
|
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 {
|
|
|
|
return errors.New("Not Implemented")
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return errors.New("Not Implemented")
|
|
|
|
}
|