2015-07-05 03:54:57 -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 rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/iodine"
|
|
|
|
"github.com/minio/minio/pkg/utils/scsi"
|
|
|
|
)
|
|
|
|
|
2015-07-05 13:19:23 -04:00
|
|
|
// DiskInfoService disk info service
|
|
|
|
type DiskInfoService struct{}
|
2015-07-05 03:54:57 -04:00
|
|
|
|
2015-07-05 13:19:23 -04:00
|
|
|
// DiskInfoReply disk info reply for disk info service
|
|
|
|
type DiskInfoReply struct {
|
2015-07-05 03:54:57 -04:00
|
|
|
Hostname string `json:"hostname"`
|
2015-07-09 14:57:10 -04:00
|
|
|
Mounts map[string]scsi.Mountinfo `json:"mounts"`
|
2015-07-05 03:54:57 -04:00
|
|
|
Disks []string `json:"disks"`
|
2015-07-09 14:57:10 -04:00
|
|
|
DiskAttributes map[string]scsi.Attributes `json:"-"` // for the time being not unmarshalling this
|
2015-07-05 03:54:57 -04:00
|
|
|
}
|
|
|
|
|
2015-07-05 13:19:23 -04:00
|
|
|
func setDiskInfoReply(sis *DiskInfoReply) error {
|
2015-07-05 03:54:57 -04:00
|
|
|
var err error
|
|
|
|
sis.Hostname, err = os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-07-09 14:57:10 -04:00
|
|
|
mounts, err := scsi.GetMountInfo()
|
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
sis.Mounts = make(map[string]scsi.Mountinfo)
|
|
|
|
sis.Mounts = mounts
|
|
|
|
|
2015-07-05 03:54:57 -04:00
|
|
|
disks, err := scsi.GetDisks()
|
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
sis.DiskAttributes = make(map[string]scsi.Attributes)
|
2015-07-09 14:57:10 -04:00
|
|
|
|
2015-07-05 03:54:57 -04:00
|
|
|
for k, v := range disks {
|
|
|
|
sis.Disks = append(sis.Disks, k)
|
|
|
|
sis.DiskAttributes[k] = v
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get method
|
2015-07-05 13:19:23 -04:00
|
|
|
func (s *DiskInfoService) Get(r *http.Request, args *Args, reply *DiskInfoReply) error {
|
2015-07-05 03:54:57 -04:00
|
|
|
return setDiskInfoReply(reply)
|
|
|
|
}
|