Raphaël Badin has proposed merging lp:~rvb/juju-core/provider-userdata into 
lp:~maas-maintainers/juju-core/maas-provider-skeleton.

Commit message:
Add userData utility method.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~rvb/juju-core/provider-userdata/+merge/152728

This branch adds the 'userData()' utility method that will be used by the 
provider's 'startInstance()' method.

As discussed with Jeroen, instead of introducing yet another structure, it 
simply uses 'cloudinit.MachineConfig'.  The caller will have to build that 
structure but this way, it's mouch more clear what data is actually needed 
where.  This branch also adds the constants that 'startInstance()' will need 
when building 'cloudinit.MachineConfig' objects.
-- 
https://code.launchpad.net/~rvb/juju-core/provider-userdata/+merge/152728
Your team MAAS Maintainers is requested to review the proposed merge of 
lp:~rvb/juju-core/provider-userdata into 
lp:~maas-maintainers/juju-core/maas-provider-skeleton.
=== modified file 'environs/maas/environ.go'
--- environs/maas/environ.go	2013-03-08 11:36:53 +0000
+++ environs/maas/environ.go	2013-03-11 17:12:20 +0000
@@ -15,6 +15,12 @@
 	"time"
 )
 
+const (
+	mgoPort     = 37017
+	apiPort     = 17070
+	jujuDataDir = "/var/lib/juju"
+)
+
 type maasEnviron struct {
 	name string
 

=== modified file 'environs/maas/util.go'
--- environs/maas/util.go	2013-02-08 11:07:33 +0000
+++ environs/maas/util.go	2013-03-11 17:12:20 +0000
@@ -1,7 +1,10 @@
 package maas
 
 import (
+	"launchpad.net/juju-core/environs/cloudinit"
+	"launchpad.net/juju-core/log"
 	"launchpad.net/juju-core/state"
+	"launchpad.net/juju-core/trivial"
 	"net/url"
 	"strings"
 )
@@ -24,3 +27,18 @@
 	}
 	return values
 }
+
+// userData returns a zipped cloudinit config.
+func userData(cfg *cloudinit.MachineConfig) ([]byte, error) {
+	cloudcfg, err := cloudinit.New(cfg)
+	if err != nil {
+		return nil, err
+	}
+	data, err := cloudcfg.Render()
+	if err != nil {
+		return nil, err
+	}
+	cdata := trivial.Gzip(data)
+	log.Debugf("environs/maas: maas user data; %d bytes", len(cdata))
+	return cdata, nil
+}

=== modified file 'environs/maas/util_test.go'
--- environs/maas/util_test.go	2013-02-06 16:24:45 +0000
+++ environs/maas/util_test.go	2013-03-11 17:12:20 +0000
@@ -2,7 +2,14 @@
 
 import (
 	. "launchpad.net/gocheck"
+	"launchpad.net/goyaml"
+	"launchpad.net/juju-core/environs/cloudinit"
+	"launchpad.net/juju-core/environs/config"
 	"launchpad.net/juju-core/state"
+	"launchpad.net/juju-core/state/api"
+	"launchpad.net/juju-core/testing"
+	"launchpad.net/juju-core/trivial"
+	"launchpad.net/juju-core/version"
 )
 
 type UtilSuite struct{}
@@ -26,3 +33,51 @@
 
 	c.Check(values["id"], DeepEquals, []string{"system_id1", "system_id2"})
 }
+
+func (s *UtilSuite) TestUserData(c *C) {
+
+	tools := &state.Tools{
+		URL:    "http://foo.com/tools/juju1.2.3-linux-amd64.tgz";,
+		Binary: version.MustParseBinary("1.2.3-linux-amd64"),
+	}
+	envConfig, err := config.New(map[string]interface{}{
+		"type":            "maas",
+		"name":            "foo",
+		"default-series":  "series",
+		"authorized-keys": "keys",
+		"ca-cert":         testing.CACert,
+	})
+	c.Assert(err, IsNil)
+
+	cfg := &cloudinit.MachineConfig{
+		MachineId:       "10",
+		Tools:           tools,
+		StateServerCert: []byte(testing.ServerCert),
+		StateServerKey:  []byte(testing.ServerKey),
+		StateInfo: &state.Info{
+			Password: "pw1",
+			CACert:   []byte("CA CERT\n" + testing.CACert),
+		},
+		APIInfo: &api.Info{
+			Password: "pw2",
+			CACert:   []byte("CA CERT\n" + testing.CACert),
+		},
+		DataDir:     jujuDataDir,
+		MongoPort:   mgoPort,
+		Config:      envConfig,
+		APIPort:     apiPort,
+		StateServer: true,
+	}
+	result, err := userData(cfg)
+	c.Assert(err, IsNil)
+
+	unzipped, err := trivial.Gunzip(result)
+	c.Assert(err, IsNil)
+
+	x := make(map[interface{}]interface{})
+	err = goyaml.Unmarshal(unzipped, &x)
+	c.Assert(err, IsNil)
+
+	// Just check that the cloudinit config looks good.
+	c.Check(x["apt_upgrade"], Equals, true)
+}

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to