代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。