minio/pkg/donut/node.go

77 lines
1.9 KiB
Go
Raw Normal View History

2015-04-05 04:53:41 -04:00
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
2015-04-05 04:53:41 -04: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 donut
2015-06-24 23:34:20 -04:00
import (
"github.com/minio/minio/pkg/donut/disk"
2015-08-03 19:17:21 -04:00
"github.com/minio/minio/pkg/probe"
2015-06-24 23:34:20 -04:00
)
2015-04-05 04:53:41 -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
2015-08-03 19:17:21 -04:00
func newNode(hostname string) (node, *probe.Error) {
2015-04-05 04:53:41 -04:00
if hostname == "" {
2015-08-03 19:17:21 -04:00
return node{}, probe.New(InvalidArgument{})
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
}
// ListDisks - return number of disks
2015-08-03 19:17:21 -04:00
func (n node) ListDisks() (map[int]disk.Disk, *probe.Error) {
2015-04-05 04:53:41 -04:00
return n.disks, nil
}
// AttachDisk - attach a disk
2015-08-03 19:17:21 -04:00
func (n node) AttachDisk(disk disk.Disk, diskOrder int) *probe.Error {
2015-06-24 23:34:20 -04:00
if diskOrder < 0 {
2015-08-03 19:17:21 -04:00
return probe.New(InvalidArgument{})
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
}
// DetachDisk - detach a disk
2015-08-03 19:17:21 -04:00
func (n node) DetachDisk(diskOrder int) *probe.Error {
2015-06-24 23:34:20 -04:00
delete(n.disks, diskOrder)
2015-04-05 04:53:41 -04:00
return nil
}
// SaveConfig - save node configuration
2015-08-03 19:17:21 -04:00
func (n node) SaveConfig() *probe.Error {
return probe.New(NotImplemented{Function: "SaveConfig"})
2015-04-05 04:53:41 -04:00
}
// LoadConfig - load node configuration from saved configs
2015-08-03 19:17:21 -04:00
func (n node) LoadConfig() *probe.Error {
return probe.New(NotImplemented{Function: "LoadConfig"})
2015-04-05 04:53:41 -04:00
}