Beispiel #1
0
// UpdateModel implements ModelUpdater.
func (c *MemStore) UpdateModel(controller, account, model string, details jujuclient.ModelDetails) error {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelName(model); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelDetails(details); err != nil {
		return err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		controllerAccountModels.AccountModels = make(map[string]*jujuclient.AccountModels)
		c.Models[controller] = controllerAccountModels
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		accountModels = &jujuclient.AccountModels{
			Models: make(map[string]jujuclient.ModelDetails),
		}
		controllerAccountModels.AccountModels[account] = accountModels
	}
	accountModels.Models[model] = details
	return nil
}
Beispiel #2
0
// SetCurrentModel implements ModelUpdater.
func (c *MemStore) SetCurrentModel(controllerName, accountName, modelName string) error {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return errors.Trace(err)
	}
	if err := jujuclient.ValidateAccountName(accountName); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelName(modelName); err != nil {
		return errors.Trace(err)
	}
	controllerAccountModels, ok := c.Models[controllerName]
	if !ok {
		return errors.NotFoundf("models for controller %s", controllerName)
	}
	accountModels, ok := controllerAccountModels.AccountModels[accountName]
	if !ok {
		return errors.NotFoundf(
			"models for account %s on controller %s",
			accountName, controllerName,
		)
	}
	if _, ok := accountModels.Models[modelName]; !ok {
		return errors.NotFoundf("model %s:%s:%s", controllerName, accountName, modelName)
	}
	accountModels.CurrentModel = modelName
	return nil
}
Beispiel #3
0
// UpdateAccount implements AccountUpdater.
func (c *MemStore) UpdateAccount(controllerName, accountName string, details jujuclient.AccountDetails) error {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountName(accountName); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountDetails(details); err != nil {
		return err
	}
	accounts, ok := c.Accounts[controllerName]
	if !ok {
		accounts = &jujuclient.ControllerAccounts{
			Accounts: make(map[string]jujuclient.AccountDetails),
		}
		c.Accounts[controllerName] = accounts
	}
	if len(accounts.Accounts) > 0 {
		if _, ok := accounts.Accounts[accountName]; !ok {
			return errors.AlreadyExistsf(
				"alternative account for controller %s",
				controllerName,
			)
		}
	}
	accounts.Accounts[accountName] = details
	return nil

}
Beispiel #4
0
// RemoveModel implements ModelRemover.
func (c *MemStore) RemoveModel(controller, account, model string) error {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelName(model); err != nil {
		return err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		return errors.NotFoundf("models for controller %s", controller)
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		return errors.NotFoundf(
			"models for account %s on controller %s",
			account, controller,
		)
	}
	if _, ok := accountModels.Models[model]; !ok {
		return errors.NotFoundf("model %s:%s:%s", controller, account, model)
	}
	delete(accountModels.Models, model)
	if accountModels.CurrentModel == model {
		accountModels.CurrentModel = ""
	}
	return nil
}
Beispiel #5
0
// ControllerByName implements ControllerGetter.ControllerByName
func (c *MemStore) ControllerByName(name string) (*jujuclient.ControllerDetails, error) {
	if err := jujuclient.ValidateControllerName(name); err != nil {
		return nil, err
	}
	if result, ok := c.Controllers[name]; ok {
		return &result, nil
	}
	return nil, errors.NotFoundf("controller %s", name)
}
Beispiel #6
0
// UpdateController implements ControllerUpdater.UpdateController
func (c *MemStore) UpdateController(name string, one jujuclient.ControllerDetails) error {
	if err := jujuclient.ValidateControllerName(name); err != nil {
		return err
	}
	if err := jujuclient.ValidateControllerDetails(one); err != nil {
		return err
	}
	c.Controllers[name] = one
	return nil
}
Beispiel #7
0
// AllAccounts implements AccountGetter.
func (c *MemStore) AllAccounts(controllerName string) (map[string]jujuclient.AccountDetails, error) {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return nil, err
	}
	accounts, ok := c.Accounts[controllerName]
	if !ok {
		return nil, errors.NotFoundf("accounts for controller %s", controllerName)
	}
	return accounts.Accounts, nil
}
Beispiel #8
0
// UpdateBootstrapConfig implements BootstrapConfigUpdater.
func (c *MemStore) UpdateBootstrapConfig(controllerName string, cfg jujuclient.BootstrapConfig) error {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return err
	}
	if err := jujuclient.ValidateBootstrapConfig(cfg); err != nil {
		return err
	}
	c.BootstrapConfig[controllerName] = cfg
	return nil

}
Beispiel #9
0
// CurrentAccount implements AccountGetter.
func (c *MemStore) CurrentAccount(controllerName string) (string, error) {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return "", err
	}
	accounts, ok := c.Accounts[controllerName]
	if !ok {
		return "", errors.NotFoundf("accounts for controller %s", controllerName)
	}
	if accounts.CurrentAccount == "" {
		return "", errors.NotFoundf("current account for controller %s", controllerName)
	}
	return accounts.CurrentAccount, nil
}
Beispiel #10
0
// Init implements Command.Init.
func (c *unregisterCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.New("controller name must be specified")
	}
	c.controllerName, args = args[0], args[1:]

	if err := jujuclient.ValidateControllerName(c.controllerName); err != nil {
		return err
	}

	if err := cmd.CheckEmpty(args); err != nil {
		return err
	}
	return nil
}
Beispiel #11
0
// AllModels implements ModelGetter.
func (c *MemStore) AllModels(controller, account string) (map[string]jujuclient.ModelDetails, error) {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return nil, err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return nil, err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		return nil, errors.NotFoundf("models for controller %s", controller)
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		return nil, errors.NotFoundf("models for account %s on controller %s", account, controller)
	}
	return accountModels.Models, nil
}
Beispiel #12
0
// SetCurrentAccount implements AccountUpdater.
func (c *MemStore) SetCurrentAccount(controllerName, accountName string) error {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountName(accountName); err != nil {
		return err
	}
	accounts, ok := c.Accounts[controllerName]
	if !ok {
		return errors.NotFoundf("accounts for controller %s", controllerName)
	}
	if _, ok := accounts.Accounts[accountName]; !ok {
		return errors.NotFoundf("account %s:%s", controllerName, accountName)
	}
	accounts.CurrentAccount = accountName
	return nil
}
Beispiel #13
0
// AccountByName implements AccountGetter.
func (c *MemStore) AccountByName(controllerName, accountName string) (*jujuclient.AccountDetails, error) {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return nil, err
	}
	if err := jujuclient.ValidateAccountName(accountName); err != nil {
		return nil, err
	}
	accounts, ok := c.Accounts[controllerName]
	if !ok {
		return nil, errors.NotFoundf("accounts for controller %s", controllerName)
	}
	details, ok := accounts.Accounts[accountName]
	if !ok {
		return nil, errors.NotFoundf("account %s:%s", controllerName, accountName)
	}
	return &details, nil
}
Beispiel #14
0
// RemoveController implements ControllerRemover.RemoveController
func (c *MemStore) RemoveController(name string) error {
	if err := jujuclient.ValidateControllerName(name); err != nil {
		return err
	}
	names := set.NewStrings(name)
	if namedControllerDetails, ok := c.Controllers[name]; ok {
		for name, details := range c.Controllers {
			if details.ControllerUUID == namedControllerDetails.ControllerUUID {
				names.Add(name)
			}
		}
	}
	for _, name := range names.Values() {
		delete(c.Models, name)
		delete(c.Accounts, name)
		delete(c.BootstrapConfig, name)
		delete(c.Controllers, name)
	}
	return nil
}
Beispiel #15
0
// CurrentModel implements ModelGetter.
func (c *MemStore) CurrentModel(controller, account string) (string, error) {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return "", err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return "", err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		return "", errors.NotFoundf("models for controller %s", controller)
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		return "", errors.NotFoundf("models for account %s on controller %s", account, controller)
	}
	if accountModels.CurrentModel == "" {
		return "", errors.NotFoundf("current model for account %s on controller %s", account, controller)
	}
	return accountModels.CurrentModel, nil
}
Beispiel #16
0
// ModelByName implements ModelGetter.
func (c *MemStore) ModelByName(controller, account, model string) (*jujuclient.ModelDetails, error) {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return nil, err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return nil, err
	}
	if err := jujuclient.ValidateModelName(model); err != nil {
		return nil, err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		return nil, errors.NotFoundf("models for controller %s", controller)
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		return nil, errors.NotFoundf("models for account %s on controller %s", account, controller)
	}
	details, ok := accountModels.Models[model]
	if !ok {
		return nil, errors.NotFoundf("model %s:%s:%s", controller, account, model)
	}
	return &details, nil
}
func (s *ControllerValidationSuite) TestValidateControllerName(c *gc.C) {
	c.Assert(jujuclient.ValidateControllerName(""), gc.ErrorMatches, "empty controller name not valid")
}