Exemplo n.º 1
0
// updateEnvironmentInfo updates the given environment info with the values
// stored in the provided YAML encoded data.
func updateEnvironmentInfo(info configstore.EnvironInfo, data []byte) error {
	var values configstore.EnvironInfoData
	if err := yaml.Unmarshal(data, &values); err != nil {
		return errors.Annotate(err, "cannot unmarshal jenv data")
	}

	// Ensure the required values are present.
	if missing := getMissingEnvironmentInfoFields(values); len(missing) != 0 {
		return errors.Errorf("missing required fields in jenv data: %s", strings.Join(missing, ", "))
	}

	// Update the environment info.
	info.SetAPICredentials(configstore.APICredentials{
		User:     values.User,
		Password: values.Password,
	})
	info.SetAPIEndpoint(configstore.APIEndpoint{
		Addresses: values.StateServers,
		Hostnames: values.ServerHostnames,
		CACert:    values.CACert,
		ModelUUID: values.ModelUUID,
	})
	info.SetBootstrapConfig(values.Config)
	return nil
}
Exemplo n.º 2
0
Arquivo: open.go Projeto: zhouqt/juju
// decorateAndWriteInfo decorates the info struct with information
// from the given cfg, and the writes that out to the filesystem.
func decorateAndWriteInfo(info configstore.EnvironInfo, cfg *config.Config) error {

	// Sanity check our config.
	var endpoint configstore.APIEndpoint
	if cert, ok := cfg.CACert(); !ok {
		return errors.Errorf("CACert is not set")
	} else if uuid, ok := cfg.UUID(); !ok {
		return errors.Errorf("UUID is not set")
	} else if adminSecret := cfg.AdminSecret(); adminSecret == "" {
		return errors.Errorf("admin-secret is not set")
	} else {
		endpoint = configstore.APIEndpoint{
			CACert:      cert,
			EnvironUUID: uuid,
		}
	}

	creds := configstore.APICredentials{
		User:     "******", // TODO(waigani) admin@local once we have that set
		Password: cfg.AdminSecret(),
	}
	info.SetAPICredentials(creds)
	info.SetAPIEndpoint(endpoint)
	info.SetBootstrapConfig(cfg.AllAttrs())

	if err := info.Write(); err != nil {
		return errors.Annotatef(err, "cannot create environment info %q", cfg.Name())
	}

	return nil
}
Exemplo n.º 3
0
// decorateAndWriteInfo decorates the info struct with information
// from the given cfg, and the writes that out to the filesystem.
func decorateAndWriteInfo(info configstore.EnvironInfo, cfg *config.Config) error {

	// Sanity check our config.
	var endpoint configstore.APIEndpoint
	if cert, ok := cfg.CACert(); !ok {
		return errors.Errorf("CACert is not set")
	} else if uuid, ok := cfg.UUID(); !ok {
		return errors.Errorf("UUID is not set")
	} else if adminSecret := cfg.AdminSecret(); adminSecret == "" {
		return errors.Errorf("admin-secret is not set")
	} else {
		endpoint = configstore.APIEndpoint{
			CACert:    cert,
			ModelUUID: uuid,
		}
	}

	creds := configstore.APICredentials{
		User:     configstore.DefaultAdminUsername,
		Password: cfg.AdminSecret(),
	}
	endpoint.ServerUUID = endpoint.ModelUUID
	info.SetAPICredentials(creds)
	info.SetAPIEndpoint(endpoint)
	info.SetBootstrapConfig(cfg.AllAttrs())

	if err := info.Write(); err != nil {
		return errors.Annotatef(err, "cannot create model info %q", cfg.Name())
	}

	return nil
}