本文整理汇总了Golang中github.com/juju/juju/version.GetOSFromSeries函数的典型用法代码示例。如果您正苦于以下问题:Golang GetOSFromSeries函数的具体用法?Golang GetOSFromSeries怎么用?Golang GetOSFromSeries使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetOSFromSeries函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
oldMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
newMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
if !exploded {
c.Assert(newMetadata, gc.HasLen, len(oldMetadata))
} else {
// new metadata should have more tools.
c.Assert(len(newMetadata), jc.GreaterThan, len(oldMetadata))
var expectedSeries set.Strings
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Ubuntu {
expectedSeries.Add(series)
}
}
c.Assert(newMetadata, gc.HasLen, expectedSeries.Size())
for _, m := range newMetadata {
c.Assert(expectedSeries.Contains(m.Release), jc.IsTrue)
}
}
}
示例2: TestCurrentSeries
func (*CurrentSuite) TestCurrentSeries(c *gc.C) {
s := version.Current.Series
if s == "unknown" {
s = "n/a"
}
out, err := exec.Command("lsb_release", "-c").CombinedOutput()
if err != nil {
// If the command fails (for instance if we're running on some other
// platform) then CurrentSeries should be unknown.
switch runtime.GOOS {
case "darwin":
c.Check(s, gc.Matches, `mavericks|mountainlion|lion|snowleopard`)
case "windows":
c.Check(s, gc.Matches, `win2012hvr2|win2012hv|win2012|win2012r2|win8|win81|win7`)
default:
c.Assert(s, gc.Equals, "n/a")
}
} else {
os, err := version.GetOSFromSeries(s)
c.Assert(err, gc.IsNil)
// There is no lsb_release command on CentOS.
switch os {
case version.CentOS:
c.Check(s, gc.Matches, `centos7`)
default:
c.Assert(string(out), gc.Equals, "Codename:\t"+s+"\n")
}
}
}
示例3: versionInitSystem
func versionInitSystem(series string) (string, error) {
os, err := version.GetOSFromSeries(series)
if err != nil {
notFound := errors.NotFoundf("init system for series %q", series)
return "", errors.Wrap(err, notFound)
}
switch os {
case version.Windows:
return InitSystemWindows, nil
case version.Ubuntu:
switch series {
case "precise", "quantal", "raring", "saucy", "trusty", "utopic":
return InitSystemUpstart, nil
default:
// vivid and later
if featureflag.Enabled(feature.LegacyUpstart) {
return InitSystemUpstart, nil
}
return InitSystemSystemd, nil
}
case version.CentOS:
return InitSystemSystemd, nil
}
return "", errors.NotFoundf("unknown os %q (from series %q), init system", os, series)
}
示例4: NewUserdataConfig
// UserdataConfig is supposed to take in an instanceConfig as well as a
// cloudinit.cloudConfig and add attributes in the cloudinit structure based on
// the values inside instanceConfig and on the series
func NewUserdataConfig(icfg *instancecfg.InstanceConfig, conf cloudinit.CloudConfig) (UserdataConfig, error) {
// TODO(ericsnow) bug #1426217
// Protect icfg and conf better.
operatingSystem, err := version.GetOSFromSeries(icfg.Series)
if err != nil {
return nil, err
}
base := baseConfigure{
tag: names.NewMachineTag(icfg.MachineId),
icfg: icfg,
conf: conf,
os: operatingSystem,
}
switch operatingSystem {
case version.Ubuntu:
return &unixConfigure{base}, nil
case version.CentOS:
return &unixConfigure{base}, nil
case version.Windows:
return &windowsConfigure{base}, nil
default:
return nil, errors.NotSupportedf("OS %s", icfg.Series)
}
}
示例5: setDataDirPermissions
func (w *unixConfigure) setDataDirPermissions() string {
os, _ := version.GetOSFromSeries(w.icfg.Series)
var user string
switch os {
case version.CentOS:
user = "root"
default:
user = "syslog"
}
return fmt.Sprintf("chown %s:adm %s", user, w.icfg.LogDir)
}
示例6: TestGetOSFromSeries
func (s *supportedSeriesSuite) TestGetOSFromSeries(c *gc.C) {
for _, t := range getOSFromSeriesTests {
got, err := version.GetOSFromSeries(t.series)
if t.err != "" {
c.Assert(err, gc.ErrorMatches, t.err)
} else {
c.Check(err, jc.ErrorIsNil)
c.Assert(got, gc.Equals, t.want)
}
}
}
示例7: writeEnvironment
func (w *proxyWorker) writeEnvironment() error {
osystem, err := version.GetOSFromSeries(version.Current.Series)
if err != nil {
return err
}
switch osystem {
case version.Windows:
return w.writeEnvironmentToRegistry()
default:
return w.writeEnvironmentFile()
}
}
示例8: osVal
// osVal will lookup the value of the key valname
// in the apropriate map, based on the series. This will
// help reduce boilerplate code
func osVal(series string, valname osVarType) (string, error) {
os, err := version.GetOSFromSeries(series)
if err != nil {
return "", err
}
switch os {
case version.Windows:
return winVals[valname], nil
default:
return nixVals[valname], nil
}
}
示例9: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
envtesting.RemoveFakeToolsMetadata(c, env.Storage())
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
// We don't write metadata at bootstrap anymore.
simplestreamsMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
c.Assert(simplestreamsMetadata, gc.HasLen, 0)
// The tools should have been added to state, and
// exploded into each of the supported series of
// the same operating system if the tools were uploaded.
st, err := state.Open(&mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
var expectedSeries set.Strings
if exploded {
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Current.OS {
expectedSeries.Add(series)
}
}
} else {
expectedSeries.Add(version.Current.Series)
}
storage, err := st.ToolsStorage()
c.Assert(err, gc.IsNil)
defer storage.Close()
metadata, err := storage.AllMetadata()
c.Assert(err, gc.IsNil)
c.Assert(metadata, gc.HasLen, expectedSeries.Size())
for _, m := range metadata {
c.Assert(expectedSeries.Contains(m.Version.Series), jc.IsTrue)
}
}
示例10: locallyBuildableTools
// locallyBuildableTools returns the list of tools that
// can be built locally, for series of the same OS.
func locallyBuildableTools() (buildable coretools.List) {
for _, series := range version.SupportedSeries() {
if os, err := version.GetOSFromSeries(series); err != nil || os != version.Current.OS {
continue
}
binary := version.Current
binary.Series = series
// Increment the build number so we know it's a development build.
binary.Build++
buildable = append(buildable, &coretools.Tools{Version: binary})
}
return buildable
}
示例11: osVal
// osVal will lookup the value of the key valname
// in the apropriate map, based on the series. This will
// help reduce boilerplate code
func osVal(series string, valname osVarType) (string, error) {
os, err := version.GetOSFromSeries(series)
if err != nil {
return "", err
}
switch os {
case version.Windows:
return winVals[valname], nil
case version.Ubuntu:
return linuxVals[valname], nil
}
return "", fmt.Errorf("Unknown OS: %q", os)
}
示例12: NewUserdataConfig
func NewUserdataConfig(cfg *MachineConfig, c *cloudinit.Config) (UserdataConfig, error) {
operatingSystem, err := version.GetOSFromSeries(cfg.Series)
if err != nil {
return nil, err
}
switch operatingSystem {
case version.Ubuntu:
return newUbuntuConfig(cfg, c)
case version.Windows:
return newWindowsConfig(cfg, c)
default:
return nil, errors.Errorf("Unsupported OS %s", cfg.Series)
}
}
示例13: NewRenderer
// NewRenderer returns a Renderer interface for selected series
func NewRenderer(series string) (Renderer, error) {
operatingSystem, err := version.GetOSFromSeries(series)
if err != nil {
return nil, err
}
switch operatingSystem {
case version.Windows:
return &WindowsRenderer{}, nil
case version.Ubuntu:
return &UbuntuRenderer{}, nil
default:
return nil, errors.Errorf("No renderer could be found for %s", series)
}
}
示例14: binary
// binary returns the tools metadata's binary version, which may be used for
// map lookup. It is possible for a binary to have an unkown OS.
func (t *ToolsMetadata) binary() (version.Binary, error) {
num, err := version.Parse(t.Version)
if err != nil {
return version.Binary{}, errors.Trace(err)
}
toolsOS, err := version.GetOSFromSeries(t.Release)
if err != nil && !version.IsUnknownOSForSeriesError(err) {
return version.Binary{}, errors.Trace(err)
}
return version.Binary{
Number: num,
Series: t.Release,
Arch: t.Arch,
OS: toolsOS,
}, nil
}
示例15: New
// New returns a new Config with no options set.
func New(series string) (CloudConfig, error) {
os, err := version.GetOSFromSeries(series)
if err != nil {
return nil, err
}
switch os {
case version.Windows:
renderer, _ := shell.NewRenderer("powershell")
return &windowsCloudConfig{
&cloudConfig{
series: series,
renderer: renderer,
attrs: make(map[string]interface{}),
},
}, nil
case version.Ubuntu:
renderer, _ := shell.NewRenderer("bash")
return &ubuntuCloudConfig{
&cloudConfig{
series: series,
paccmder: commands.NewAptPackageCommander(),
pacconfer: config.NewAptPackagingConfigurer(series),
renderer: renderer,
attrs: make(map[string]interface{}),
},
}, nil
case version.CentOS:
renderer, _ := shell.NewRenderer("bash")
return ¢OSCloudConfig{
&cloudConfig{
series: series,
paccmder: commands.NewYumPackageCommander(),
pacconfer: config.NewYumPackagingConfigurer(series),
renderer: renderer,
attrs: make(map[string]interface{}),
},
}, nil
default:
return nil, errors.NotFoundf("cloudconfig for series %q", series)
}
}