API Docs for:
Show:

FakeBackend Class

Module: env.fakebackend
Parent Module: env

An in-memory fake Juju backend.

Methods

_getAnnotationGroup

(
  • entity
)
String

Helper method to determine where to log annotation changes relative to a given entity.

Parameters:

  • entity Object

    to track.

Returns:

String: Annotation group name (index into this.annotations).

_getAvailableMachines

() Array

Find machines without any units currently assigned.

Returns:

Array: An array of zero or more machines that have been previously allocated but that are not currently in use by a unit.

_getCharmFromData

(
  • data
)
Object

Convert charm data as returned by the charmStore into a charm. The charm might be pre-existing or might need to be created, but after this method it will be within the db.

Parameters:

  • data Object

    The raw charm information as delivered by the charmStore's loadByPath method.

Returns:

Object: A matching charm from the db.

_getUnitMachines

(
  • count
)
Array

Find or allocate machines for the requested number of units.

Parameters:

  • count Integer

    The number of units that need machines.

Returns:

Array: An array of [count] machines.

_loadCharm

(
  • charmUrl
  • callbacks
)
Undefined

Get a charm from a URL, via charmStore and/or db. Uses callbacks.

Parameters:

  • charmUrl String

    The URL of the charm.

  • callbacks Function

    An optional object with optional success and failure callables. This is asynchronous because we often must go over the network to the charm store. The success callable receives the fully loaded charm, and the failure callable receives an object with an explanatory "error" attribute.

Returns:

Undefined: Use the callbacks to handle success or failure.

_resetAnnotations

() Undefined

Reset the database for reporting object annotation changes.

Returns:

Undefined: Nothing.

_resetChanges

() Undefined

Reset the database for reporting object changes.

Returns:

Undefined: Nothing.

addRelation

(
  • endpointA
  • endpointB
)

Add a relation between two services.

Parameters:

  • endpointA String

    A string representation of the service name and endpoint connection type ie) wordpress:db.

  • endpointB String

    A string representation of the service name and endpoint connection type ie) wordpress:db.

addUnit

(
  • serviceName
  • numUnits
)
Object

Add units to the given service.

Parameters:

  • serviceName String

    The name of the service to be scaled up.

  • numUnits Integer

    The number of units to be added, defaulting to 1.

Returns:

Object: Returns an object either with an "error" attribute containing a string describing the problem, or with a "units" attribute containing a list of the added units.

deploy

(
  • charmUrl
  • callback
  • options
)
Undefined

Deploy a charm. Uses a callback for response!

Parameters:

  • charmUrl String

    The URL of the charm.

  • callback Function

    A call that will receive an object either with an "error" attribute containing a string describing the problem, or with a "service" attribute containing the new service, a "charm" attribute containing the charm used, and a "units" attribute containing a list of the added units. This is asynchronous because we often must go over the network to the charm store.

  • options Object

    An options object. name: The name of the service to be deployed, defaulting to the charm name. config: The charm configuration options, defaulting to none. configYAML: The charm configuration options, expressed as a YAML string. You may provide only one of config or configYAML. unitCount: The number of units to be deployed.

Returns:

Undefined: Get the result from the callback.

destroyService

(
  • serviceName
)
Object

Destroy the named service.

Parameters:

  • serviceName String

    to destroy.

Returns:

Object: results With err and service_name.

expose

(
  • serviceName
)
Object

Exposes a service from the supplied string.

Parameters:

  • serviceName String

    The service name.

Returns:

Object: An object containing an error and warning properties which will be undefined if there were no warnings or errors.

findMatch

(
  • endpoints
)
Object

Loops through the charm endpoint data to determine whether we have a relationship match. The result is either an object with an error attribute, or an object giving the interface, scope, providing endpoint, and requiring endpoint.

Parameters:

  • endpoints Array

    Pair of two endpoint data objects. Each endpoint data object has name, charm, service, and scope.

Returns:

Object: A hash with the keys 'interface', 'scope', 'provides', and 'requires'.

getAnnotations

(
  • entityName
)
Object

