本文整理汇总了Golang中github.com/juju/juju/cloud.PublicCloudMetadata函数的典型用法代码示例。如果您正苦于以下问题:Golang PublicCloudMetadata函数的具体用法?Golang PublicCloudMetadata怎么用?Golang PublicCloudMetadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PublicCloudMetadata函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getCloudDetails
func getCloudDetails() (map[string]*cloudDetails, error) {
clouds, _, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
if err != nil {
return nil, err
}
details := make(map[string]*cloudDetails)
for name, cloud := range clouds {
cloudDetails := makeCloudDetails(cloud)
details[name] = cloudDetails
}
// Add in built in providers like "lxd" and "manual".
for name, cloud := range common.BuiltInProviders() {
cloudDetails := makeCloudDetails(cloud)
cloudDetails.Source = "built-in"
details[name] = cloudDetails
}
personalClouds, err := jujucloud.PersonalCloudMetadata()
if err != nil {
return nil, err
}
for name, cloud := range personalClouds {
// Add to result with "local:" prefix.
cloudDetails := makeCloudDetails(cloud)
cloudDetails.Source = "local"
details[localPrefix+name] = cloudDetails
}
return details, nil
}
示例3: listCloudDetails
func listCloudDetails() (*cloudList, error) {
clouds, _, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
if err != nil {
return nil, err
}
details := newCloudList()
for name, cloud := range clouds {
cloudDetails := makeCloudDetails(cloud)
details.public[name] = cloudDetails
}
// Add in built in clouds like localhost (lxd).
for name, cloud := range common.BuiltInClouds() {
cloudDetails := makeCloudDetails(cloud)
cloudDetails.Source = "built-in"
details.builtin[name] = cloudDetails
}
personalClouds, err := jujucloud.PersonalCloudMetadata()
if err != nil {
return nil, err
}
for name, cloud := range personalClouds {
cloudDetails := makeCloudDetails(cloud)
cloudDetails.Source = "local"
details.personal[name] = cloudDetails
// Delete any built-in or public clouds with same name.
delete(details.builtin, name)
delete(details.public, name)
}
return details, nil
}
示例4: TestPublicCloudsMetadataFallback
func (s *cloudSuite) TestPublicCloudsMetadataFallback(c *gc.C) {
clouds, fallbackUsed, err := cloud.PublicCloudMetadata("badfile.yaml")
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsTrue)
var cloudNames []string
for name, _ := range clouds {
cloudNames = append(cloudNames, name)
}
c.Assert(cloudNames, jc.SameContents, publicCloudNames)
}
示例5: 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)
}
示例6: assembleClouds
// assembleClouds
func assembleClouds() ([]string, error) {
public, _, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
if err != nil {
return nil, errors.Trace(err)
}
personal, err := jujucloud.PersonalCloudMetadata()
if err != nil {
return nil, errors.Trace(err)
}
return sortClouds(public, common.BuiltInClouds(), personal), nil
}
示例7: allClouds
func (c *detectCredentialsCommand) allClouds() (map[string]jujucloud.Cloud, error) {
clouds, _, err := jujucloud.PublicCloudMetadata(jujucloud.JujuPublicCloudsPath())
if err != nil {
return nil, err
}
personalClouds, err := jujucloud.PersonalCloudMetadata()
if err != nil {
return nil, err
}
for k, v := range personalClouds {
clouds[k] = v
}
return clouds, nil
}
示例8: TestWritePublicCloudsMetadata
func (s *cloudSuite) TestWritePublicCloudsMetadata(c *gc.C) {
clouds := map[string]cloud.Cloud{
"aws-me": cloud.Cloud{
Type: "aws",
AuthTypes: []cloud.AuthType{"userpass"},
},
}
err := cloud.WritePublicCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
publicClouds, fallbackUsed, err := cloud.PublicCloudMetadata(cloud.JujuPublicCloudsPath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
c.Assert(publicClouds, jc.DeepEquals, clouds)
}
示例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: TestWritePublicCloudsMetadata
func (s *cloudSuite) TestWritePublicCloudsMetadata(c *gc.C) {
origHome := osenv.SetJujuXDGDataHome(c.MkDir())
s.AddCleanup(func(*gc.C) { osenv.SetJujuXDGDataHome(origHome) })
clouds := map[string]cloud.Cloud{
"aws-me": cloud.Cloud{
Type: "aws",
AuthTypes: []cloud.AuthType{"userpass"},
},
}
err := cloud.WritePublicCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
publicClouds, fallbackUsed, err := cloud.PublicCloudMetadata(cloud.JujuPublicCloudsPath())
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
c.Assert(publicClouds, jc.DeepEquals, clouds)
}
示例11: 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)
}
示例12: TestPublicCloudsMetadata
func (s *cloudSuite) TestPublicCloudsMetadata(c *gc.C) {
metadata := `
clouds:
aws-me:
type: aws
auth-types: [ userpass ]
`[1:]
dir := c.MkDir()
cloudyamlfile := filepath.Join(dir, "public-clouds.yaml")
err := ioutil.WriteFile(cloudyamlfile, []byte(metadata), 0644)
c.Assert(err, jc.ErrorIsNil)
clouds, fallbackUsed, err := cloud.PublicCloudMetadata(cloudyamlfile)
c.Assert(err, jc.ErrorIsNil)
c.Assert(fallbackUsed, jc.IsFalse)
c.Assert(clouds, jc.DeepEquals, map[string]cloud.Cloud{
"aws-me": cloud.Cloud{
Type: "aws",
AuthTypes: []cloud.AuthType{"userpass"},
},
})
}
示例13: 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:])
}
示例14: Run
func (c *addCloudCommand) Run(ctxt *cmd.Context) error {
specifiedClouds, err := cloud.ParseCloudMetadataFile(c.CloudFile)
if err != nil {
return err
}
if specifiedClouds == nil {
return errors.New("no personal clouds are defined")
}
newCloud, ok := specifiedClouds[c.Cloud]
if !ok {
return errors.Errorf("cloud %q not found in file %q", c.Cloud, c.CloudFile)
}
publicClouds, _, err := cloud.PublicCloudMetadata()
if err != nil {
return err
}
if _, ok = publicClouds[c.Cloud]; ok && !c.Replace {
return errors.Errorf("%q is the name of a public cloud; use --replace to use your cloud definition instead", c.Cloud)
}
builtinClouds := common.BuiltInClouds()
if _, ok = builtinClouds[c.Cloud]; ok && !c.Replace {
return errors.Errorf("%q is the name of a built-in cloud; use --replace to use your cloud definition instead", c.Cloud)
}
personalClouds, err := cloud.PersonalCloudMetadata()
if err != nil {
return err
}
if _, ok = personalClouds[c.Cloud]; ok && !c.Replace {
return errors.Errorf("%q already exists; use --replace to replace this existing cloud", c.Cloud)
}
if personalClouds == nil {
personalClouds = make(map[string]cloud.Cloud)
}
personalClouds[c.Cloud] = newCloud
return cloud.WritePersonalCloudMetadata(personalClouds)
}