mongo

package
v0.0.0-...-6337964 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2014 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SharedSecretFile is the name of the Mongo shared secret file
	// located within the Juju data directory.
	SharedSecretFile = "shared-secret"

	// ReplicaSetName is the name of the replica set that juju uses for its
	// state servers.
	ReplicaSetName = "juju"
)
View Source
const SocketTimeout = 21 * time.Second

SocketTimeout should be long enough that even a slow mongo server will respond in that length of time. Since mongo servers ping themselves every 10 seconds, we use a value of just over 2 ping periods to allow for delayed pings due to issues such as CPU starvation etc.

Variables

View Source
var (

	// JujuMongodPath holds the default path to the juju-specific mongod.
	JujuMongodPath = "/usr/lib/juju/bin/mongod"
)

Functions

func DialInfo

func DialInfo(info Info, opts DialOpts) (*mgo.DialInfo, error)

DialInfo returns information on how to dial the state's mongo server with the given info and dial options.

func EnsureAdminUser

func EnsureAdminUser(p EnsureAdminUserParams) (added bool, err error)

EnsureAdminUser ensures that the specified user and password are added to the admin database.

This function will stop the Mongo service if it needs to add the admin user, as it must restart Mongo in --noauth mode.

func EnsureServer

func EnsureServer(dataDir string, namespace string, info params.StateServingInfo) error

EnsureMongoServer ensures that the correct mongo upstart script is installed and running.

This method will remove old versions of the mongo upstart script as necessary before installing the new version.

The namespace is a unique identifier to prevent multiple instances of mongo on this machine from colliding. This should be empty unless using the local provider.

func GenerateSharedSecret

func GenerateSharedSecret() (string, error)

GenerateSharedSecret generates a pseudo-random shared secret (keyfile) for use with Mongo replica sets.

func IsMaster

func IsMaster(session *mgo.Session, obj WithAddresses) (bool, error)

IsMaster returns a boolean that represents whether the given machine's peer address is the primary mongo host for the replicaset

func Path

func Path() (string, error)

Path returns the executable path to be used to run mongod on this machine. If the juju-bundled version of mongo exists, it will return that path, otherwise it will return the command to run mongod from the path.

func RemoveService

func RemoveService(namespace string) error

RemoveService removes the mongoDB upstart service from this machine.

func SelectPeerAddress

func SelectPeerAddress(addrs []network.Address) string

SelectPeerAddress returns the address to use as the mongo replica set peer address by selecting it from the given addresses.

func SelectPeerHostPort

func SelectPeerHostPort(hostPorts []network.HostPort) string

SelectPeerHostPort returns the HostPort to use as the mongo replica set peer by selecting it from the given hostPorts.

func ServiceName

func ServiceName(namespace string) string

ServiceName returns the name of the upstart service config for mongo using the given namespace.

func SetAdminMongoPassword

func SetAdminMongoPassword(session *mgo.Session, user, password string) error

SetAdminMongoPassword sets the administrative password to access a mongo database. If the password is non-empty, all subsequent attempts to access the database must be authorized; otherwise no authorization is required.

func SetMongoPassword

func SetMongoPassword(name, password string, dbs ...*mgo.Database) error

SetMongoPassword sets the mongo password in the specified databases for the given user name. Previous passwords are invalidated.

Types

type DialOpts

type DialOpts struct {
	// Timeout is the amount of time to wait contacting
	// a state server.
	Timeout time.Duration
}

DialOpts holds configuration parameters that control the Dialing behavior when connecting to a state server.

func DefaultDialOpts

func DefaultDialOpts() DialOpts

DefaultDialOpts returns a DialOpts representing the default parameters for contacting a state server.

type EnsureAdminUserParams

type EnsureAdminUserParams struct {
	// DialInfo specifies how to connect to the mongo server.
	DialInfo *mgo.DialInfo
	// Namespace is the agent namespace, used to derive the Mongo service name.
	Namespace string
	// DataDir is the Juju data directory, used to start a --noauth server.
	DataDir string
	// Port is the listening port of the Mongo server.
	Port int
	// User holds the user to log in to the mongo server as.
	User string
	// Password holds the password for the user to log in as.
	Password string
}

type Info

type Info struct {
	// Addrs gives the addresses of the MongoDB servers for the state.
	// Each address should be in the form address:port.
	Addrs []string

	// CACert holds the CA certificate that will be used
	// to validate the state server's certificate, in PEM format.
	CACert string
}

Info encapsulates information about cluster of mongo servers and can be used to make a connection to that cluster.

type WithAddresses

type WithAddresses interface {
	Addresses() []network.Address
}

WithAddresses represents an entity that has a set of addresses. e.g. a state Machine object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL