本文整理匯總了Golang中github.com/juju/juju/cloud.ParseCloudMetadata函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseCloudMetadata函數的具體用法?Golang ParseCloudMetadata怎麽用?Golang ParseCloudMetadata使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseCloudMetadata函數的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestNewData
func (s *updateCloudsSuite) TestNewData(c *gc.C) {
clouds, err := jujucloud.ParseCloudMetadata([]byte(sampleUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
err = jujucloud.WritePublicCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
newUpdateCloudData := sampleUpdateCloudData + `
anotherregion:
endpoint: http://anotherregion/1.0
`[1:]
ts := s.setupTestServer(c, newUpdateCloudData)
defer ts.Close()
msg := s.run(c, ts.URL, "")
publicClouds, fallbackUsed, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
clouds, err = jujucloud.ParseCloudMetadata([]byte(newUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
c.Assert(publicClouds, jc.DeepEquals, clouds)
c.Assert(msg, gc.Matches, `
Fetching latest public cloud list...
Updated your list of public clouds with 1 cloud region added:
added cloud region:
- aws/anotherregion
`[1:])
}
示例2: assertCompareClouds
func (s *cloudSuite) assertCompareClouds(c *gc.C, meta2 string, expected bool) {
meta1 := `
clouds:
aws-me:
type: aws
auth-types: [ userpass ]
`[1:]
if meta2 == "" {
meta2 = meta1
}
c1, err := cloud.ParseCloudMetadata([]byte(meta1))
c.Assert(err, jc.ErrorIsNil)
c2, err := cloud.ParseCloudMetadata([]byte(meta2))
c.Assert(err, jc.ErrorIsNil)
result, err := cloud.IsSameCloudMetadata(c1, c2)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.Equals, expected)
}
示例3: TestGeneratedPublicCloudInfo
func (s *cloudSuite) TestGeneratedPublicCloudInfo(c *gc.C) {
cloudData, err := ioutil.ReadFile("fallback-public-cloud.yaml")
c.Assert(err, jc.ErrorIsNil)
clouds, err := cloud.ParseCloudMetadata(cloudData)
c.Assert(err, jc.ErrorIsNil)
generatedClouds := parsePublicClouds(c)
c.Assert(clouds, jc.DeepEquals, generatedClouds)
}
示例4: TestNoNewData
func (s *updateCloudsSuite) TestNoNewData(c *gc.C) {
clouds, err := jujucloud.ParseCloudMetadata([]byte(sampleUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
err = jujucloud.WritePublicCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
ts := s.setupTestServer(c, sampleUpdateCloudData)
defer ts.Close()
msg := s.run(c, ts.URL, "")
c.Assert(strings.Replace(msg, "\n", "", -1), gc.Matches, "Fetching latest public cloud list...Your list of public clouds is up to date, see `juju clouds`.")
}
示例5: TestNewData
func (s *updateCloudsSuite) TestNewData(c *gc.C) {
clouds, err := jujucloud.ParseCloudMetadata([]byte(sampleUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
err = jujucloud.WritePublicCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
newUpdateCloudData := sampleUpdateCloudData + `
anotherregion:
endpoint: http://anotherregion/1.0
`[1:]
ts := s.setupTestServer(c, newUpdateCloudData)
defer ts.Close()
s.run(c, ts.URL, "")
publicClouds, fallbackUsed, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
clouds, err = jujucloud.ParseCloudMetadata([]byte(newUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
c.Assert(publicClouds, jc.DeepEquals, clouds)
}
示例6: TestFirstRun
func (s *updateCloudsSuite) TestFirstRun(c *gc.C) {
ts := s.setupTestServer(c, sampleUpdateCloudData)
defer ts.Close()
s.run(c, ts.URL, "")
publicClouds, fallbackUsed, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
clouds, err := jujucloud.ParseCloudMetadata([]byte(sampleUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
c.Assert(publicClouds, jc.DeepEquals, clouds)
}
示例7: TestNoNewData
func (s *updateCloudsSuite) TestNoNewData(c *gc.C) {
clouds, err := jujucloud.ParseCloudMetadata([]byte(sampleUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
err = jujucloud.WritePublicCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
ts := s.setupTestServer(c, sampleUpdateCloudData)
defer ts.Close()
msg := s.run(c, ts.URL, "")
c.Assert(msg, gc.Matches, ".*no new public cloud information available at this time.*")
}
示例8: TestListPreservesRegionOrder
func (s *showSuite) TestListPreservesRegionOrder(c *gc.C) {
ctx, err := testing.RunCommand(c, cloud.NewListCloudsCommand(), "--format", "yaml")
c.Assert(err, jc.ErrorIsNil)
lines := strings.Split(testing.Stdout(ctx), "\n")
withClouds := "clouds:\n " + strings.Join(lines, "\n ")
parsedClouds, err := jujucloud.ParseCloudMetadata([]byte(withClouds))
c.Assert(err, jc.ErrorIsNil)
parsedCloud, ok := parsedClouds["aws"]
c.Assert(ok, jc.IsTrue) // aws found in output
aws, err := jujucloud.CloudByName("aws")
c.Assert(err, jc.ErrorIsNil)
c.Assert(&parsedCloud, jc.DeepEquals, aws)
}
示例9: Run
func (c *updateCloudsCommand) Run(ctxt *cmd.Context) error {
fmt.Fprint(ctxt.Stdout, "Fetching latest public cloud list... ")
client := utils.GetHTTPClient(utils.VerifySSLHostnames)
resp, err := client.Get(c.publicCloudURL)
if err != nil {
return err
}
defer resp.Body.Close()
noNewClouds := "\nno new public cloud information available at this time"
if resp.StatusCode != http.StatusOK {
switch resp.StatusCode {
case http.StatusNotFound:
fmt.Fprintln(ctxt.Stdout, noNewClouds)
return nil
case http.StatusUnauthorized:
return errors.Unauthorizedf("unauthorised access to URL %q", c.publicCloudURL)
}
return fmt.Errorf("cannot read public cloud information at URL %q, %q", c.publicCloudURL, resp.Status)
}
cloudData, err := decodeCheckSignature(resp.Body, c.publicSigningKey)
if err != nil {
return errors.Annotate(err, "error receiving updated cloud data")
}
newPublicClouds, err := jujucloud.ParseCloudMetadata(cloudData)
if err != nil {
return errors.Annotate(err, "invalid cloud data received when updating clouds")
}
currentPublicClouds, _, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
if err != nil {
return errors.Annotate(err, "invalid local public cloud data")
}
sameCloudInfo, err := jujucloud.IsSameCloudMetadata(newPublicClouds, currentPublicClouds)
if err != nil {
// Should never happen.
return err
}
if sameCloudInfo {
fmt.Fprintln(ctxt.Stdout, noNewClouds)
return nil
}
if err := jujucloud.WritePublicCloudMetadata(newPublicClouds); err != nil {
return errors.Annotate(err, "error writing new local public cloud data")
}
fmt.Fprintln(ctxt.Stdout, "done.")
return nil
}
示例10: TestParseCloudsConfig
func (s *cloudSuite) TestParseCloudsConfig(c *gc.C) {
clouds, err := cloud.ParseCloudMetadata([]byte(`clouds:
testing:
type: dummy
config:
k1: v1
k2: 2.0
`))
c.Assert(err, jc.ErrorIsNil)
c.Assert(clouds, gc.HasLen, 1)
testingCloud := clouds["testing"]
c.Assert(testingCloud, jc.DeepEquals, cloud.Cloud{
Type: "dummy",
Config: map[string]interface{}{
"k1": "v1",
"k2": float64(2.0),
},
})
}
示例11: TestParseCloudsRegionConfig
func (s *cloudSuite) TestParseCloudsRegionConfig(c *gc.C) {
clouds, err := cloud.ParseCloudMetadata([]byte(`clouds:
testing:
type: dummy
config:
k1: v1
k2: 2.0
region-config:
region1:
mascot: [eggs, ham]
region2:
mascot: glenda
region3:
mascot: gopher
`))
c.Assert(err, jc.ErrorIsNil)
c.Assert(clouds, gc.HasLen, 1)
testingCloud := clouds["testing"]
c.Assert(testingCloud, jc.DeepEquals, cloud.Cloud{
Type: "dummy",
Config: map[string]interface{}{
"k1": "v1",
"k2": float64(2.0),
},
RegionConfig: cloud.RegionConfig{
"region1": cloud.Attrs{
"mascot": []interface{}{"eggs", "ham"},
},
"region2": cloud.Attrs{
"mascot": "glenda",
},
"region3": cloud.Attrs{
"mascot": "gopher",
},
},
})
}
示例12: TestFirstRun
func (s *updateCloudsSuite) TestFirstRun(c *gc.C) {
// make sure there is nothing
err := jujucloud.WritePublicCloudMetadata(nil)
c.Assert(err, jc.ErrorIsNil)
ts := s.setupTestServer(c, sampleUpdateCloudData)
defer ts.Close()
msg := s.run(c, ts.URL, "")
publicClouds, fallbackUsed, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
clouds, err := jujucloud.ParseCloudMetadata([]byte(sampleUpdateCloudData))
c.Assert(err, jc.ErrorIsNil)
c.Assert(publicClouds, jc.DeepEquals, clouds)
c.Assert(msg, gc.Matches, `
Fetching latest public cloud list...
Updated your list of public clouds with 1 cloud added:
added cloud:
- aws
`[1:])
}
示例13: parsePublicClouds
func parsePublicClouds(c *gc.C) map[string]cloud.Cloud {
clouds, err := cloud.ParseCloudMetadata([]byte(cloud.FallbackPublicCloudInfo))
c.Assert(err, jc.ErrorIsNil)
c.Assert(clouds, gc.HasLen, len(publicCloudNames))
return clouds
}