本文整理匯總了Golang中bosh/platform/vitals.NewService函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewService函數的具體用法?Golang NewService怎麽用?Golang NewService使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewService函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewUbuntuPlatform
func NewUbuntuPlatform(
collector boshstats.StatsCollector,
fs boshsys.FileSystem,
cmdRunner boshsys.CmdRunner,
diskManager boshdisk.Manager,
dirProvider boshdirs.DirectoriesProvider,
cdromWaitInterval time.Duration,
arpWaitInterval time.Duration,
diskWaitTimeout time.Duration,
) (platform ubuntu) {
platform.collector = collector
platform.fs = fs
platform.cmdRunner = cmdRunner
platform.dirProvider = dirProvider
platform.partitioner = diskManager.GetPartitioner()
platform.formatter = diskManager.GetFormatter()
platform.mounter = diskManager.GetMounter()
platform.compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
platform.copier = boshcmd.NewCpCopier(cmdRunner, fs)
platform.vitalsService = boshvitals.NewService(collector, dirProvider)
platform.cdromWaitInterval = cdromWaitInterval
platform.arpWaitInterval = arpWaitInterval
platform.diskWaitTimeout = diskWaitTimeout
return
}
示例2: NewProvider
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger, runner)
sigarCollector := boshstats.NewSigarStatsCollector()
linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs)
udev := boshudev.NewConcreteUdevDevice(runner)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs)
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
centosNetManager := boshnet.NewCentosNetManager(fs, runner, 10*time.Second)
ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, 10*time.Second)
centos := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
centosNetManager,
500*time.Millisecond,
logger,
)
ubuntu := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
ubuntuNetManager,
500*time.Millisecond,
logger,
)
p.platforms = map[string]Platform{
"ubuntu": ubuntu,
"centos": centos,
"dummy": NewDummyPlatform(sigarCollector, fs, runner, dirProvider, linuxDiskManager),
}
return
}
示例3: newDummyPlatform
func newDummyPlatform(
collector boshstats.StatsCollector,
fs boshsys.FileSystem,
cmdRunner boshsys.CmdRunner,
dirProvider boshdirs.DirectoriesProvider,
) (platform dummyPlatform) {
platform.collector = collector
platform.fs = fs
platform.cmdRunner = cmdRunner
platform.dirProvider = dirProvider
platform.compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
platform.copier = boshcmd.NewCpCopier(cmdRunner, fs)
platform.vitalsService = boshvitals.NewService(collector, dirProvider)
return
}
示例4: NewDummyPlatform
func NewDummyPlatform(
collector boshstats.StatsCollector,
fs boshsys.FileSystem,
cmdRunner boshsys.CmdRunner,
dirProvider boshdirs.DirectoriesProvider,
logger boshlog.Logger,
) *dummyPlatform {
return &dummyPlatform{
fs: fs,
cmdRunner: cmdRunner,
collector: collector,
compressor: boshcmd.NewTarballCompressor(cmdRunner, fs),
copier: boshcmd.NewCpCopier(cmdRunner, fs, logger),
dirProvider: dirProvider,
vitalsService: boshvitals.NewService(collector, dirProvider),
}
}
示例5: newCentosPlatform
func newCentosPlatform(
collector boshstats.StatsCollector,
fs boshsys.FileSystem,
cmdRunner boshsys.CmdRunner,
diskManager boshdisk.Manager,
dirProvider boshdirs.DirectoriesProvider,
) (platform centos) {
platform.collector = collector
platform.fs = fs
platform.cmdRunner = cmdRunner
platform.dirProvider = dirProvider
platform.partitioner = diskManager.GetPartitioner()
platform.formatter = diskManager.GetFormatter()
platform.mounter = diskManager.GetMounter()
platform.diskWaitTimeout = 3 * time.Minute
platform.compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
platform.copier = boshcmd.NewCpCopier(cmdRunner, fs)
platform.vitalsService = boshvitals.NewService(collector, dirProvider)
return
}
示例6: init
func init() {
const expectedUbuntuDHCPConfig = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
prepend domain-name-servers zz.zz.zz.zz;
prepend domain-name-servers yy.yy.yy.yy;
prepend domain-name-servers xx.xx.xx.xx;
`
Describe("ubuntu", func() {
var (
collector *fakestats.FakeStatsCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager *fakedisk.FakeDiskManager
dirProvider boshdirs.DirectoriesProvider
platform Platform
cdutil *fakecd.FakeCdUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeStatsCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs)
vitalsService = boshvitals.NewService(collector, dirProvider)
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
netManager := boshnet.NewUbuntuNetManager(fs, cmdRunner, 1*time.Millisecond)
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
netManager,
1*time.Millisecond,
logger,
)
})
Describe("SetupDhcp", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns"},
DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy", "zz.zz.zz.zz"},
},
"vip": boshsettings.Network{
Default: []string{},
DNS: []string{"aa.aa.aa.aa"},
},
}
Context("when dhcp was not previously configured", func() {
It("updates dhclient.conf", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp3/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
It("restarts dhclient", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(2))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"pkill", "dhclient3"}))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"/etc/init.d/networking", "restart"}))
})
})
Context("when dhcp was previously configured with different configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp3/dhclient.conf", "fake-other-configuration")
})
//.........這裏部分代碼省略.........
示例7: NewProvider
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider, options ProviderOptions) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger)
linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs, options.Linux.BindMountPersistentDisk)
udev := boshudev.NewConcreteUdevDevice(runner)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs, logger)
sigarCollector := boshstats.NewSigarStatsCollector(&sigar.ConcreteSigar{})
// Kick of stats collection as soon as possible
go sigarCollector.StartCollecting(SigarStatsCollectionInterval, nil)
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
routesSearcher := boshnet.NewCmdRoutesSearcher(runner)
ipResolver := boship.NewIPResolver(boship.NetworkInterfaceToAddrsFunc)
defaultNetworkResolver := boshnet.NewDefaultNetworkResolver(routesSearcher, ipResolver)
arping := bosharp.NewArping(runner, fs, logger, ArpIterations, ArpIterationDelay, ArpInterfaceCheckDelay)
centosNetManager := boshnet.NewCentosNetManager(fs, runner, defaultNetworkResolver, ipResolver, arping, logger)
ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, defaultNetworkResolver, ipResolver, arping, logger)
centos := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
centosNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
ubuntu := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
ubuntuNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
p.platforms = map[string]Platform{
"ubuntu": ubuntu,
"centos": centos,
"dummy": NewDummyPlatform(sigarCollector, fs, runner, dirProvider, logger),
}
return
}
示例8:
options LinuxOptions
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
collector = &fakestats.FakeStatsCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
diskWaitTimeout = 1 * time.Millisecond
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs, logger)
vitalsService = boshvitals.NewService(collector, dirProvider)
netManager = &fakenet.FakeNetManager{}
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
options = LinuxOptions{}
fs.SetGlob("/sys/bus/scsi/devices/*:0:0:0/block/*", []string{
"/sys/bus/scsi/devices/0:0:0:0/block/sr0",
"/sys/bus/scsi/devices/6:0:0:0/block/sdd",
"/sys/bus/scsi/devices/fake-host-id:0:0:0/block/sda",
})
fs.SetGlob("/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/*", []string{
"/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/sdf",
})
})
示例9: init
func init() {
const expectedCentosDHCPConfig = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
prepend domain-name-servers zz.zz.zz.zz;
prepend domain-name-servers yy.yy.yy.yy;
prepend domain-name-servers xx.xx.xx.xx;
`
const expectedCentosIfcfg = `DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.195.6
NETMASK=255.255.255.0
BROADCAST=192.168.195.255
GATEWAY=192.168.195.1
ONBOOT=yes`
Describe("centos", func() {
var (
collector *fakestats.FakeStatsCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager *fakedisk.FakeDiskManager
dirProvider boshdirs.DirectoriesProvider
platform Platform
cdutil *fakecd.FakeCdUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeStatsCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs)
vitalsService = boshvitals.NewService(collector, dirProvider)
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
netManager := boshnet.NewCentosNetManager(fs, cmdRunner, 1*time.Millisecond)
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
netManager,
1*time.Millisecond,
logger,
)
})
Describe("SetupDhcp", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns"},
DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy", "zz.zz.zz.zz"},
},
"vip": boshsettings.Network{
Default: []string{},
DNS: []string{"aa.aa.aa.aa"},
},
}
Context("when dhcp was not previously configured", func() {
It("writes dhcp configuration", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedCentosDHCPConfig))
})
It("restarts network", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network", "restart"}))
//.........這裏部分代碼省略.........
示例10: NewProvider
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider, options ProviderOptions) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger)
linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs, options.Linux.BindMountPersistentDisk)
udev := boshudev.NewConcreteUdevDevice(runner)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs, logger)
sigarCollector := boshstats.NewSigarStatsCollector()
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
routesSearcher := boshnet.NewCmdRoutesSearcher(runner)
defaultNetworkResolver := boshnet.NewDefaultNetworkResolver(
routesSearcher,
boshnet.DefaultInterfaceToAddrsFunc,
)
centosNetManager := boshnet.NewCentosNetManager(fs, runner, defaultNetworkResolver, 10*time.Second, logger)
ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, defaultNetworkResolver, 10*time.Second, logger)
centos := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
centosNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
ubuntu := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
ubuntuNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
p.platforms = map[string]Platform{
"ubuntu": ubuntu,
"centos": centos,
"dummy": NewDummyPlatform(sigarCollector, fs, runner, dirProvider, linuxDiskManager, logger),
}
return
}
示例11: init
func init() {
Describe("Testing with Ginkgo", func() {
var (
collector *fakestats.FakeStatsCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager fakedisk.FakeDiskManager
dirProvider boshdirs.DirectoriesProvider
diskWaitTimeout time.Duration
platform Platform
cdutil *fakecd.FakeCdUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
)
BeforeEach(func() {
collector = &fakestats.FakeStatsCollector{}
fs = &fakesys.FakeFileSystem{}
cmdRunner = &fakesys.FakeCmdRunner{}
diskManager = fakedisk.NewFakeDiskManager(cmdRunner)
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
diskWaitTimeout = 1 * time.Millisecond
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs)
vitalsService = boshvitals.NewService(collector, dirProvider)
})
JustBeforeEach(func() {
netManager := boshnet.NewUbuntuNetManager(fs, cmdRunner, 1*time.Millisecond)
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
diskWaitTimeout,
netManager,
)
})
It("ubuntu setup runtime configuration", func() {
err := platform.SetupRuntimeConfiguration()
assert.NoError(GinkgoT(), err)
assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))
assert.Equal(GinkgoT(), []string{"bosh-agent-rc"}, cmdRunner.RunCommands[0])
})
It("ubuntu create user", func() {
expectedUseradd := []string{
"useradd",
"-m",
"-b", "/some/path/to/home",
"-s", "/bin/bash",
"-p", "bar-pwd",
"foo-user",
}
password := "bar-pwd"
err := platform.CreateUser("foo-user", password, "/some/path/to/home")
assert.NoError(GinkgoT(), err)
basePathStat := fs.GetFileTestStat("/some/path/to/home")
assert.Equal(GinkgoT(), fakesys.FakeFileTypeDir, basePathStat.FileType)
assert.Equal(GinkgoT(), os.FileMode(0755), basePathStat.FileMode)
assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))
assert.Equal(GinkgoT(), expectedUseradd, cmdRunner.RunCommands[0])
})
It("ubuntu create user with an empty password", func() {
expectedUseradd := []string{
"useradd",
"-m",
"-b", "/some/path/to/home",
"-s", "/bin/bash",
"foo-user",
}
password := ""
err := platform.CreateUser("foo-user", password, "/some/path/to/home")
assert.NoError(GinkgoT(), err)
basePathStat := fs.GetFileTestStat("/some/path/to/home")
assert.Equal(GinkgoT(), fakesys.FakeFileTypeDir, basePathStat.FileType)
assert.Equal(GinkgoT(), os.FileMode(0755), basePathStat.FileMode)
assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))
assert.Equal(GinkgoT(), expectedUseradd, cmdRunner.RunCommands[0])
})
It("ubuntu add user to groups", func() {
//.........這裏部分代碼省略.........