=== removed file 'environs/local/lxc.go'
--- environs/local/lxc.go 2012-03-15 02:15:16 +0000
+++ environs/local/lxc.go 1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
-package local
-
-import (
- "bytes"
- "os/exec"
- "strings"
-)
-
-// container represents an LXC container with the given name.
-type container struct {
- Name string
-}
-
-// runLXCCommand runs an LXC command with the given arguments,
-// strip outing the usage message.
-func runLXCCommand(args ...string) ([]byte, error) {
- output, err := exec.Command(args[0], args...).CombinedOutput()
- if i := bytes.Index(bytes.ToLower(output), []byte("\nusage: ")); i > 0 {
- output = output[:i]
- }
- return output, err
-}
-
-// rootPath returns the LXC container root filesystem path.
-func (c *container) rootPath() string {
- return "/var/lib/lxc/" + c.Name + "/rootfs/"
-}
-
-// create creates the LXC container.
-func (c *container) create() ([]byte, error) {
- return runLXCCommand("sudo", "lxc-create", "-n", c.Name)
-}
-
-// start starts the LXC container.
-func (c *container) start() ([]byte, error) {
- return runLXCCommand("sudo", "lxc-start", "--daemon", "-n", c.Name)
-}
-
-// stop stops the LXC container.
-func (c *container) stop() ([]byte, error) {
- return runLXCCommand("sudo", "lxc-stop", "-n", c.Name)
-}
-
-// destroy destroys the LXC container.
-func (c *container) destroy() ([]byte, error) {
- return runLXCCommand("sudo", "lxc-destroy", "-n", c.Name)
-}
-
-// running returns true if the container name is in the
-// list of the containers that are running.
-func (c *container) running() bool {
- for _, containerName := range list() {
- if containerName == c.Name {
- return true
- }
- }
- return false
-}
-
-// list returns a list with the names of containers.
-func list() []string {
- output, _ := runLXCCommand("sudo", "lxc-ls")
- return strings.Fields(string(output))
-}
=== removed file 'environs/local/lxc_test.go'
--- environs/local/lxc_test.go 2012-03-14 14:13:43 +0000
+++ environs/local/lxc_test.go 1970-01-01 00:00:00 +0000
@@ -1,81 +0,0 @@
-package local
-
-import (
- "flag"
- . "launchpad.net/gocheck"
- "testing"
-)
-
-const Defaultcontainer = "lxc_test"
-
-func Test(t *testing.T) { TestingT(t) }
-
-type S struct{}
-
-var _ = Suite(&S{})
-
-var lxcEnabled = flag.Bool("lxc", false, "enable LXC tests that require sudo")
-
-func (s *S) SetUpSuite(c *C) {
- if !*lxcEnabled {
- c.Skip("lxc tests need sudo access (-lxc to enable)")
- }
-}
-
-func (s *S) TestCreate(c *C) {
- var container container
- container.Name = Defaultcontainer
-
- _, err := container.create()
- c.Assert(err, IsNil)
-
- c.Assert(container.running(), Equals, true)
-
- _, err = container.destroy()
- c.Assert(err, IsNil)
-
- c.Assert(container.running(), Equals, false)
-}
-
-func (s *S) TestStart(c *C) {
- var container container
- container.Name = Defaultcontainer
-
- _, err := container.create()
- c.Assert(err, IsNil)
-
- _, err = container.start()
- c.Assert(err, IsNil)
-
- _, err = container.stop()
- c.Assert(err, IsNil)
-
- _, err = container.destroy()
- c.Assert(err, IsNil)
-}
-
-func (s *S) TestIsRunningWhencontainerIsCreated(c *C) {
- var container container
- container.Name = Defaultcontainer
-
- _, err := container.create()
- c.Assert(err, IsNil)
-
- c.Assert(container.running(), Equals, true)
-
- _, err = container.destroy()
- c.Assert(err, IsNil)
-}
-
-func (s *S) TestIsNotRunningWhencontainerIsNotCreated(c *C) {
- var container container
- container.Name = Defaultcontainer
-
- c.Assert(container.running(), Equals, false)
-}
-
-func (s *S) TestRootPath(c *C) {
- var container container
- container.Name = Defaultcontainer
- c.Assert(container.rootPath(), Equals, "/var/lib/lxc/"+Defaultcontainer+"/rootfs/")
-}
=== removed file 'environs/local/network.go'
--- environs/local/network.go 2012-05-24 17:10:58 +0000
+++ environs/local/network.go 1970-01-01 00:00:00 +0000
@@ -1,148 +0,0 @@
-package local
-
-import (
- "encoding/xml"
- "io/ioutil"
- "os"
- "os/exec"
- "strings"
- "text/template"
-)
-
-// network represents a local virtual network.
-type network struct {
- XMLName xml.Name `xml:"network"`
- Name string `xml:"name"`
- Bridge bridge `xml:"bridge"`
- Ip ip `xml:"ip"`
- Subnet int
-}
-
-// ip represents an ip with the given address and netmask.
-type ip struct {
- Ip string `xml:"address,attr"`
- Mask string `xml:"netmask,attr"`
-}
-
-// bridge represents a briddge with the given name.
-type bridge struct {
- Name string `xml:"name,attr"`
-}
-
-// newNetwork returns a started network.
-func newNetwork(name string, subnet int) (*network, error) {
- n := network{Name: name, Subnet: subnet}
- err := n.start()
- if err != nil {
- return nil, err
- }
- err = n.loadAttributes()
- if err != nil {
- return nil, err
- }
- return &n, nil
-}
-
-// loadAttributes loads the attributes for a network.
-func (n *network) loadAttributes() error {
- output, err := exec.Command("virsh", "net-dumpxml", n.Name).Output()
- if err != nil {
- return err
- }
- return xml.Unmarshal(output, &n)
-}
-
-// running returns true if network name is in the
-// list of networks and is active.
-func (n *network) running() (bool, error) {
- networks, err := listNetworks()
- if err != nil {
- return false, err
- }
- return networks[n.Name], nil
-}
-
-// exists returns true if network name is in the
-// list of networks.
-func (n *network) exists() (bool, error) {
- networks, err := listNetworks()
- if err != nil {
- return false, err
- }
- _, exists := networks[n.Name]
- return exists, nil
-}
-
-// virsh replaces %d with an auto increment
-// number to make the bridge name unique
-var libVirtNetworkTemplate = template.Must(template.New("").Parse(`
-
- {{.Name}}
-
-
-
-
-
-
-
-
-`))
-
-// start ensures that the network is started.
-// If the network name does not exist, it is created.
-func (n *network) start() error {
- exists, err := n.exists()
- if err != nil {
- return err
- }
- if exists {
- running, err := n.running()
- if err != nil {
- return err
- }
- if running {
- return nil
- }
- return exec.Command("virsh", "net-start", n.Name).Run()
- }
- file, err := ioutil.TempFile(os.TempDir(), "network")
- if err != nil {
- return err
- }
- defer file.Close()
- defer os.Remove(file.Name())
- err = libVirtNetworkTemplate.Execute(file, n)
- if err != nil {
- return err
- }
- err = exec.Command("virsh", "net-define", file.Name()).Run()
- if err != nil {
- return err
- }
- return exec.Command("virsh", "net-start", n.Name).Run()
-}
-
-// listNetworks returns a map from network name to active status.
-func listNetworks() (map[string]bool, error) {
- output, err := exec.Command("virsh", "net-list", "--all").Output()
- if err != nil {
- return nil, err
- }
- // Remove the header.
- networks := map[string]bool{}
- lines := strings.Split(string(output), "\n")
- if len(lines) < 3 {
- return networks, nil
- }
- lines = lines[2:]
- for _, line := range lines {
- if line == "" {
- continue
- }
- fields := strings.Fields(line)
- if len(fields) > 2 {
- networks[fields[0]] = fields[1] == "active"
- }
- }
- return networks, nil
-}
=== removed file 'environs/local/network_test.go'
--- environs/local/network_test.go 2012-05-24 17:10:58 +0000
+++ environs/local/network_test.go 1970-01-01 00:00:00 +0000
@@ -1,144 +0,0 @@
-package local
-
-import (
- . "launchpad.net/gocheck"
- "os"
-)
-
-var scriptText = `#!/bin/bash
-#!/bin/bash
-
-case "$1" in
-net-list)
-cat <
-default
-7f5d45e4-2fa2-f713-0229-fb1fea419e3b
-
-
-
-
-
-
-
-
-END
-;;
-
-net-start)
-echo "net-start"
-;;
-
-net-define)
-echo "net-define"
-;;
-
-esac
-`
-
-type networkSuite struct {
- oldPath string
-}
-
-var _ = Suite(&networkSuite{})
-
-func (s *networkSuite) SetUpSuite(c *C) {
- s.oldPath = os.Getenv("PATH")
- dir := c.MkDir()
- os.Setenv("PATH", dir+":"+s.oldPath)
- writeScript(c, dir)
-}
-
-func (s *networkSuite) TearDownSuite(c *C) {
- os.Setenv("PATH", s.oldPath)
-}
-
-func (s *networkSuite) TestStartNetwork(c *C) {
- // start a network that already exists
- n := network{Name: "default"}
- err := n.start()
- c.Assert(err, IsNil)
-
- // start a new network
- n = network{Name: "newnet"}
- err = n.start()
- c.Assert(err, IsNil)
-}
-
-func (s *networkSuite) TestNewNetwork(c *C) {
- _, err := newNetwork("name", 133)
- c.Assert(err, IsNil)
-}
-
-func (s *networkSuite) TestLoadAttributes(c *C) {
- n := network{Name: "default"}
- err := n.loadAttributes()
- c.Assert(err, IsNil)
- c.Assert(n.Name, Equals, "default")
- c.Assert(n.Bridge.Name, Equals, "virbr0")
- c.Assert(n.Ip.Ip, Equals, "192.168.122.1")
- c.Assert(n.Ip.Mask, Equals, "255.255.255.0")
-}
-
-func (s *networkSuite) TestRunning(c *C) {
- n := network{Name: "default"}
- running, err := n.running()
- c.Assert(err, IsNil)
- c.Assert(running, Equals, true)
-
- n = network{Name: "foobar"}
- running, err = n.running()
- c.Assert(err, IsNil)
- c.Assert(running, Equals, false)
-
- n = network{Name: "fakeName"}
- running, err = n.running()
- c.Assert(err, IsNil)
- c.Assert(running, Equals, false)
-}
-
-func (s *networkSuite) TestNetworkExists(c *C) {
- n := network{Name: "default"}
- exists, err := n.exists()
- c.Assert(err, IsNil)
- c.Assert(exists, Equals, true)
-
- n = network{Name: "foobar"}
- exists, err = n.exists()
- c.Assert(err, IsNil)
- c.Assert(exists, Equals, true)
-
- n = network{Name: "fakeName"}
- exists, err = n.exists()
- c.Assert(err, IsNil)
- c.Assert(exists, Equals, false)
-}
-
-func (s *networkSuite) TestListNetworks(c *C) {
- expected := map[string]bool{
- "juju-test": true,
- "foobar": false,
- "default": true,
- }
- networks, err := listNetworks()
- c.Assert(err, IsNil)
- c.Assert(networks, DeepEquals, expected)
-}
-
-func writeScript(c *C, dir string) {
- f, err := os.OpenFile(dir+"/virsh", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
- c.Assert(err, IsNil)
- defer f.Close()
- _, err = f.WriteString(scriptText)
- c.Assert(err, IsNil)
-}