github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/provider/maas/export_test.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package maas
     5  
     6  import (
     7  	"strings"
     8  
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  	"launchpad.net/gomaasapi"
    12  
    13  	"github.com/juju/juju/cloudconfig/cloudinit"
    14  	"github.com/juju/juju/environs"
    15  	"github.com/juju/juju/environs/storage"
    16  )
    17  
    18  var (
    19  	ShortAttempt            = &shortAttempt
    20  	APIVersion              = apiVersion
    21  	MaasStorageProviderType = maasStorageProviderType
    22  )
    23  
    24  func MAASAgentName(env environs.Environ) string {
    25  	return env.(*maasEnviron).ecfg().maasAgentName()
    26  }
    27  
    28  func GetMAASClient(env environs.Environ) *gomaasapi.MAASObject {
    29  	return env.(*maasEnviron).getMAASClient()
    30  }
    31  
    32  func NewCloudinitConfig(env environs.Environ, hostname, iface, series string) (cloudinit.CloudConfig, error) {
    33  	return env.(*maasEnviron).newCloudinitConfig(hostname, iface, series)
    34  }
    35  
    36  var indexData = `
    37  {
    38   "index": {
    39    "com.ubuntu.cloud:released:maas": {
    40     "updated": "Fri, 14 Feb 2014 13:39:35 +0000",
    41     "cloudname": "maas",
    42     "datatype": "image-ids",
    43     "format": "products:1.0",
    44     "products": [
    45       "com.ubuntu.cloud:server:12.04:amd64"
    46     ],
    47     "path": "streams/v1/com.ubuntu.cloud:released:maas.json"
    48    }
    49   },
    50   "updated": "Fri, 14 Feb 2014 13:39:35 +0000",
    51   "format": "index:1.0"
    52  }
    53  `
    54  
    55  var imagesData = `
    56  {
    57    "content_id": "com.ubuntu.cloud:released:maas",
    58    "format": "products:1.0",
    59    "updated": "Fri, 14 Feb 2014 13:39:35 +0000",
    60    "datatype": "image-ids",
    61    "products": {
    62      "com.ubuntu.cloud:server:12.04:amd64": {
    63        "release": "precise",
    64        "version": "12.04",
    65        "arch": "amd64",
    66        "versions": {
    67          "20140214": {
    68            "items": {
    69              "11223344-0a0a-ff99-11bb-0a1b2c3d4e5f": {
    70                "region": "some-region",
    71                "id": "11223344-0a0a-ff99-11bb-0a1b2c3d4e5f",
    72                "virt": "kvm"
    73              }
    74            },
    75            "pubname": "ubuntu-precise-12.04-amd64-server-20140214",
    76            "label": "release"
    77          }
    78        }
    79      }
    80    }
    81  }
    82  `
    83  
    84  func UseTestImageMetadata(c *gc.C, stor storage.Storage) {
    85  	files := map[string]string{
    86  		"images/streams/v1/index.json":                          indexData,
    87  		"images/streams/v1/com.ubuntu.cloud:released:maas.json": imagesData,
    88  	}
    89  	for f, d := range files {
    90  		rdr := strings.NewReader(d)
    91  		err := stor.Put(f, rdr, int64(len(d)))
    92  		c.Assert(err, jc.ErrorIsNil)
    93  	}
    94  }