Exemplo n.º 1
0
Arquivo: add.go Projeto: makyo/juju
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)
	}
	personalClouds, err := cloud.PersonalCloudMetadata()
	if err != nil {
		return err
	}
	if _, ok = personalClouds[c.Cloud]; ok && !c.Replace {
		return errors.Errorf("cloud called %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)
}
Exemplo n.º 2
0
func (s *restoreSuite) SetUpTest(c *gc.C) {
	s.BaseBackupsSuite.SetUpTest(c)
	clouds := map[string]cloud.Cloud{
		"mycloud": {
			Type:      "openstack",
			AuthTypes: []cloud.AuthType{"userpass", "access-key"},
			Endpoint:  "http://homestack",
			Regions: []cloud.Region{
				{Name: "a-region", Endpoint: "http://london/1.0"},
			},
		},
	}
	err := cloud.WritePersonalCloudMetadata(clouds)
	c.Assert(err, jc.ErrorIsNil)

	s.store = jujuclienttesting.NewMemStore()
	s.store.Controllers["testing"] = jujuclient.ControllerDetails{
		ControllerUUID:         "deadbeef-0bad-400d-8000-5b1d0d06f00d",
		CACert:                 testing.CACert,
		Cloud:                  "mycloud",
		CloudRegion:            "a-region",
		APIEndpoints:           []string{"10.0.1.1:17777"},
		UnresolvedAPIEndpoints: []string{"10.0.1.1:17777"},
	}
	s.store.CurrentControllerName = "testing"
	s.store.Models["testing"] = &jujuclient.ControllerModels{
		Models: map[string]jujuclient.ModelDetails{
			"admin": {"test1-uuid"},
		},
		CurrentModel: "admin",
	}
	s.store.Accounts["testing"] = jujuclient.AccountDetails{
		User:     "******",
		Password: "******",
	}
	s.store.BootstrapConfig["testing"] = jujuclient.BootstrapConfig{
		Cloud:       "mycloud",
		CloudType:   "dummy",
		CloudRegion: "a-region",
		Config: map[string]interface{}{
			"type": "dummy",
			"name": "admin",
		},
		ControllerModelUUID: testing.ModelTag.Id(),
		ControllerConfig: controller.Config{
			"api-port":   17070,
			"state-port": 37017,
		},
	}
	s.store.Credentials["dummy"] = cloud.CloudCredential{
		AuthCredentials: map[string]cloud.Credential{
			"me": cloud.NewCredential(cloud.UserPassAuthType, map[string]string{
				"username": "******",
				"password": "******",
			}),
		},
	}
}
Exemplo n.º 3
0
func (s *personalCloudSuite) TestWritePersonalClouds(c *gc.C) {
	clouds := map[string]cloud.Cloud{
		"homestack": cloud.Cloud{
			Type:      "openstack",
			AuthTypes: []cloud.AuthType{"userpass", "access-key"},
			Endpoint:  "http://homestack",
			Regions: []cloud.Region{
				cloud.Region{Name: "london", Endpoint: "http://london/1.0"},
			},
		},
		"azurestack": cloud.Cloud{
			Type:      "azure",
			AuthTypes: []cloud.AuthType{"userpass"},
			Regions: []cloud.Region{{
				Name:     "prod",
				Endpoint: "http://prod.azurestack.local",
			}, {
				Name:     "dev",
				Endpoint: "http://dev.azurestack.local",
			}, {
				Name:     "test",
				Endpoint: "http://test.azurestack.local",
			}},
		},
	}
	err := cloud.WritePersonalCloudMetadata(clouds)
	c.Assert(err, jc.ErrorIsNil)
	data, err := ioutil.ReadFile(osenv.JujuXDGDataHomePath("clouds.yaml"))
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(string(data), gc.Equals, `
clouds:
  azurestack:
    type: azure
    auth-types: [userpass]
    regions:
      prod:
        endpoint: http://prod.azurestack.local
      dev:
        endpoint: http://dev.azurestack.local
      test:
        endpoint: http://test.azurestack.local
  homestack:
    type: openstack
    auth-types: [userpass, access-key]
    endpoint: http://homestack
    regions:
      london:
        endpoint: http://london/1.0
`[1:])
}
Exemplo n.º 4
0
Arquivo: remove.go Projeto: bac/juju
func (c *removeCloudCommand) Run(ctxt *cmd.Context) error {
	personalClouds, err := cloud.PersonalCloudMetadata()
	if err != nil {
		return err
	}
	if _, ok := personalClouds[c.Cloud]; !ok {
		ctxt.Infof("No personal cloud called %q exists", c.Cloud)
		return nil
	}
	delete(personalClouds, c.Cloud)
	if err := cloud.WritePersonalCloudMetadata(personalClouds); err != nil {
		return errors.Trace(err)
	}
	ctxt.Infof("Removed details of personal cloud %q", c.Cloud)
	return nil
}
Exemplo n.º 5
0
Arquivo: add.go Projeto: bac/juju
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)
}