Skip to content

Commit

Permalink
Added CentOS userdata support
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanteleaga committed Apr 16, 2015
1 parent 01d1ada commit 96429c2
Show file tree
Hide file tree
Showing 84 changed files with 1,317 additions and 1,217 deletions.
1 change: 1 addition & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/juju/juju/api"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/cloudconfig/cloudinit"
"github.com/juju/juju/juju/paths"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
Expand Down
3 changes: 2 additions & 1 deletion api/block/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package block_test

import (
gc "gopkg.in/check.v1"
"testing"

gc "gopkg.in/check.v1"
)

func TestAll(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions apiserver/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ func machineJobFromParams(job multiwatcher.MachineJob) (state.MachineJob, error)
// provisions a machine agent on the machine executing the script.
func (c *Client) ProvisioningScript(args params.ProvisioningScriptParams) (params.ProvisioningScriptResult, error) {
var result params.ProvisioningScriptResult
mcfg, err := MachineConfig(c.api.state, args.MachineId, args.Nonce, args.DataDir)
icfg, err := InstanceConfig(c.api.state, args.MachineId, args.Nonce, args.DataDir)
if err != nil {
return result, err
}
Expand All @@ -909,16 +909,16 @@ func (c *Client) ProvisioningScript(args params.ProvisioningScriptParams) (param
// true. False indicates the client doesn't care and we should use
// what's specified in the environments.yaml file.
if args.DisablePackageCommands {
mcfg.EnableOSRefreshUpdate = false
mcfg.EnableOSUpgrade = false
icfg.EnableOSRefreshUpdate = false
icfg.EnableOSUpgrade = false
} else if cfg, err := c.api.state.EnvironConfig(); err != nil {
return result, err
} else {
mcfg.EnableOSUpgrade = cfg.EnableOSUpgrade()
mcfg.EnableOSRefreshUpdate = cfg.EnableOSRefreshUpdate()
icfg.EnableOSUpgrade = cfg.EnableOSUpgrade()
icfg.EnableOSRefreshUpdate = cfg.EnableOSRefreshUpdate()
}

result.Script, err = manual.ProvisioningScript(mcfg)
result.Script, err = manual.ProvisioningScript(icfg)
return result, err
}

Expand Down
4 changes: 2 additions & 2 deletions apiserver/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3376,9 +3376,9 @@ func (s *clientSuite) TestProvisioningScript(c *gc.C) {
Nonce: apiParams.Nonce,
})
c.Assert(err, jc.ErrorIsNil)
mcfg, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
icfg, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
sshinitScript, err := manual.ProvisioningScript(mcfg)
sshinitScript, err := manual.ProvisioningScript(icfg)
c.Assert(err, jc.ErrorIsNil)
// ProvisioningScript internally calls MachineConfig,
// which allocates a new, random password. Everything
Expand Down
14 changes: 7 additions & 7 deletions apiserver/client/machineconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/cloudconfig/instancecfg"
"github.com/juju/juju/environmentserver/authentication"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/cloudinit"
"github.com/juju/juju/state"
)

// MachineConfig returns information from the environment config that
// is needed for machine cloud-init (for non-state servers only). It
// is exposed for testing purposes.
// TODO(rog) fix environs/manual tests so they do not need to call this, or move this elsewhere.
func MachineConfig(st *state.State, machineId, nonce, dataDir string) (*cloudinit.MachineConfig, error) {
func InstanceConfig(st *state.State, machineId, nonce, dataDir string) (*instancecfg.InstanceConfig, error) {
environConfig, err := st.EnvironConfig()
if err != nil {
return nil, err
Expand Down Expand Up @@ -94,19 +94,19 @@ func MachineConfig(st *state.State, machineId, nonce, dataDir string) (*cloudini
return nil, err
}
secureServerConnection := info.CAPrivateKey != ""
mcfg, err := environs.NewMachineConfig(machineId, nonce, env.Config().ImageStream(), machine.Series(),
icfg, err := instancecfg.NewInstanceConfig(machineId, nonce, env.Config().ImageStream(), machine.Series(),
secureServerConnection, networks, mongoInfo, apiInfo,
)
if err != nil {
return nil, err
}
if dataDir != "" {
mcfg.DataDir = dataDir
icfg.DataDir = dataDir
}
mcfg.Tools = tools
err = environs.FinishMachineConfig(mcfg, environConfig)
icfg.Tools = tools
err = instancecfg.FinishInstanceConfig(icfg, environConfig)
if err != nil {
return nil, err
}
return mcfg, nil
return icfg, nil
}
20 changes: 10 additions & 10 deletions apiserver/client/machineconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
c.Assert(len(machines), gc.Equals, 1)

machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)

envConfig, err := s.State.EnvironConfig()
c.Assert(err, jc.ErrorIsNil)
mongoAddrs := s.State.MongoConnectionInfo().Addrs
apiAddrs := []string{net.JoinHostPort("localhost", strconv.Itoa(envConfig.APIPort()))}

c.Check(machineConfig.MongoInfo.Addrs, gc.DeepEquals, mongoAddrs)
c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
c.Check(instanceConfig.MongoInfo.Addrs, gc.DeepEquals, mongoAddrs)
c.Check(instanceConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
toolsURL := fmt.Sprintf("https://%s/environment/%s/tools/%s",
apiAddrs[0], jujutesting.EnvironmentTag.Id(), machineConfig.Tools.Version)
c.Assert(machineConfig.Tools.URL, gc.Equals, toolsURL)
c.Assert(machineConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "true")
apiAddrs[0], jujutesting.EnvironmentTag.Id(), instanceConfig.Tools.Version)
c.Assert(instanceConfig.Tools.URL, gc.Equals, toolsURL)
c.Assert(instanceConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "true")
}

func (s *machineConfigSuite) TestSecureConnectionDisallowed(c *gc.C) {
Expand All @@ -83,9 +83,9 @@ func (s *machineConfigSuite) TestSecureConnectionDisallowed(c *gc.C) {
c.Assert(len(machines), gc.Equals, 1)

machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "false")
c.Assert(instanceConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "false")
}

func (s *machineConfigSuite) TestMachineConfigNoArch(c *gc.C) {
Expand All @@ -97,7 +97,7 @@ func (s *machineConfigSuite) TestMachineConfigNoArch(c *gc.C) {
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
_, err = client.MachineConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
_, err = client.InstanceConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("arch is not set for %q", "machine-"+machines[0].Machine))
}

Expand All @@ -115,6 +115,6 @@ func (s *machineConfigSuite) TestMachineConfigNoTools(c *gc.C) {
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
_, err = client.MachineConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
_, err = client.InstanceConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error())
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/cloudinit"
"github.com/juju/juju/cloudconfig/cloudinit"
coretesting "github.com/juju/juju/testing"
sshtesting "github.com/juju/juju/utils/ssh/testing"
)
Expand Down
46 changes: 46 additions & 0 deletions cloudconfig/cloudinit/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cloudinit

import (
"github.com/juju/errors"

"github.com/juju/juju/version"
)

type Renderer interface {

// Mkdir returns an OS specific script for creating a directory
Mkdir(path string) []string

// WriteFile returns a command to write data
WriteFile(filename string, contents string, permission int) []string

// Render renders the userdata script for a particular OS type
Render(conf *Config) ([]byte, error)

// FromSlash returns the result of replacing each slash ('/') character
// in path with a separator character. Multiple slashes are replaced by
// multiple separators.

FromSlash(path string) string
// PathJoin will join a path using OS specific path separator.
// This works for selected OS instead of current OS

PathJoin(path ...string) string
}

// 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)
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

gc "gopkg.in/check.v1"

"github.com/juju/juju/cloudinit"
"github.com/juju/juju/cloudconfig/cloudinit"
)

type progressSuite struct{}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package cloudinit
package cloudconfig

var (
ToolsDownloadCommand = toolsDownloadCommand
Expand Down
Loading

0 comments on commit 96429c2

Please sign in to comment.