1 Star 0 Fork 0

liucxer/ceph-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ceph_cluster.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
liu.changxi@datatom.com 提交于 2021-11-03 11:08 . init
package ceph_cluster
import (
"errors"
"gitee.com/liucxer/ceph-tools/pkg/ceph_osd"
"gitee.com/liucxer/ceph-tools/pkg/host_client"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"time"
)
type CephCluster struct {
IpAddr string `json:"ipAddr"`
Master *host_client.HostClient
Clients []*host_client.HostClient
osds []ceph_osd.CephOsd `json:"osds"`
}
func NewCluster(ipAddr string) (*CephCluster, error) {
var (
err error
)
if ipAddr == "" {
logrus.Errorf("ipAddr is empty")
return nil, errors.New("ipAddresses is empty")
}
var cluster CephCluster
defaultUser := "root"
defaultPassword := "daemon"
//defaultPort := "22"
config := &ssh.ClientConfig{
Timeout: 3 * time.Second,
User: defaultUser,
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
config.Auth = []ssh.AuthMethod{ssh.Password(defaultPassword)}
cluster.Master, err = host_client.NewHostClient(ipAddr)
if err != nil {
return nil, err
}
return &cluster, nil
}
func (cluster *CephCluster) Close() error {
var (
err error
)
for _, client := range cluster.Clients {
err = client.Close()
if err != nil {
return err
}
}
return nil
}
func (cluster *CephCluster) ExecCmd(cmd string) error {
for _, client := range cluster.Clients {
_, err := client.ExecCmd(cmd)
if err != nil {
logrus.Errorf("host :%s, ExecCmd: err:%v", client.IpAddr, err)
return err
}
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liucxer/ceph-tools.git
git@gitee.com:liucxer/ceph-tools.git
liucxer
ceph-tools
ceph-tools
ecdc69b73bfe

搜索帮助