本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system.NewOsFileSystem函数的典型用法代码示例。如果您正苦于以下问题:Golang NewOsFileSystem函数的具体用法?Golang NewOsFileSystem怎么用?Golang NewOsFileSystem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewOsFileSystem函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runAgent
func runAgent(logger logger.Logger) chan error {
errCh := make(chan error, 1)
go func() {
defer logger.HandlePanic("Main")
logger.Debug(mainLogTag, "Starting agent")
fs := boshsys.NewOsFileSystem(logger)
app := boshapp.New(logger, fs)
err := app.Setup(os.Args)
if err != nil {
logger.Error(mainLogTag, "App setup %s", err.Error())
errCh <- err
return
}
err = app.Run()
if err != nil {
logger.Error(mainLogTag, "App run %s", err.Error())
errCh <- err
return
}
}()
return errCh
}
示例2: basicDeps
func basicDeps() (boshlog.Logger, boshsys.FileSystem, boshsys.CmdRunner) {
logger := boshlog.NewWriterLogger(boshlog.LevelDebug, os.Stderr, os.Stderr)
fs := boshsys.NewOsFileSystem(logger)
cmdRunner := boshsys.NewExecCmdRunner(logger)
return logger, fs, cmdRunner
}
示例3: basicDeps
func basicDeps() (boshlog.Logger, boshsys.FileSystem, boshsys.CmdRunner, boshuuid.Generator) {
logger := boshlog.NewWriterLogger(boshlog.LevelDebug, os.Stderr, os.Stderr)
fs := boshsys.NewOsFileSystem(logger)
runner := boshsys.NewExecCmdRunner(logger)
uuidGen := boshuuid.NewGenerator()
return logger, fs, runner, uuidGen
}
示例4: newSignalableFileLogger
func newSignalableFileLogger(logPath string, level boshlog.LogLevel) boshlog.Logger {
// Log file logger errors to the STDERR logger
logger := boshlog.NewLogger(boshlog.LevelError)
fileSystem := boshsys.NewOsFileSystem(logger)
// log file will be closed by process exit
// log file readable by all
logfileLogger, _, err := boshlogfile.New(level, logPath, boshlogfile.DefaultLogFileMode, fileSystem)
if err != nil {
logger := boshlog.NewLogger(boshlog.LevelError)
ui := biui.NewConsoleUI(logger)
fail(err, ui, logger, nil)
}
return newSignalableLogger(logfileLogger)
}
示例5: main
func main() {
logger := newSignalableLogger(boshlog.NewLogger(boshlog.LevelDebug))
defer logger.HandlePanic("Main")
logger.Debug(mainLogTag, "Starting agent")
fs := boshsys.NewOsFileSystem(logger)
app := boshapp.New(logger, fs)
err := app.Setup(os.Args)
if err != nil {
logger.Error(mainLogTag, "App setup %s", err.Error())
os.Exit(1)
}
err = app.Run()
if err != nil {
logger.Error(mainLogTag, "App run %s", err.Error())
os.Exit(1)
}
}
示例6:
. "github.com/onsi/gomega"
)
var _ = Describe("Blob Manager", func() {
var (
fs boshsys.FileSystem
logger boshlog.Logger
basePath string
blobPath string
blobId string
toWrite io.Reader
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
fs = boshsys.NewOsFileSystem(logger)
blobId = "105d33ae-655c-493d-bf9f-1df5cf3ca847"
basePath = os.TempDir()
blobPath = filepath.Join(basePath, blobId)
toWrite = bytes.NewReader([]byte("new data"))
})
readFile := func(fileIO boshsys.File) []byte {
fileStat, _ := fileIO.Stat()
fileBytes := make([]byte, fileStat.Size())
fileIO.Read(fileBytes)
return fileBytes
}
It("fetches", func() {
blobManager := NewBlobManager(fs, basePath)
示例7: init
func init() {
Describe("App", func() {
var (
baseDir string
agentConfPath string
agentConfJSON string
app App
)
BeforeEach(func() {
var err error
baseDir, err = ioutil.TempDir("", "go-agent-test")
Expect(err).ToNot(HaveOccurred())
err = os.Mkdir(filepath.Join(baseDir, "bosh"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
})
BeforeEach(func() {
agentConfPath = filepath.Join(baseDir, "bosh", "agent.json")
agentConfJSON = `{
"Infrastructure": { "Settings": { "Sources": [{ "Type": "CDROM", "FileName": "/fake-file-name" }] } }
}`
settingsPath := filepath.Join(baseDir, "bosh", "settings.json")
settingsJSON := `{
"agent_id": "my-agent-id",
"blobstore": {
"options": {
"bucket_name": "george",
"encryption_key": "optional encryption key",
"access_key_id": "optional access key id",
"secret_access_key": "optional secret access key"
},
"provider": "dummy"
},
"disks": {
"ephemeral": "/dev/sdb",
"persistent": {
"vol-xxxxxx": "/dev/sdf"
},
"system": "/dev/sda1"
},
"env": {
"bosh": {
"password": "some encrypted password"
}
},
"networks": {
"netA": {
"default": ["dns", "gateway"],
"ip": "ww.ww.ww.ww",
"dns": [
"xx.xx.xx.xx",
"yy.yy.yy.yy"
]
},
"netB": {
"dns": [
"zz.zz.zz.zz"
]
}
},
"Mbus": "https://vcap:[email protected]:6868",
"ntp": [
"0.north-america.pool.ntp.org",
"1.north-america.pool.ntp.org"
],
"vm": {
"name": "vm-abc-def"
}
}`
err := ioutil.WriteFile(settingsPath, []byte(settingsJSON), 0640)
Expect(err).ToNot(HaveOccurred())
})
JustBeforeEach(func() {
err := ioutil.WriteFile(agentConfPath, []byte(agentConfJSON), 0640)
Expect(err).ToNot(HaveOccurred())
logger := boshlog.NewLogger(boshlog.LevelNone)
fakefs := boshsys.NewOsFileSystem(logger)
app = New(logger, fakefs)
})
AfterEach(func() {
os.RemoveAll(baseDir)
})
It("Sets up device path resolver on platform specific to infrastructure", func() {
err := app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(err).ToNot(HaveOccurred())
Expect(app.GetPlatform().GetDevicePathResolver()).To(Equal(devicepathresolver.NewIdentityDevicePathResolver()))
})
//.........这里部分代码省略.........
示例8: NewDnsUpdater
func NewDnsUpdater(cfg config.Config, log logger.Logger) *DnsUpdater {
fs := system.NewOsFileSystem(log)
cmdRunner := system.NewExecCmdRunner(log)
return &DnsUpdater{cfg: cfg, logger: log, fs: fs, cmdRunner: cmdRunner}
}
示例9: loadConfig
func (app *app) loadConfig(path string) (Config, error) {
// Use one off copy of file system to read configuration file
fs := boshsys.NewOsFileSystem(app.logger)
return LoadConfigFromPath(fs, path)
}
示例10:
"github.com/cloudfoundry/bosh-init/installation"
"github.com/cloudfoundry/bosh-utils/logger"
"github.com/cloudfoundry/bosh-utils/system"
"github.com/cloudfoundry/bosh-utils/system/fakes"
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("Uninstaller", func() {
Describe("Uninstall", func() {
It("deletes the installation target directory", func() {
logBuffer := gbytes.NewBuffer()
goLogger := log.New(logBuffer, "", log.LstdFlags)
boshlogger := logger.New(logger.LevelInfo, goLogger, goLogger)
fs := system.NewOsFileSystem(boshlogger)
installationPath, err := fs.TempDir("some-installation-dir")
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFileString(filepath.Join(installationPath, "some-installation-artifact"), "something-blah")
Expect(err).ToNot(HaveOccurred())
installationTarget := installation.NewTarget(installationPath)
uninstaller := installation.NewUninstaller(fs, boshlogger)
Expect(fs.FileExists(installationPath)).To(BeTrue())
err = uninstaller.Uninstall(installationTarget)
Expect(err).ToNot(HaveOccurred())
示例11: main
func main() {
if len(os.Args) < 2 || len(os.Args) > 3 {
println("Usage: blt path/to/config.json [path/to/state.json]")
os.Exit(1)
}
logger := boshlog.NewLogger(boshlog.LevelDebug)
fs := boshsys.NewOsFileSystem(logger)
cmdRunner := boshsys.NewExecCmdRunner(logger)
config := bltconfig.NewConfig(fs)
err := config.Load(os.Args[1])
if err != nil {
panic(err)
}
assetsProvider := bltassets.NewProvider(config.AssetsPath)
logger.Debug("main", "Setting up environment")
environmentProvider := bltenv.NewProvider(config, fs, cmdRunner, assetsProvider)
environment := environmentProvider.Get()
err = environment.Setup()
if err != nil {
panic(err)
}
defer environment.Shutdown()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
environment.Shutdown()
os.Exit(1)
}()
logger.Debug("main", "Starting deploy")
cliRunnerFactory := bltclirunner.NewFactory(config.CliCmd, cmdRunner, fs)
directorInfo, err := bltaction.NewDirectorInfo(environment.DirectorURL(), cliRunnerFactory)
if err != nil {
panic(err)
}
actionFactory := bltaction.NewFactory(directorInfo, fs, assetsProvider)
prepareActionFlow := bltflow.NewFlow(1, []bltflow.ActionInfo{{Name: "prepare"}}, actionFactory, cliRunnerFactory)
err = prepareActionFlow.Run(false)
if err != nil {
panic(err)
}
if !config.UsingLegacyManifest {
uploadCloudConfigActionFlow := bltflow.NewFlow(2, []bltflow.ActionInfo{{Name: "upload_cloud_config"}}, actionFactory, cliRunnerFactory)
err := uploadCloudConfigActionFlow.Run(false)
if err != nil {
panic(err)
}
}
randomizer := bltflow.NewRandomizer(actionFactory, cliRunnerFactory, fs, logger)
if len(os.Args) == 3 {
err := randomizer.Configure(os.Args[2])
if err != nil {
panic(err)
}
} else {
err := randomizer.Prepare(config.Flows, config.NumberOfDeployments)
if err != nil {
panic(err)
}
}
doneCh := make(chan error)
for i := 0; i < config.NumberOfDeployments; i++ {
go func(i int) {
doneCh <- randomizer.RunFlow(i, config.UsingLegacyManifest)
}(i)
}
for i := 0; i < config.NumberOfDeployments; i++ {
err := <-doneCh
if err != nil {
panic(err)
}
}
println("Done!")
}
示例12: main
func main() {
if len(os.Args) < 2 || len(os.Args) > 3 {
println("Usage: bft path/to/config.json seed")
os.Exit(1)
}
logger := boshlog.NewLogger(boshlog.LevelDebug)
fs := boshsys.NewOsFileSystem(logger)
cmdRunner := boshsys.NewExecCmdRunner(logger)
testConfig := bftconfig.NewConfig(fs)
err := testConfig.Load(os.Args[1])
if err != nil {
panic(err)
}
envConfig := bltconfig.NewConfig(fs)
err = envConfig.Load(os.Args[1])
if err != nil {
panic(err)
}
assetsProvider := bltassets.NewProvider(envConfig.AssetsPath)
logger.Debug("main", "Setting up environment")
environmentProvider := bltenv.NewProvider(envConfig, fs, cmdRunner, assetsProvider)
environment := environmentProvider.Get()
if !testConfig.GenerateManifestOnly {
err = environment.Setup()
if err != nil {
panic(err)
}
defer environment.Shutdown()
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
environment.Shutdown()
os.Exit(1)
}()
cliRunnerFactory := bltclirunner.NewFactory(envConfig.CliCmd, cmdRunner, fs)
var directorInfo bltaction.DirectorInfo
if testConfig.GenerateManifestOnly {
directorInfo = bltaction.DirectorInfo{
UUID: "blah",
URL: "xxx",
}
} else {
directorInfo, err = bltaction.NewDirectorInfo(environment.DirectorURL(), cliRunnerFactory)
}
if err != nil {
panic(err)
}
cliRunner := cliRunnerFactory.Create()
cliRunner.Configure()
defer cliRunner.Clean()
if !testConfig.GenerateManifestOnly {
logger.Debug("main", "Preparing to deploy")
preparer := bftdeployment.NewPreparer(directorInfo, cliRunner, fs, assetsProvider)
err = preparer.Prepare()
if err != nil {
panic(err)
}
}
logger.Debug("main", "Starting deploy")
renderer := bftdeployment.NewRenderer(fs)
var seed int64
if len(os.Args) == 3 {
seed, _ = strconv.ParseInt(os.Args[2], 10, 64)
} else {
seed = time.Now().Unix()
}
logger.Info("main", "Seeding with %d", seed)
rand.Seed(seed)
nameGenerator := bftnamegen.NewNameGenerator()
decider := bftdecider.NewRandomDecider()
ipPoolProvider := bftnetwork.NewIpPoolProvider()
networksAssigner := bftnetwork.NewAssigner(testConfig.Parameters.Networks, nameGenerator, ipPoolProvider, decider, logger)
parameterProvider := bftparam.NewParameterProvider(testConfig.Parameters, nameGenerator, decider, networksAssigner, logger)
inputGenerator := bftdeployment.NewInputGenerator(testConfig.Parameters, parameterProvider, testConfig.NumberOfConsequentDeploys, nameGenerator, decider, logger)
analyzer := bftanalyzer.NewAnalyzer(logger)
deployer := bftdeployment.NewDeployer(
cliRunner,
directorInfo,
renderer,
//.........这里部分代码省略.........