本文整理匯總了Golang中github.com/juju/utils/series.GetOSFromSeries函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetOSFromSeries函數的具體用法?Golang GetOSFromSeries怎麽用?Golang GetOSFromSeries使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetOSFromSeries函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetUpTest
func (s *syslogSuite) SetUpTest(c *gc.C) {
if runtime.GOOS != "linux" {
c.Skip(fmt.Sprintf("this test requires a controller, therefore does not support %q", runtime.GOOS))
}
currentSeries := series.HostSeries()
osFromSeries, err := series.GetOSFromSeries(currentSeries)
c.Assert(err, jc.ErrorIsNil)
if osFromSeries != os.Ubuntu {
c.Skip(fmt.Sprintf("this test requires a controller, therefore does not support OS %q only Ubuntu", osFromSeries.String()))
}
s.AgentSuite.SetUpTest(c)
// TODO(perrito666) 200160701:
// This needs to be done to stop the test from trying to install mongo
// while running, but it is a huge footprint for such little benefit.
// This test should not need JujuConnSuite or AgentSuite.
s.fakeEnsureMongo = agenttest.InstallFakeEnsureMongo(s)
done := make(chan struct{})
s.received = make(chan rfc5424test.Message)
addr := s.createSyslogServer(c, s.received, done)
// Leave log forwarding disabled initially, it will be enabled
// via a model config update in the test.
err = s.State.UpdateModelConfig(map[string]interface{}{
"syslog-host": addr,
"syslog-ca-cert": coretesting.CACert,
"syslog-client-cert": coretesting.ServerCert,
"syslog-client-key": coretesting.ServerKey,
}, nil, nil)
c.Assert(err, jc.ErrorIsNil)
s.logsCh, err = logsender.InstallBufferedLogWriter(1000)
c.Assert(err, jc.ErrorIsNil)
}
示例2: versionInitSystem
func versionInitSystem(ser string) (string, error) {
seriesos, err := series.GetOSFromSeries(ser)
if err != nil {
notFound := errors.NotFoundf("init system for series %q", ser)
return "", errors.Wrap(err, notFound)
}
switch seriesos {
case os.Windows:
return InitSystemWindows, nil
case os.Ubuntu:
switch ser {
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 os.CentOS:
return InitSystemSystemd, nil
}
return "", errors.NotFoundf("unknown os %q (from series %q), init system", seriesos, ser)
}
示例3: validateUploadAllowed
// validateUploadAllowed returns an error if an attempt to upload tools should
// not be allowed.
func validateUploadAllowed(env environs.Environ, toolsArch, toolsSeries *string, validator constraints.Validator) error {
// Now check that the architecture and series for which we are setting up an
// environment matches that from which we are bootstrapping.
hostArch := arch.HostArch()
// We can't build tools for a different architecture if one is specified.
if toolsArch != nil && *toolsArch != hostArch {
return fmt.Errorf("cannot use agent built for %q using a machine running on %q", *toolsArch, hostArch)
}
hostOS := jujuos.HostOS()
if toolsSeries != nil {
toolsSeriesOS, err := series.GetOSFromSeries(*toolsSeries)
if err != nil {
return errors.Trace(err)
}
if !toolsSeriesOS.EquivalentTo(hostOS) {
return errors.Errorf("cannot use agent built for %q using a machine running %q", *toolsSeries, hostOS)
}
}
// If no architecture is specified, ensure the target provider supports instances matching our architecture.
if _, err := validator.Validate(constraints.Value{Arch: &hostArch}); err != nil {
return errors.Errorf(
"model %q of type %s does not support instances running on %q",
env.Config().Name(), env.Config().Type(), hostArch,
)
}
return nil
}
示例4: newRole
// newRole creates a gwacl.Role object (an Azure Virtual Machine) which uses
// the given Virtual Hard Drive.
//
// roleSize is the name of one of Azure's machine types, e.g. ExtraSmall,
// Large, A6 etc.
func (env *azureEnviron) newRole(roleSize string, vhd *gwacl.OSVirtualHardDisk, stateServer bool, userdata, ser string, snapshot *azureEnviron) (*gwacl.Role, error) {
// Do some common initialization
roleName := gwacl.MakeRandomRoleName("juju")
hostname := roleName
password := gwacl.MakeRandomPassword()
os, err := series.GetOSFromSeries(ser)
if err != nil {
return nil, errors.Trace(err)
}
// Generate a Network Configuration with the initially required ports open.
networkConfigurationSet := gwacl.NewNetworkConfigurationSet(env.getInitialEndpoints(stateServer), nil)
var role *gwacl.Role
switch os {
case jujuos.Windows:
role, err = makeWindowsRole(password, roleSize, roleName, userdata, vhd, networkConfigurationSet, snapshot)
default:
role, err = makeLinuxRole(hostname, password, roleSize, roleName, userdata, vhd, networkConfigurationSet)
}
if err != nil {
return nil, errors.Trace(err)
}
role.AvailabilitySetName = "juju"
return role, nil
}
示例5: 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 := series.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 os.Ubuntu:
return &unixConfigure{base}, nil
case os.CentOS:
return &unixConfigure{base}, nil
case os.Windows:
return &windowsConfigure{base}, nil
default:
return nil, errors.NotSupportedf("OS %s", icfg.Series)
}
}
示例6: TestCurrentSeries
func (*CurrentSuite) TestCurrentSeries(c *gc.C) {
s := series.HostSeries()
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:
current_os, err := series.GetOSFromSeries(s)
c.Assert(err, gc.IsNil)
if s != "n/a" {
// There is no lsb_release command on CentOS.
if current_os == os.CentOS {
c.Check(s, gc.Matches, `centos7`)
}
}
}
} else {
c.Assert(string(out), gc.Equals, "Codename:\t"+s+"\n")
}
}
示例7: getDisks
// getDisks builds the raw spec for the disks that should be attached to
// the new instances and returns it. This will always include a root
// disk with characteristics determined by the provides args and
// constraints.
func getDisks(spec *instances.InstanceSpec, cons constraints.Value, ser, eUUID string) ([]google.DiskSpec, error) {
size := common.MinRootDiskSizeGiB(ser)
if cons.RootDisk != nil && *cons.RootDisk > size {
size = common.MiBToGiB(*cons.RootDisk)
}
var imageURL string
os, err := series.GetOSFromSeries(ser)
if err != nil {
return nil, errors.Trace(err)
}
switch os {
case jujuos.Ubuntu:
imageURL = ubuntuImageBasePath
case jujuos.Windows:
imageURL = windowsImageBasePath
default:
return nil, errors.Errorf("os %s is not supported on the gce provider", os.String())
}
dSpec := google.DiskSpec{
Series: ser,
SizeHintGB: size,
ImageURL: imageURL + spec.Image.Id,
Boot: true,
AutoDelete: true,
Description: eUUID,
}
if cons.RootDisk != nil && dSpec.TooSmall() {
msg := "Ignoring root-disk constraint of %dM because it is smaller than the GCE image size of %dG"
logger.Infof(msg, *cons.RootDisk, google.MinDiskSizeGB(ser))
}
return []google.DiskSpec{dSpec}, nil
}
示例8: getContainerInstance
func getContainerInstance() (cont []ContainerInstance, err error) {
current_os, err := series.GetOSFromSeries(series.HostSeries())
if err != nil {
return nil, err
}
switch current_os {
case jujuos.CentOS:
cont = []ContainerInstance{
{instance.LXC, [][]string{
{"lxc"},
{"cloud-image-utils"},
}},
{instance.KVM, [][]string{
{"uvtool-libvirt"},
{"uvtool"},
}},
}
default:
cont = []ContainerInstance{
{instance.LXC, [][]string{
{"--target-release", "precise-updates/cloud-tools", "lxc"},
{"--target-release", "precise-updates/cloud-tools", "cloud-image-utils"},
}},
{instance.KVM, [][]string{
{"uvtool-libvirt"},
{"uvtool"},
}},
}
}
return cont, nil
}
示例9: TestGetDisks
func (s *environBrokerSuite) TestGetDisks(c *gc.C) {
for _, test := range getDisksTests {
diskSpecs, err := gce.GetDisks(s.spec, s.StartInstArgs.Constraints, test.Series, "32f7d570-5bac-4b72-b169-250c24a94b2b", false)
if test.error != nil {
c.Assert(err, gc.Equals, err)
} else {
c.Assert(err, jc.ErrorIsNil)
c.Assert(diskSpecs, gc.HasLen, 1)
diskSpec := diskSpecs[0]
os, err := series.GetOSFromSeries(test.Series)
c.Assert(err, jc.ErrorIsNil)
switch os {
case jujuos.Ubuntu:
c.Check(diskSpec.SizeHintGB, gc.Equals, uint64(8))
case jujuos.Windows:
c.Check(diskSpec.SizeHintGB, gc.Equals, uint64(40))
default:
c.Check(diskSpec.SizeHintGB, gc.Equals, uint64(8))
}
c.Check(diskSpec.ImageURL, gc.Equals, test.basePath+s.spec.Image.Id)
}
}
diskSpecs, err := gce.GetDisks(s.spec, s.StartInstArgs.Constraints, "trusty", "32f7d570-5bac-4b72-b169-250c24a94b2b", true)
c.Assert(err, jc.ErrorIsNil)
c.Assert(diskSpecs, gc.HasLen, 1)
spec := diskSpecs[0]
c.Assert(spec.ImageURL, gc.Equals, gce.UbuntuDailyImageBasePath+s.spec.Image.Id)
}
示例10: ComposeUserData
// ComposeUserData fills out the provided cloudinit configuration structure
// so it is suitable for initialising a machine with the given configuration,
// and then renders it and encodes it using the supplied renderer.
// When calling ComposeUserData a encoding implementation must be chosen from
// the providerinit/encoders package according to the need of the provider.
//
// If the provided cloudcfg is nil, a new one will be created internally.
func ComposeUserData(icfg *instancecfg.InstanceConfig, cloudcfg cloudinit.CloudConfig, renderer renderers.ProviderRenderer) ([]byte, error) {
if cloudcfg == nil {
var err error
cloudcfg, err = cloudinit.New(icfg.Series)
if err != nil {
return nil, errors.Trace(err)
}
}
_, err := configureCloudinit(icfg, cloudcfg)
if err != nil {
return nil, errors.Trace(err)
}
operatingSystem, err := series.GetOSFromSeries(icfg.Series)
if err != nil {
return nil, errors.Trace(err)
}
// This might get replaced by a renderer.RenderUserdata which will either
// render it as YAML or Bash since some CentOS images might ship without cloudnit
udata, err := cloudcfg.RenderYAML()
if err != nil {
return nil, errors.Trace(err)
}
udata, err = renderer.EncodeUserdata(udata, operatingSystem)
if err != nil {
return nil, errors.Trace(err)
}
logger.Tracef("Generated cloud init:\n%s", string(udata))
return udata, err
}
示例11: populateTools
// populateTools stores uploaded tools in provider storage
// and updates the tools metadata.
func (c *BootstrapCommand) populateTools(st *state.State, env environs.Environ) error {
agentConfig := c.CurrentConfig()
dataDir := agentConfig.DataDir()
current := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
tools, err := agenttools.ReadTools(dataDir, current)
if err != nil {
return errors.Trace(err)
}
data, err := ioutil.ReadFile(filepath.Join(
agenttools.SharedToolsDir(dataDir, current),
"tools.tar.gz",
))
if err != nil {
return errors.Trace(err)
}
toolstorage, err := st.ToolsStorage()
if err != nil {
return errors.Trace(err)
}
defer toolstorage.Close()
var toolsVersions []version.Binary
if strings.HasPrefix(tools.URL, "file://") {
// Tools were uploaded: clone for each series of the same OS.
os, err := series.GetOSFromSeries(tools.Version.Series)
if err != nil {
return errors.Trace(err)
}
osSeries := series.OSSupportedSeries(os)
for _, series := range osSeries {
toolsVersion := tools.Version
toolsVersion.Series = series
toolsVersions = append(toolsVersions, toolsVersion)
}
} else {
// Tools were downloaded from an external source: don't clone.
toolsVersions = []version.Binary{tools.Version}
}
for _, toolsVersion := range toolsVersions {
metadata := binarystorage.Metadata{
Version: toolsVersion.String(),
Size: tools.Size,
SHA256: tools.SHA256,
}
logger.Debugf("Adding tools: %v", toolsVersion)
if err := toolstorage.Add(bytes.NewReader(data), metadata); err != nil {
return errors.Trace(err)
}
}
return nil
}
示例12: shouldWarnJuju1x
func shouldWarnJuju1x() bool {
// this code only applies to Ubuntu, where we renamed Juju 1.x to juju-1.
ostype, err := series.GetOSFromSeries(series.HostSeries())
if err != nil || ostype != utilsos.Ubuntu {
return false
}
return osenv.Juju1xEnvConfigExists() && !juju2xConfigDataExists()
}
示例13: setDataDirPermissions
func (w *unixConfigure) setDataDirPermissions() string {
seriesos, _ := series.GetOSFromSeries(w.icfg.Series)
var user string
switch seriesos {
case os.CentOS:
user = "root"
default:
user = "syslog"
}
return fmt.Sprintf("chown %s:adm %s", user, w.icfg.LogDir)
}
示例14: TestGetOSFromSeries
func (s *supportedSeriesSuite) TestGetOSFromSeries(c *gc.C) {
for _, t := range getOSFromSeriesTests {
got, err := series.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)
}
}
}
示例15: 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(ser string, valname osVarType) (string, error) {
os, err := series.GetOSFromSeries(ser)
if err != nil {
return "", err
}
switch os {
case jujuos.Windows:
return winVals[valname], nil
default:
return nixVals[valname], nil
}
}