getAnnotations from an object. This uses standard name resolution (see db.resolveModelByName) to determine which object to return annotations for.

Parameters:

  • entityName String

    to get annotations for.

Returns:

Object: annotations as key/value map.

getCharm

(
  • charmName
)
Object

Get Charm data.

Parameters:

  • charmName String

    to get.

Returns:

Object: charm attrs..

getService

(
  • serviceName
)
Object

Get service attributes.

Parameters:

  • serviceName String

    to get.

Returns:

Object: Service Attributes..

initializer

() Undefined

Initializes.

Returns:

Undefined: Nothing.

login

(
  • username
  • submittedPassword
)
Bool

Attempt to log a user in.

Parameters:

  • username String

    The id of the user.

  • submittedPassword String

    The user-submitted password.

Returns:

Bool: True if the authentication was successful.

newEnvironment

(
  • options
  • apiBackend
)
Object static

Provided by the env module.

Defined in app/store/env/env.js:14

Create and return a store environment suitable for connecting to the provided API backend.

Parameters:

  • options Object

    Attributes used for instantiating the environment.

  • apiBackend String

    The name of the API backend this environment connects to.

Returns:

Object: The environment instance.

nextAnnotations

() Object

Return all of the recently anotated objects.

Returns:

Object: A hash of the keys 'services', 'machines', 'units', 'relations' and 'annotations'. Each of those are hashes from entity identifier to [entity, boolean] where the boolean means either active (true) or removed (false).

nextChanges

() Object

Return all of the recently changed objects.

Returns:

Object: A hash of the keys 'services', 'machines', 'units' and 'relations'. Each of those are hashes from entity identifier to [entity, boolean] where the boolean means either active (true) or removed (false).

parseEndpointStrings

(
  • endpoints
)
Object

Takes two string endpoints and splits it into usable parts.

Parameters:

  • endpoints Array

    an array of endpoint strings to split in the format wordpress:db.

Returns:

Object: A hash with four keys: service (the associated service model), charm (the associated charm model for the service), name (the user-defined service name), and type (the charm-author-defined relation type name).

removeAnnotations

(
  • entityName
  • keys
)
Undefined

Remove annotations (optional by key) from an entity.

Parameters:

  • entityName String

    to remove annotations from.

  • keys Array

    (optional) array of {String} keys to remove. If this is falsey all annotations are removed.

Returns:

Undefined: side effects only.

removeRelation

(
  • endpointA
  • endpointB
)

Removes a relation between two services.

Parameters:

  • endpointA String

    A string representation of the service name and endpoint connection type ie) wordpress:db.

  • endpointB String

    A string representation of the service name and endpoint connection type ie) wordpress:db.

removeUnits

(
  • unitNames
)

Removes the supplied units

Parameters:

  • unitNames Array

    a list of unit names to be removed.

resolved

(
  • unitName
  • (optional)
)
Object

Mark a unit or a unit relation as resolved. In the fakebackend this validates arguments but doesn't take any real action.

Parameters:

  • unitName String

    tp resp;ve.

  • (optional) String

    relationName to resolve for unit.

Returns:

Object: with result or error.

setConfig

(
  • serviceName
  • config
)

Sets the configuration settings on the supplied service to the supplied config object while leaving the settings untouched if they are not in the supplied config.

Parameters:

  • serviceName String

    the service id.

  • config Object

    properties to set.

setConstraints

(
  • serviceName
  • data
)

Sets the constraints on a service to restrict the type of machine to be used for the service.

Parameters:

  • serviceName String

    the service id.

  • data Object | Array

    either an array of strings "foo=bar" or an object {foo: 'bar'}.

unexpose

(
  • serviceName
)
Object

Unexposes a service from the supplied string.

Parameters:

  • serviceName String

    The service name.

Returns:

Object: An object containing an error and warning properties which will be undefined if there were no warnings or errors.

updateAnnotations

(
  • entityName
  • annotations
)
Object

Update annotations for a given entity. This performs a merge of existing annotations with any new data.

Parameters:

  • entityName String

    to update.

  • annotations Object

    key/value map.

Returns:

Object: either result or error property.