push2cloud-cf-adapter
This repository is part of the push2cloud project. For contribution guidelines, issues, and general documentation, visit the main push2cloud project page.
push2cloud-cf-adapter abstracts the cloud foundry api.
It's designed for use with Node.js and installable via npm install --save push2cloud-cf-adapter
.
Usage
const cf = ; const api = ; // the callback way...api; // or the promise way...api;
Download
The source is available for download from GitHub. Alternatively, you can install using npm:
npm install --save push2cloud-cf-adapter
You can then require()
push2cloud-cf-adapter as normal:
const cf = ;
Documentation
Each asynchronous call can be done with classical callback style or with promise style.
General
App
createApp
uploadApp
pushApp
stageApp
startApp
stopApp
restartApp
startAppAndWaitForInstances
deleteApp
Route
Service
General
General api methods.
init([callback])
Retrieves information of the current space. i.e. apps, services, service bindings, routes, domains, etc...
Arguments
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
const cf = ; const api = ; api;
getInfo([callback])
Retrieves information of the cloud foundry platform.
Arguments
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
stats.on('retry', [fn])
Will be emitted when an api request will retry.
Arguments
fn(obj)
- A function which is called when an api request will retry.
Example
apistats;
api.attachRetryHandler([fn])
You can attach you own retryHandler for your target.
Arguments
fn(options)
- A function or an array of funcitons which is called to verify if the failed request should be retried. Should returntrue
or astring
to trigger a retry.
Examples
api;
api;
App
App related api methods.
createApp(options, [callback])
Creates an app.
Arguments
options
- An options containing:name
- The app name.buildpack
- Optional Buildpack to build the app. 3 options:- a) Blank or not set means autodetection.
- b) A Git Url pointing to a buildpack.
- c) Name of an installed buildpack.
command
- Optional The command to start an app after it is staged, maximum length: 4096 (e.g. 'rails s -p $PORT' or 'java com.org.Server $PORT').env
- Optional Object containing key/value pairs of all the environment variables to run in your app. Does not include any system or service variables.disk
- Optional The maximum amount of disk available to an instance of an app. i.e. 256MB, 1G, 256, 1024memory
- Optional The amount of memory each instance should have. i.e. 256MB, 1G, 256, 1024instances
- Optional The number of instances of the app to run. To ensure optimal availability, ensure there are at least 2 instances.dockerImage
- Optional Name of the Docker image containing the app.enableSSH
- Optional Enable SSHing into the app. Supported for Diego only. false if SSH is disabled globally or on the space, true if enabled for bothhealthCheckType
- Optional Type of health check to perform. 'port' or 'process'healthCheckTimeout
- Optional Timeout for health checking of an staged app when starting up
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
uploadApp(options, [callback])
Uploads an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.path
- The path to the app on your filesystem.tmpZipPath
- Optional Custom temporary path to save the zip file. Default ispath
+ '.zip.tmp'.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
pushApp(options, [callback])
Creates and uploads an app.
Arguments
options
- See combinedoptions
argument ofcreateApp
anduploadApp
.callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
stageApp(options, [callback])
Stages an app. Creates a droplet so the effective start of that app will be much faster.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.stageTimeout
- Optional Will return if staging duration is longer than that value in seconds. Default is 300.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
startApp(options, [callback])
Starts an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
stopApp(options, [callback])
Stops an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
restartApp(options, [callback])
Restarts an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
startAppAndWaitForInstances(options, [callback])
Starts an app and waits for all instances to run stable.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.startTimeout
- Optional Will return if starting duration is longer than that value in seconds. Default is 30.interval
- Optional The interval in seconds to wait between checking the app instance state. Default is 3.timeout
- Optional Will return if starting duration of a single instance is longer than that value in seconds. Default is 30.gracePeriod
- Optional Period to check and wait for the app instances not crashing. Default is 40.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
deleteApp(options, [callback])
Deletes an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orname
are mandatory but not both.name
- Optional The app name.appGuid
orname
are mandatory but not both.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
Route
Route related api methods.
createRoute(options, [callback])
Creates a route.
Arguments
options
- An options containing:domainGuid
- Optional The app guid.domainGuid
ordomain
are mandatory but not both.domain
- Optional The app name.domainGuid
ordomain
are mandatory but not both.hostname
- The host portion of the route. Required for shared-domains.path
- The path for a route as raw text. 1) Paths must be between 2 and 128 characters 2) Paths must start with a forward slash "/" 3) Paths must not contain a "?"port
- The port of the route. Supported for domains of TCP router groups only.generatePort
- Set totrue
to generate a random port. Defaults tofalse
. Supported for domains for TCP router groups only. Takes precedence over manually specified port.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
associateRoute(options, [callback])
Associates a route to an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orapp
are mandatory but not both.app
- Optional The app name.appGuid
orapp
are mandatory but not both.routeGuid
- Optional The route guid.routeGuid
ordomain
andhostname
are mandatory but not all.domain
- Optional The app name.routeGuid
ordomain
andhostname
are mandatory but not all.hostname
- Optional The host portion of the route. Required for shared-domains.routeGuid
ordomain
andhostname
are mandatory but not all.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
disassociateRoute(options, [callback])
Disassociates a route from an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orapp
are mandatory but not both.app
- Optional The app name.appGuid
orapp
are mandatory but not both.routeGuid
- Optional The route guid.routeGuid
ordomain
andhostname
are mandatory but not all.domain
- Optional The app name.routeGuid
ordomain
andhostname
are mandatory but not all.hostname
- Optional The host portion of the route. Required for shared-domains.routeGuid
ordomain
andhostname
are mandatory but not all.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
deleteRoute(options, [callback])
Deletes a route.
Arguments
options
- An options containing:routeGuid
- Optional The route guid.routeGuid
ordomain
andhostname
are mandatory but not all.domain
- Optional The app name.routeGuid
ordomain
andhostname
are mandatory but not all.hostname
- Optional The host portion of the route. Required for shared-domains.routeGuid
ordomain
andhostname
are mandatory but not all.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
Service
Service related api methods.
createServiceInstance(options, [callback])
Creates a service instance.
Arguments
options
- An options containing:name
- The service instance name.type
- The service type.plan
- The service plan.parameters
- Optional Arbitrary parameters to pass along to the service broker. Must be an object.tags
- Optional An array of strings for the service instance. Max characters: 2048
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
bindService(options, [callback])
Binds a service instance to an app.
Arguments
options
- An options containing:appGuid
- Optional The app guid.appGuid
orapp
are mandatory but not both.app
- Optional The app name.appGuid
orapp
are mandatory but not both.service
- Optional The service instance name.serviceInstanceGuid
orservice
are mandatory but not both.serviceInstanceGuid
- Optional The service instance guid.serviceInstanceGuid
orservice
are mandatory but not both.parameters
- Optional Arbitrary parameters to pass along to the service broker. Must be an object.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
unbindService(options, [callback])
Unbinds a service instance from an app.
Arguments
options
- An options containing:app
- Optional The app name.serviceBindingGuid
orapp
and service` are mandatory but not all.service
- Optional The service instance name.serviceBindingGuid
orapp
and service` are mandatory but not all.serviceBindingGuid
- OptionalserviceBindingGuid
orapp
and service` are mandatory but not all.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;
deleteServiceInstance(options, [callback])
Deletes a service instance.
Arguments
options
- An options containing:name
- Optional The service instance name.serviceInstanceGuid
orname
are mandatory but not both.serviceInstanceGuid
- Optional The service instance guid.serviceInstanceGuid
orname
are mandatory but not both.
callback(err, result)
- A callback which is called when function has finished, or an error occurs.
Example
api;