Esempio n. 1
0
// Delete a role.
func (r *Role) Delete() error {
	if config.UsingDB() {
		if err := r.deleteSQL(); err != nil {
			return err
		}
	} else {
		ds := datastore.New()
		ds.Delete("role", r.Name)
	}
	indexer.DeleteItemFromCollection("role", r.Name)
	return nil
}
Esempio n. 2
0
// Delete the environment, returning an error if you try to delete the
// "_default" environment.
func (e *ChefEnvironment) Delete() error {
	if e.Name == "_default" {
		err := fmt.Errorf("The '_default' environment cannot be modified.")
		return err
	}
	if config.UsingDB() {
		if err := e.deleteEnvironmentSQL(); err != nil {
			return nil
		}
	} else {
		ds := datastore.New()
		ds.Delete("env", e.Name)
	}
	indexer.DeleteItemFromCollection("environment", e.Name)
	return nil
}
Esempio n. 3
0
// Delete the node.
func (n *Node) Delete() error {
	if config.UsingDB() {
		if err := n.deleteSQL(); err != nil {
			return err
		}
	} else {
		ds := datastore.New()
		ds.Delete("node", n.Name)
		// TODO: This may need a different config flag?
		if config.Config.UseSerf {
			n.deleteStatuses()
		}
	}
	indexer.DeleteItemFromCollection("node", n.Name)
	return nil
}
Esempio n. 4
0
// Delete a client, but will refuse to do so if it is the last client
// that is an adminstrator.
func (c *Client) Delete() error {
	// Make sure this isn't the last admin or something
	// This will be a *lot* easier with an actual database.
	if c.isLastAdmin() {
		err := fmt.Errorf("Cannot delete the last admin")
		return err
	}

	if config.UsingDB() {
		err := c.deleteSQL()
		if err != nil {
			return err
		}
	} else {
		ds := datastore.New()
		ds.Delete("client", c.Name)
	}
	indexer.DeleteItemFromCollection("client", c.Name)
	return nil
}
Esempio n. 5
0
// DeleteDBItem deletes a data bag item.
func (db *DataBag) DeleteDBItem(dbItemName string) error {
	if config.UsingDB() {
		dbi, err := db.GetDBItem(dbItemName)
		if err != nil {
			return err
		}
		err = dbi.deleteDBItemSQL()
		if err != nil {
			return err
		}
	} else {
		delete(db.DataBagItems, dbItemName)
	}
	err := db.Save()
	if err != nil {
		return err
	}
	indexer.DeleteItemFromCollection(db.Name, dbItemName)
	return nil
}