2016-11-05 17:09:05 -07:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2016-11-10 10:59:26 -08:00
|
|
|
package mon
|
2016-08-04 18:01:10 -07:00
|
|
|
|
|
|
|
|
import (
|
2016-08-11 16:57:20 -07:00
|
|
|
"fmt"
|
2016-11-21 14:24:07 -08:00
|
|
|
"io/ioutil"
|
2016-08-24 13:56:46 -07:00
|
|
|
"os"
|
2016-11-10 10:59:26 -08:00
|
|
|
"path"
|
2016-08-24 13:56:46 -07:00
|
|
|
"path/filepath"
|
2016-08-04 18:01:10 -07:00
|
|
|
"strings"
|
2016-08-18 08:21:30 -07:00
|
|
|
|
2016-11-11 17:37:08 -08:00
|
|
|
"github.com/coreos/pkg/capnslog"
|
2016-08-18 17:18:24 -07:00
|
|
|
"github.com/go-ini/ini"
|
2016-10-26 00:38:39 +02:00
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2017-12-04 08:33:19 -08:00
|
|
|
"github.com/rook/rook/pkg/daemon/ceph/client"
|
2016-08-04 18:01:10 -07:00
|
|
|
)
|
|
|
|
|
|
2017-10-17 09:33:37 -07:00
|
|
|
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "cephmon")
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
MonitorKeyringTemplate = `
|
|
|
|
|
[mon.]
|
|
|
|
|
key = %s
|
|
|
|
|
caps mon = "allow *"` + AdminKeyringTemplate
|
|
|
|
|
|
|
|
|
|
AdminKeyringTemplate = `
|
|
|
|
|
[client.admin]
|
|
|
|
|
key = %s
|
|
|
|
|
auid = 0
|
|
|
|
|
caps mds = "allow"
|
|
|
|
|
caps mon = "allow *"
|
|
|
|
|
caps osd = "allow *"
|
|
|
|
|
caps mgr = "allow *"
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
|
2016-08-04 18:01:10 -07:00
|
|
|
type CephMonitorConfig struct {
|
2016-09-23 09:21:35 -07:00
|
|
|
Name string `json:"name"`
|
|
|
|
|
Endpoint string `json:"endpoint"`
|
2016-08-04 18:01:10 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-18 17:18:24 -07:00
|
|
|
type cephConfig struct {
|
2016-11-10 10:59:26 -08:00
|
|
|
*GlobalConfig `ini:"global,omitempty"`
|
2016-08-18 17:18:24 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 10:59:26 -08:00
|
|
|
type GlobalConfig struct {
|
2017-10-25 15:20:50 -07:00
|
|
|
EnableExperimental string `ini:"enable experimental unrecoverable data corrupting features,omitempty"`
|
2016-09-30 17:38:26 -07:00
|
|
|
FSID string `ini:"fsid,omitempty"`
|
|
|
|
|
RunDir string `ini:"run dir,omitempty"`
|
|
|
|
|
MonMembers string `ini:"mon initial members,omitempty"`
|
2017-08-01 22:32:31 -07:00
|
|
|
MonHost string `ini:"mon host"`
|
2016-09-30 17:38:26 -07:00
|
|
|
LogFile string `ini:"log file,omitempty"`
|
|
|
|
|
MonClusterLogFile string `ini:"mon cluster log file,omitempty"`
|
2017-01-30 21:13:05 -08:00
|
|
|
PublicAddr string `ini:"public addr,omitempty"`
|
|
|
|
|
PublicNetwork string `ini:"public network,omitempty"`
|
|
|
|
|
ClusterAddr string `ini:"cluster addr,omitempty"`
|
|
|
|
|
ClusterNetwork string `ini:"cluster network,omitempty"`
|
2016-11-18 16:49:42 -08:00
|
|
|
MonKeyValueDb string `ini:"mon keyvaluedb"`
|
2017-10-12 16:08:08 -07:00
|
|
|
MonAllowPoolDelete bool `ini:"mon_allow_pool_delete"`
|
2017-12-04 15:53:22 -08:00
|
|
|
MaxPgsPerOsd int `ini:"mon_max_pg_per_osd"`
|
2016-09-30 17:38:26 -07:00
|
|
|
DebugLogDefaultLevel int `ini:"debug default"`
|
|
|
|
|
DebugLogRadosLevel int `ini:"debug rados"`
|
2016-10-11 21:05:33 -07:00
|
|
|
DebugLogMonLevel int `ini:"debug mon"`
|
2016-11-11 17:37:08 -08:00
|
|
|
DebugLogOSDLevel int `ini:"debug osd"`
|
2016-10-14 14:41:15 -07:00
|
|
|
DebugLogBluestoreLevel int `ini:"debug bluestore"`
|
2016-11-11 17:37:08 -08:00
|
|
|
DebugLogFilestoreLevel int `ini:"debug filestore"`
|
|
|
|
|
DebugLogJournalLevel int `ini:"debug journal"`
|
|
|
|
|
DebugLogLevelDBLevel int `ini:"debug leveldb"`
|
2016-11-18 16:49:42 -08:00
|
|
|
FileStoreOmapBackend string `ini:"filestore_omap_backend"`
|
2016-09-30 17:38:26 -07:00
|
|
|
OsdPgBits int `ini:"osd pg bits,omitempty"`
|
|
|
|
|
OsdPgpBits int `ini:"osd pgp bits,omitempty"`
|
|
|
|
|
OsdPoolDefaultSize int `ini:"osd pool default size,omitempty"`
|
|
|
|
|
OsdPoolDefaultMinSize int `ini:"osd pool default min size,omitempty"`
|
|
|
|
|
OsdPoolDefaultPgNum int `ini:"osd pool default pg num,omitempty"`
|
|
|
|
|
OsdPoolDefaultPgpNum int `ini:"osd pool default pgp num,omitempty"`
|
|
|
|
|
OsdMaxObjectNameLen int `ini:"osd max object name len,omitempty"`
|
|
|
|
|
OsdMaxObjectNamespaceLen int `ini:"osd max object namespace len,omitempty"`
|
2016-10-14 14:41:15 -07:00
|
|
|
OsdObjectStore string `ini:"osd objectstore"`
|
2017-10-25 15:20:50 -07:00
|
|
|
CrushLocation string `ini:"crush location,omitempty"`
|
2016-09-30 17:38:26 -07:00
|
|
|
RbdDefaultFeatures int `ini:"rbd_default_features,omitempty"`
|
2017-02-09 17:01:59 -08:00
|
|
|
FatalSignalHandlers string `ini:"fatal signal handlers"`
|
2016-08-18 17:18:24 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 10:59:26 -08:00
|
|
|
// get the path of a given monitor's run dir
|
|
|
|
|
func getMonRunDirPath(configDir, monName string) string {
|
|
|
|
|
return path.Join(configDir, monName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get the path of a given monitor's keyring
|
|
|
|
|
func getMonKeyringPath(configDir, monName string) string {
|
|
|
|
|
return filepath.Join(getMonRunDirPath(configDir, monName), "keyring")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get the path of a given monitor's data dir
|
|
|
|
|
func getMonDataDirPath(configDir, monName string) string {
|
2017-08-01 22:31:53 -07:00
|
|
|
return filepath.Join(getMonRunDirPath(configDir, monName), "data")
|
2016-11-10 10:59:26 -08:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 10:41:16 -07:00
|
|
|
// get the path of a given monitor's config file
|
2016-11-10 10:59:26 -08:00
|
|
|
func GetConfFilePath(root, clusterName string) string {
|
2016-08-24 10:41:16 -07:00
|
|
|
return fmt.Sprintf("%s/%s.config", root, clusterName)
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 13:44:54 -07:00
|
|
|
func GenerateAdminConnectionConfig(context *clusterd.Context, cluster *ClusterInfo) error {
|
2017-10-25 15:20:50 -07:00
|
|
|
return GenerateAdminConnectionConfigWithSettings(context, cluster, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GenerateAdminConnectionConfigWithSettings(context *clusterd.Context, cluster *ClusterInfo, settings *cephConfig) error {
|
2017-06-02 13:44:54 -07:00
|
|
|
root := path.Join(context.ConfigDir, cluster.Name)
|
2017-06-13 12:33:08 -07:00
|
|
|
keyring := fmt.Sprintf(AdminKeyringTemplate, cluster.AdminSecret)
|
2017-06-02 13:44:54 -07:00
|
|
|
keyringPath := path.Join(root, fmt.Sprintf("%s.keyring", client.AdminUsername))
|
2017-10-05 10:00:19 -07:00
|
|
|
err := writeKeyring(keyring, keyringPath)
|
2016-12-02 13:52:40 -08:00
|
|
|
if err != nil {
|
2017-06-02 13:44:54 -07:00
|
|
|
return fmt.Errorf("failed to write keyring to %s. %+v", root, err)
|
2016-12-02 13:52:40 -08:00
|
|
|
}
|
|
|
|
|
|
2017-10-25 15:20:50 -07:00
|
|
|
if _, err = GenerateConfigFile(context, cluster, root, client.AdminUsername, keyringPath, settings, nil); err != nil {
|
2017-06-02 13:44:54 -07:00
|
|
|
return fmt.Errorf("failed to write config to %s. %+v", root, err)
|
|
|
|
|
}
|
|
|
|
|
logger.Infof("generated admin config in %s", root)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func writeMonKeyring(context *clusterd.Context, c *ClusterInfo, name string) error {
|
|
|
|
|
keyringPath := getMonKeyringPath(context.ConfigDir, name)
|
2017-09-14 09:40:34 -07:00
|
|
|
keyring := fmt.Sprintf(MonitorKeyringTemplate, c.MonitorSecret, c.AdminSecret)
|
2017-10-05 10:00:19 -07:00
|
|
|
return writeKeyring(keyring, keyringPath)
|
2017-06-02 13:44:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// writes the monitor keyring to disk
|
2017-10-05 10:00:19 -07:00
|
|
|
func writeKeyring(keyring, path string) error {
|
2017-06-02 13:44:54 -07:00
|
|
|
if err := os.MkdirAll(filepath.Dir(path), 0744); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to create keyring directory for %s: %+v", path, err)
|
|
|
|
|
}
|
|
|
|
|
if err := ioutil.WriteFile(path, []byte(keyring), 0644); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to write monitor keyring to %s: %+v", path, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2016-12-02 13:52:40 -08:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 10:41:16 -07:00
|
|
|
// generates and writes the monitor config file to disk
|
2016-11-21 14:24:07 -08:00
|
|
|
func GenerateConnectionConfigFile(context *clusterd.Context, cluster *ClusterInfo, pathRoot, user, keyringPath string) (string, error) {
|
2017-10-25 15:20:50 -07:00
|
|
|
return GenerateConfigFile(context, cluster, pathRoot, user, keyringPath, nil, nil)
|
2016-10-14 14:41:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// generates and writes the monitor config file to disk
|
2016-11-10 10:59:26 -08:00
|
|
|
func GenerateConfigFile(context *clusterd.Context, cluster *ClusterInfo, pathRoot, user, keyringPath string,
|
2017-10-25 15:20:50 -07:00
|
|
|
globalConfig *cephConfig, clientSettings map[string]string) (string, error) {
|
2016-10-26 09:48:25 -07:00
|
|
|
|
2016-08-24 13:56:46 -07:00
|
|
|
if pathRoot == "" {
|
2016-10-14 14:41:15 -07:00
|
|
|
pathRoot = getMonRunDirPath(context.ConfigDir, getFirstMonitor(cluster))
|
2016-08-24 13:56:46 -07:00
|
|
|
}
|
2016-08-24 10:41:16 -07:00
|
|
|
|
2016-08-24 13:56:46 -07:00
|
|
|
// create the config directory
|
2016-11-21 14:24:07 -08:00
|
|
|
if err := os.MkdirAll(pathRoot, 0744); err != nil {
|
2016-11-11 17:37:08 -08:00
|
|
|
logger.Warningf("failed to create config directory at %s: %+v", pathRoot, err)
|
2016-08-24 13:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-25 15:20:50 -07:00
|
|
|
configFile, err := createGlobalConfigFileSection(context, cluster, pathRoot, globalConfig)
|
2016-08-24 10:41:16 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to create global config section, %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 14:41:15 -07:00
|
|
|
if err := addClientConfigFileSection(configFile, getQualifiedUser(user), keyringPath, clientSettings); err != nil {
|
2016-09-23 15:38:16 -07:00
|
|
|
return "", fmt.Errorf("failed to add admin client config section, %+v", err)
|
2016-08-24 10:41:16 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-04 09:01:47 -08:00
|
|
|
// if there's a config file override path given, process the given config file
|
|
|
|
|
if context.ConfigFileOverride != "" {
|
|
|
|
|
err := configFile.Append(context.ConfigFileOverride)
|
|
|
|
|
if err != nil {
|
|
|
|
|
// log the config file override failure as a warning, but proceed without it
|
|
|
|
|
logger.Warningf("failed to add config file override from '%s': %+v", context.ConfigFileOverride, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 10:41:16 -07:00
|
|
|
// write the entire config to disk
|
2016-11-10 10:59:26 -08:00
|
|
|
filePath := GetConfFilePath(pathRoot, cluster.Name)
|
2017-06-13 12:33:08 -07:00
|
|
|
logger.Infof("writing config file %s", filePath)
|
2016-08-24 10:41:16 -07:00
|
|
|
if err := configFile.SaveTo(filePath); err != nil {
|
2016-11-21 14:24:07 -08:00
|
|
|
return "", fmt.Errorf("failed to save config file %s. %+v", filePath, err)
|
2016-08-24 10:41:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filePath, nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 14:24:07 -08:00
|
|
|
// create a keyring for access to the cluster, with the desired set of privileges
|
2017-06-02 13:44:54 -07:00
|
|
|
func CreateKeyring(context *clusterd.Context, clusterName, username, keyringPath string, access []string, generateContents func(string) string) error {
|
2016-11-21 14:24:07 -08:00
|
|
|
_, err := os.Stat(keyringPath)
|
|
|
|
|
if err == nil {
|
|
|
|
|
// no error, the file exists, bail out with no error
|
|
|
|
|
logger.Debugf("keyring already exists at %s", keyringPath)
|
|
|
|
|
return nil
|
|
|
|
|
} else if !os.IsNotExist(err) {
|
|
|
|
|
// some other error besides "does not exist", bail out with error
|
|
|
|
|
return fmt.Errorf("failed to stat %s: %+v", keyringPath, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get-or-create-key for the user account
|
2017-06-02 13:44:54 -07:00
|
|
|
key, err := client.AuthGetOrCreateKey(context, clusterName, username, access)
|
2016-11-21 14:24:07 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to get or create auth key for %s. %+v", username, err)
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 14:03:21 -08:00
|
|
|
return WriteKeyring(keyringPath, key, generateContents)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WriteKeyring(keyringPath, keyring string, generateContents func(string) string) error {
|
2016-11-21 14:24:07 -08:00
|
|
|
// write the keyring to disk
|
|
|
|
|
keyringDir := filepath.Dir(keyringPath)
|
|
|
|
|
if err := os.MkdirAll(keyringDir, 0744); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to create keyring dir at %s: %+v", keyringDir, err)
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 14:03:21 -08:00
|
|
|
contents := generateContents(keyring)
|
2016-11-21 14:24:07 -08:00
|
|
|
logger.Debugf("Writing keyring to: %s", keyringPath)
|
2017-01-05 14:03:21 -08:00
|
|
|
if err := ioutil.WriteFile(keyringPath, []byte(contents), 0644); err != nil {
|
2016-11-21 14:24:07 -08:00
|
|
|
return fmt.Errorf("failed to write keyring to %s: %+v", keyringPath, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 10:41:16 -07:00
|
|
|
// prepends "client." if a user namespace is not already specified
|
|
|
|
|
func getQualifiedUser(user string) string {
|
|
|
|
|
if strings.Index(user, ".") == -1 {
|
|
|
|
|
return fmt.Sprintf("client.%s", user)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return user
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-20 15:20:17 -07:00
|
|
|
func getFirstMonitor(cluster *ClusterInfo) string {
|
2016-08-24 10:41:16 -07:00
|
|
|
// Get the first monitor
|
|
|
|
|
for _, m := range cluster.Monitors {
|
2016-08-24 13:56:46 -07:00
|
|
|
return m.Name
|
2016-08-24 10:41:16 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-24 13:56:46 -07:00
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 15:20:50 -07:00
|
|
|
func CreateDefaultCephConfig(context *clusterd.Context, cluster *ClusterInfo, runDir string) *cephConfig {
|
2016-08-11 16:57:20 -07:00
|
|
|
// extract a list of just the monitor names, which will populate the "mon initial members"
|
|
|
|
|
// global config field
|
2016-08-18 14:06:14 -07:00
|
|
|
monMembers := make([]string, len(cluster.Monitors))
|
2017-08-01 22:32:31 -07:00
|
|
|
monHosts := make([]string, len(cluster.Monitors))
|
2016-08-19 13:46:12 -07:00
|
|
|
i := 0
|
|
|
|
|
for _, monitor := range cluster.Monitors {
|
2016-08-18 14:06:14 -07:00
|
|
|
monMembers[i] = monitor.Name
|
2017-08-01 22:32:31 -07:00
|
|
|
monHosts[i] = monitor.Endpoint
|
2016-08-19 13:46:12 -07:00
|
|
|
i++
|
2016-08-11 16:57:20 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-30 21:13:05 -08:00
|
|
|
cephLogLevel := logLevelToCephLogLevel(context.LogLevel)
|
2016-10-26 09:48:25 -07:00
|
|
|
|
2016-09-30 17:38:26 -07:00
|
|
|
return &cephConfig{
|
2017-09-09 17:33:28 +02:00
|
|
|
GlobalConfig: &GlobalConfig{
|
2016-10-14 14:41:15 -07:00
|
|
|
FSID: cluster.FSID,
|
|
|
|
|
RunDir: runDir,
|
|
|
|
|
MonMembers: strings.Join(monMembers, " "),
|
2017-08-01 22:32:31 -07:00
|
|
|
MonHost: strings.Join(monHosts, ","),
|
2016-10-14 14:41:15 -07:00
|
|
|
LogFile: "/dev/stdout",
|
|
|
|
|
MonClusterLogFile: "/dev/stdout",
|
2017-01-30 21:13:05 -08:00
|
|
|
PublicAddr: context.NetworkInfo.PublicAddrIPv4,
|
|
|
|
|
PublicNetwork: context.NetworkInfo.PublicNetwork,
|
|
|
|
|
ClusterAddr: context.NetworkInfo.ClusterAddrIPv4,
|
|
|
|
|
ClusterNetwork: context.NetworkInfo.ClusterNetwork,
|
2016-11-18 16:49:42 -08:00
|
|
|
MonKeyValueDb: "rocksdb",
|
2017-10-12 16:08:08 -07:00
|
|
|
MonAllowPoolDelete: true,
|
2017-12-04 15:53:22 -08:00
|
|
|
MaxPgsPerOsd: 1000,
|
2016-11-11 17:37:08 -08:00
|
|
|
DebugLogDefaultLevel: cephLogLevel,
|
|
|
|
|
DebugLogRadosLevel: cephLogLevel,
|
|
|
|
|
DebugLogMonLevel: cephLogLevel,
|
|
|
|
|
DebugLogOSDLevel: cephLogLevel,
|
|
|
|
|
DebugLogBluestoreLevel: cephLogLevel,
|
|
|
|
|
DebugLogFilestoreLevel: cephLogLevel,
|
|
|
|
|
DebugLogJournalLevel: cephLogLevel,
|
|
|
|
|
DebugLogLevelDBLevel: cephLogLevel,
|
2016-11-18 16:49:42 -08:00
|
|
|
FileStoreOmapBackend: "rocksdb",
|
2016-10-14 14:41:15 -07:00
|
|
|
OsdPgBits: 11,
|
|
|
|
|
OsdPgpBits: 11,
|
|
|
|
|
OsdPoolDefaultSize: 1,
|
|
|
|
|
OsdPoolDefaultMinSize: 1,
|
|
|
|
|
OsdPoolDefaultPgNum: 100,
|
|
|
|
|
OsdPoolDefaultPgpNum: 100,
|
|
|
|
|
RbdDefaultFeatures: 3,
|
2017-02-09 17:01:59 -08:00
|
|
|
FatalSignalHandlers: "false",
|
2016-08-18 17:18:24 -07:00
|
|
|
},
|
|
|
|
|
}
|
2016-09-30 17:38:26 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-25 15:20:50 -07:00
|
|
|
func createGlobalConfigFileSection(context *clusterd.Context, cluster *ClusterInfo, runDir string, userConfig *cephConfig) (*ini.File, error) {
|
2017-01-30 21:13:05 -08:00
|
|
|
|
2016-09-30 17:38:26 -07:00
|
|
|
var ceph *cephConfig
|
|
|
|
|
|
|
|
|
|
if userConfig != nil {
|
|
|
|
|
// use the user config since it was provided
|
|
|
|
|
ceph = userConfig
|
|
|
|
|
} else {
|
2017-10-25 15:20:50 -07:00
|
|
|
ceph = CreateDefaultCephConfig(context, cluster, runDir)
|
2016-09-30 17:38:26 -07:00
|
|
|
}
|
2016-08-18 17:18:24 -07:00
|
|
|
|
|
|
|
|
configFile := ini.Empty()
|
|
|
|
|
err := ini.ReflectFrom(configFile, ceph)
|
|
|
|
|
return configFile, err
|
2016-08-11 16:57:20 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-14 14:41:15 -07:00
|
|
|
func addClientConfigFileSection(configFile *ini.File, clientName, keyringPath string, settings map[string]string) error {
|
2016-08-18 17:18:24 -07:00
|
|
|
s, err := configFile.NewSection(clientName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := s.NewKey("keyring", keyringPath); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 14:41:15 -07:00
|
|
|
for key, val := range settings {
|
|
|
|
|
if _, err := s.NewKey(key, val); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to add key %s. %v", key, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 17:18:24 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 17:37:08 -08:00
|
|
|
func logLevelToCephLogLevel(logLevel capnslog.LogLevel) int {
|
|
|
|
|
switch logLevel {
|
|
|
|
|
case capnslog.CRITICAL:
|
|
|
|
|
case capnslog.ERROR:
|
|
|
|
|
case capnslog.WARNING:
|
|
|
|
|
return -1
|
|
|
|
|
case capnslog.NOTICE:
|
|
|
|
|
case capnslog.INFO:
|
|
|
|
|
return 0
|
|
|
|
|
case capnslog.DEBUG:
|
|
|
|
|
return 10
|
|
|
|
|
case capnslog.TRACE:
|
|
|
|
|
return 100
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2017-10-17 09:33:37 -07:00
|
|
|
|
|
|
|
|
// writes the monitor backend file to disk
|
|
|
|
|
func writeBackendFile(monDataDir, backend string) error {
|
|
|
|
|
backendPath := filepath.Join(monDataDir, "kv_backend")
|
|
|
|
|
if err := ioutil.WriteFile(backendPath, []byte(backend), 0644); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to write kv_backend to %s: %+v", backendPath, err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func generateMonMap(context *clusterd.Context, cluster *ClusterInfo, folder string) (string, error) {
|
|
|
|
|
path := path.Join(folder, "monmap")
|
|
|
|
|
args := []string{path, "--create", "--clobber", "--fsid", cluster.FSID}
|
|
|
|
|
for _, mon := range cluster.Monitors {
|
|
|
|
|
args = append(args, "--add", mon.Name, mon.Endpoint)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := context.Executor.ExecuteCommand(false, "", "monmaptool", args...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to generate monmap. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path, nil
|
|
|
|
|
}
|