本文整理汇总了Golang中github.com/juju/juju/juju/paths.DataDir函数的典型用法代码示例。如果您正苦于以下问题:Golang DataDir函数的具体用法?Golang DataDir怎么用?Golang DataDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DataDir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWindowsCloudInit
func (*cloudinitSuite) TestWindowsCloudInit(c *gc.C) {
for i, test := range windowsCloudinitTests {
c.Logf("test %d", i)
dataDir, err := paths.DataDir(test.cfg.Series)
c.Assert(err, gc.IsNil)
logDir, err := paths.LogDir(test.cfg.Series)
c.Assert(err, gc.IsNil)
test.cfg.DataDir = dataDir
test.cfg.LogDir = path.Join(logDir, "juju")
ci := coreCloudinit.New()
udata, err := cloudinit.NewUserdataConfig(&test.cfg, ci)
c.Assert(err, gc.IsNil)
err = udata.Configure()
c.Assert(err, gc.IsNil)
c.Check(ci, gc.NotNil)
data, err := udata.Render()
c.Assert(err, gc.IsNil)
stringData := strings.Replace(string(data), "\r\n", "\n", -1)
stringData = strings.Replace(stringData, "\t", " ", -1)
stringData = strings.TrimSpace(stringData)
compareString := strings.Replace(string(test.expectScripts), "\r\n", "\n", -1)
compareString = strings.Replace(compareString, "\t", " ", -1)
compareString = strings.TrimSpace(compareString)
c.Assert(stringData, gc.Equals, compareString)
}
}
示例2: TestMissingAttributes
func (s *format_1_16Suite) TestMissingAttributes(c *gc.C) {
logDir, err := paths.LogDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir, err := paths.DataDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir = filepath.FromSlash(realDataDir)
logPath := filepath.Join(logDir, "juju")
logPath = filepath.FromSlash(logPath)
dataDir := c.MkDir()
formatPath := filepath.Join(dataDir, legacyFormatFilename)
err = utils.AtomicWriteFile(formatPath, []byte(legacyFormatFileContents), 0600)
c.Assert(err, jc.ErrorIsNil)
configPath := filepath.Join(dataDir, agentConfigFilename)
err = utils.AtomicWriteFile(configPath, []byte(configDataWithoutNewAttributes), 0600)
c.Assert(err, jc.ErrorIsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(readConfig.UpgradedToVersion(), gc.Equals, version.MustParse("1.16.0"))
configLogDir := filepath.FromSlash(readConfig.LogDir())
configDataDir := filepath.FromSlash(readConfig.DataDir())
c.Assert(configLogDir, gc.Equals, logPath)
c.Assert(configDataDir, gc.Equals, realDataDir)
// Test data doesn't include a StateServerKey so StateServingInfo
// should *not* be available
_, available := readConfig.StateServingInfo()
c.Assert(available, jc.IsFalse)
}
示例3: TestMissingAttributes
func (s *format_1_18Suite) TestMissingAttributes(c *gc.C) {
logDir, err := paths.LogDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir, err := paths.DataDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir = filepath.FromSlash(realDataDir)
logPath := filepath.Join(logDir, "juju")
logPath = filepath.FromSlash(logPath)
dataDir := c.MkDir()
configPath := filepath.Join(dataDir, agentConfigFilename)
err = utils.AtomicWriteFile(configPath, []byte(configData1_18WithoutUpgradedToVersion), 0600)
c.Assert(err, jc.ErrorIsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(readConfig.UpgradedToVersion(), gc.Equals, version.MustParse("1.16.0"))
configLogDir := filepath.FromSlash(readConfig.LogDir())
configDataDir := filepath.FromSlash(readConfig.DataDir())
c.Assert(configLogDir, gc.Equals, logPath)
c.Assert(configDataDir, gc.Equals, realDataDir)
c.Assert(readConfig.PreferIPv6(), jc.IsFalse)
// The api info doesn't have the environment tag set.
apiInfo, ok := readConfig.APIInfo()
c.Assert(ok, jc.IsTrue)
c.Assert(apiInfo.EnvironTag.Id(), gc.Equals, "")
}
示例4: SetUpTest
func (s *initSystemSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
dataDir, err := paths.DataDir("vivid")
c.Assert(err, jc.ErrorIsNil)
s.dataDir = dataDir
// Patch things out.
s.ch = systemd.PatchNewChan(s)
s.stub = &testing.Stub{}
s.conn = systemd.PatchNewConn(s, s.stub)
s.fops = systemd.PatchFileOps(s, s.stub)
s.exec = systemd.PatchExec(s, s.stub)
// Set up the service.
tagStr := "machine-0"
tag, err := names.ParseTag(tagStr)
c.Assert(err, jc.ErrorIsNil)
s.tag = tag
s.name = "jujud-" + tagStr
s.conf = common.Conf{
Desc: "juju agent for " + tagStr,
ExecStart: jujud + " " + tagStr,
}
s.service = s.newService(c)
// Reset any incidental calls.
s.stub.ResetCalls()
}
示例5: newService
func newService(name string, conf common.Conf, initSystem, series string) (Service, error) {
switch initSystem {
case InitSystemWindows:
svc, err := windows.NewService(name, conf)
if err != nil {
return nil, errors.Annotatef(err, "failed to wrap service %q", name)
}
return svc, nil
case InitSystemUpstart:
return upstart.NewService(name, conf), nil
case InitSystemSystemd:
dataDir, err := paths.DataDir(series)
if err != nil {
return nil, errors.Annotatef(err, "failed to find juju data dir for service %q", name)
}
svc, err := systemd.NewService(name, conf, dataDir)
if err != nil {
return nil, errors.Annotatef(err, "failed to wrap service %q", name)
}
return svc, nil
default:
return nil, errors.NotFoundf("init system %q", initSystem)
}
}
示例6: TestWindowsUserdataEncoding
func (s *CloudInitSuite) TestWindowsUserdataEncoding(c *gc.C) {
series := "win8"
metricsSpoolDir := must(paths.MetricsSpoolDir("win8"))
toolsList := tools.List{
&tools.Tools{
URL: "http://foo.com/tools/released/juju1.2.3-win8-amd64.tgz",
Version: version.MustParseBinary("1.2.3-win8-amd64"),
Size: 10,
SHA256: "1234",
},
}
dataDir, err := paths.DataDir(series)
c.Assert(err, jc.ErrorIsNil)
logDir, err := paths.LogDir(series)
c.Assert(err, jc.ErrorIsNil)
cfg := instancecfg.InstanceConfig{
ControllerTag: testing.ControllerTag,
MachineId: "10",
AgentEnvironment: map[string]string{agent.ProviderType: "dummy"},
Series: series,
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
MachineNonce: "FAKE_NONCE",
APIInfo: &api.Info{
Addrs: []string{"state-addr.testing.invalid:54321"},
Password: "bletch",
CACert: "CA CERT\n" + testing.CACert,
Tag: names.NewMachineTag("10"),
ModelTag: testing.ModelTag,
},
MachineAgentServiceName: "jujud-machine-10",
DataDir: dataDir,
LogDir: path.Join(logDir, "juju"),
MetricsSpoolDir: metricsSpoolDir,
CloudInitOutputLog: path.Join(logDir, "cloud-init-output.log"),
}
err = cfg.SetTools(toolsList)
c.Assert(err, jc.ErrorIsNil)
ci, err := cloudinit.New("win8")
c.Assert(err, jc.ErrorIsNil)
udata, err := cloudconfig.NewUserdataConfig(&cfg, ci)
c.Assert(err, jc.ErrorIsNil)
err = udata.Configure()
c.Assert(err, jc.ErrorIsNil)
data, err := ci.RenderYAML()
c.Assert(err, jc.ErrorIsNil)
cicompose, err := cloudinit.New("win8")
c.Assert(err, jc.ErrorIsNil)
base64Data := base64.StdEncoding.EncodeToString(utils.Gzip(data))
got := []byte(fmt.Sprintf(cloudconfig.UserDataScript, base64Data))
expected, err := providerinit.ComposeUserData(&cfg, cicompose, openstack.OpenstackRenderer{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(got), gc.Equals, string(expected))
}
示例7: NewInstanceConfig
// NewInstanceConfig sets up a basic machine configuration, for a
// non-bootstrap node. You'll still need to supply more information,
// but this takes care of the fixed entries and the ones that are
// always needed.
func NewInstanceConfig(
machineID,
machineNonce,
imageStream,
series,
publicImageSigningKey string,
secureServerConnections bool,
networks []string,
mongoInfo *mongo.MongoInfo,
apiInfo *api.Info,
) (*InstanceConfig, error) {
dataDir, err := paths.DataDir(series)
if err != nil {
return nil, err
}
logDir, err := paths.LogDir(series)
if err != nil {
return nil, err
}
metricsSpoolDir, err := paths.MetricsSpoolDir(series)
if err != nil {
return nil, err
}
cloudInitOutputLog := path.Join(logDir, "cloud-init-output.log")
icfg := &InstanceConfig{
// Fixed entries.
DataDir: dataDir,
LogDir: path.Join(logDir, "juju"),
MetricsSpoolDir: metricsSpoolDir,
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
CloudInitOutputLog: cloudInitOutputLog,
MachineAgentServiceName: "jujud-" + names.NewMachineTag(machineID).String(),
Series: series,
Tags: map[string]string{},
// Parameter entries.
MachineId: machineID,
MachineNonce: machineNonce,
Networks: networks,
MongoInfo: mongoInfo,
APIInfo: apiInfo,
ImageStream: imageStream,
PublicImageSigningKey: publicImageSigningKey,
AgentEnvironment: map[string]string{
agent.AllowsSecureConnection: strconv.FormatBool(secureServerConnections),
},
}
return icfg, nil
}
示例8: TestMachineInfoCloudinitRunCmd
func (*utilSuite) TestMachineInfoCloudinitRunCmd(c *gc.C) {
hostname := "hostname"
info := machineInfo{hostname}
filename := "/var/lib/juju/MAASmachine.txt"
dataDir, err := paths.DataDir("quantal")
c.Assert(err, jc.ErrorIsNil)
cloudcfg, err := cloudinit.New("quantal")
c.Assert(err, jc.ErrorIsNil)
script, err := info.cloudinitRunCmd(cloudcfg)
c.Assert(err, jc.ErrorIsNil)
yaml, err := goyaml.Marshal(info)
c.Assert(err, jc.ErrorIsNil)
expected := fmt.Sprintf("mkdir -p '%s'\ncat > '%s' << 'EOF'\n'%s'\nEOF\nchmod 0755 '%s'", dataDir, filename, yaml, filename)
c.Check(script, gc.Equals, expected)
}
示例9: CheckAgentCommand
// CheckAgentCommand is a utility function for verifying that common agent
// options are handled by a Command; it returns an instance of that
// command pre-parsed, with any mandatory flags added.
func CheckAgentCommand(c *gc.C, create acCreator, args []string) cmd.Command {
com, conf := create()
err := coretesting.InitCommand(com, args)
dataDir, err := paths.DataDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
c.Assert(conf.DataDir(), gc.Equals, dataDir)
badArgs := append(args, "--data-dir", "")
com, _ = create()
err = coretesting.InitCommand(com, badArgs)
c.Assert(err, gc.ErrorMatches, "--data-dir option must be set")
args = append(args, "--data-dir", "jd")
com, conf = create()
c.Assert(coretesting.InitCommand(com, args), gc.IsNil)
c.Assert(conf.DataDir(), gc.Equals, "jd")
return com
}
示例10: cloudinitRunCmd
// cloudinitRunCmd returns the shell command that, when run, will create the
// "machine info" file containing the hostname of a machine.
// That command is destined to be used by cloudinit.
func (info *machineInfo) cloudinitRunCmd(cloudcfg cloudinit.CloudConfig) (string, error) {
dataDir, err := paths.DataDir(cloudcfg.GetSeries())
if err != nil {
return "", errors.Trace(err)
}
yaml, err := goyaml.Marshal(info)
if err != nil {
return "", errors.Trace(err)
}
renderer := cloudcfg.ShellRenderer()
fileName := renderer.Join(renderer.FromSlash(dataDir), "MAASmachine.txt")
script := renderer.MkdirAll(dataDir)
contents := renderer.Quote(string(yaml))
script = append(script, renderer.WriteFile(fileName, []byte(contents))...)
script = append(script, renderer.Chmod(fileName, 0755)...)
return strings.Join(script, "\n"), nil
}
示例11: cloudinitRunCmd
// cloudinitRunCmd returns the shell command that, when run, will create the
// "machine info" file containing the hostname of a machine.
// That command is destined to be used by cloudinit.
func (info *machineInfo) cloudinitRunCmd(series string) (string, error) {
dataDir, err := paths.DataDir(series)
if err != nil {
return "", err
}
renderer, err := cloudinit.NewRenderer(series)
if err != nil {
return "", err
}
yaml, err := goyaml.Marshal(info)
if err != nil {
return "", err
}
fileName := renderer.PathJoin(renderer.FromSlash(dataDir), "MAASmachine.txt")
script := renderer.Mkdir(dataDir)
contents := utils.ShQuote(string(yaml))
script = append(script, renderer.WriteFile(fileName, contents, 0755)...)
return strings.Join(script, "\n"), nil
}
示例12: NewInstanceConfig
// NewInstanceConfig sets up a basic machine configuration, for a
// non-bootstrap node. You'll still need to supply more information,
// but this takes care of the fixed entries and the ones that are
// always needed.
func NewInstanceConfig(
controllerTag names.ControllerTag,
machineID,
machineNonce,
imageStream,
series string,
apiInfo *api.Info,
) (*InstanceConfig, error) {
dataDir, err := paths.DataDir(series)
if err != nil {
return nil, err
}
logDir, err := paths.LogDir(series)
if err != nil {
return nil, err
}
metricsSpoolDir, err := paths.MetricsSpoolDir(series)
if err != nil {
return nil, err
}
cloudInitOutputLog := path.Join(logDir, "cloud-init-output.log")
icfg := &InstanceConfig{
// Fixed entries.
DataDir: dataDir,
LogDir: path.Join(logDir, "juju"),
MetricsSpoolDir: metricsSpoolDir,
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
CloudInitOutputLog: cloudInitOutputLog,
MachineAgentServiceName: "jujud-" + names.NewMachineTag(machineID).String(),
Series: series,
Tags: map[string]string{},
// Parameter entries.
ControllerTag: controllerTag,
MachineId: machineID,
MachineNonce: machineNonce,
APIInfo: apiInfo,
ImageStream: imageStream,
}
return icfg, nil
}
示例13: NewMachineConfig
// NewMachineConfig sets up a basic machine configuration, for a
// non-bootstrap node. You'll still need to supply more information,
// but this takes care of the fixed entries and the ones that are
// always needed.
func NewMachineConfig(
machineID,
machineNonce,
imageStream,
series string,
networks []string,
mongoInfo *mongo.MongoInfo,
apiInfo *api.Info,
) (*cloudinit.MachineConfig, error) {
dataDir, err := paths.DataDir(series)
if err != nil {
return nil, err
}
logDir, err := paths.LogDir(series)
if err != nil {
return nil, err
}
cloudInitOutputLog := path.Join(logDir, "cloud-init-output.log")
mcfg := &cloudinit.MachineConfig{
// Fixed entries.
DataDir: dataDir,
LogDir: path.Join(logDir, "juju"),
Jobs: []params.MachineJob{params.JobHostUnits},
CloudInitOutputLog: cloudInitOutputLog,
MachineAgentServiceName: "jujud-" + names.NewMachineTag(machineID).String(),
Series: series,
// Parameter entries.
MachineId: machineID,
MachineNonce: machineNonce,
Networks: networks,
MongoInfo: mongoInfo,
APIInfo: apiInfo,
ImageStream: imageStream,
}
return mcfg, nil
}
示例14: Restore
// Restore handles either returning or creating a controller to a backed up status:
// * extracts the content of the given backup file and:
// * runs mongorestore with the backed up mongo dump
// * updates and writes configuration files
// * updates existing db entries to make sure they hold no references to
// old instances
// * updates config in all agents.
func (b *backups) Restore(backupId string, dbInfo *DBInfo, args RestoreArgs) (names.Tag, error) {
meta, backupReader, err := b.Get(backupId)
if err != nil {
return nil, errors.Annotatef(err, "could not fetch backup %q", backupId)
}
defer backupReader.Close()
workspace, err := NewArchiveWorkspaceReader(backupReader)
if err != nil {
return nil, errors.Annotate(err, "cannot unpack backup file")
}
defer workspace.Close()
// This might actually work, but we don't have a guarantee so we don't allow it.
if meta.Origin.Series != args.NewInstSeries {
return nil, errors.Errorf("cannot restore a backup made in a machine with series %q into a machine with series %q, %#v", meta.Origin.Series, args.NewInstSeries, meta)
}
// TODO(perrito666) Create a compatibility table of sorts.
vers := meta.Origin.Version
if vers.Major != 2 {
return nil, errors.Errorf("Juju version %v cannot restore backups made using Juju version %v", version.Current.Minor, vers)
}
backupMachine := names.NewMachineTag(meta.Origin.Machine)
// The path for the config file might change if the tag changed
// and also the rest of the path, so we assume as little as possible.
oldDatadir, err := paths.DataDir(args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot determine DataDir for the restored machine")
}
var oldAgentConfig agent.ConfigSetterWriter
oldAgentConfigFile := agent.ConfigPath(oldDatadir, args.NewInstTag)
if oldAgentConfig, err = agent.ReadConfig(oldAgentConfigFile); err != nil {
return nil, errors.Annotate(err, "cannot load old agent config from disk")
}
logger.Infof("stopping juju-db")
if err = mongo.StopService(); err != nil {
return nil, errors.Annotate(err, "failed to stop mongo")
}
// delete all the files to be replaced
if err := PrepareMachineForRestore(oldAgentConfig.MongoVersion()); err != nil {
return nil, errors.Annotate(err, "cannot delete existing files")
}
logger.Infof("deleted old files to place new")
if err := workspace.UnpackFilesBundle(filesystemRoot()); err != nil {
return nil, errors.Annotate(err, "cannot obtain system files from backup")
}
logger.Infof("placed new restore files")
var agentConfig agent.ConfigSetterWriter
// The path for the config file might change if the tag changed
// and also the rest of the path, so we assume as little as possible.
datadir, err := paths.DataDir(args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot determine DataDir for the restored machine")
}
agentConfigFile := agent.ConfigPath(datadir, backupMachine)
if agentConfig, err = agent.ReadConfig(agentConfigFile); err != nil {
return nil, errors.Annotate(err, "cannot load agent config from disk")
}
ssi, ok := agentConfig.StateServingInfo()
if !ok {
return nil, errors.Errorf("cannot determine state serving info")
}
APIHostPorts := network.NewHostPorts(ssi.APIPort, args.PrivateAddress, args.PublicAddress)
agentConfig.SetAPIHostPorts([][]network.HostPort{APIHostPorts})
if err := agentConfig.Write(); err != nil {
return nil, errors.Annotate(err, "cannot write new agent configuration")
}
logger.Infof("wrote new agent config for restore")
if backupMachine.Id() != "0" {
logger.Infof("extra work needed backup belongs to %q machine", backupMachine.String())
serviceName := "jujud-" + agentConfig.Tag().String()
aInfo := service.NewMachineAgentInfo(
agentConfig.Tag().Id(),
dataDir,
paths.MustSucceed(paths.LogDir(args.NewInstSeries)),
)
// TODO(perrito666) renderer should have a RendererForSeries, for the moment
// restore only works on linuxes.
renderer, _ := shell.NewRenderer("bash")
serviceAgentConf := service.AgentConf(aInfo, renderer)
svc, err := service.NewService(serviceName, serviceAgentConf, args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot generate service for the restored agent.")
//.........这里部分代码省略.........
示例15: must
type customDataSuite struct {
testing.BaseSuite
}
var _ = gc.Suite(&customDataSuite{})
func must(s string, err error) string {
if err != nil {
panic(err)
}
return s
}
var logDir = must(paths.LogDir("precise"))
var metricsSpoolDir = must(paths.MetricsSpoolDir("precise"))
var dataDir = must(paths.DataDir("precise"))
var cloudInitOutputLog = path.Join(logDir, "cloud-init-output.log")
// makeInstanceConfig produces a valid cloudinit machine config.
func makeInstanceConfig(c *gc.C) *instancecfg.InstanceConfig {
machineId := "0"
machineTag := names.NewMachineTag(machineId)
return &instancecfg.InstanceConfig{
MachineId: machineId,
MachineNonce: "gxshasqlnng",
DataDir: dataDir,
LogDir: logDir,
MetricsSpoolDir: metricsSpoolDir,
Jobs: []multiwatcher.MachineJob{
multiwatcher.JobManageEnviron,
multiwatcher.JobHostUnits,