f5 iControl LX Development Kit
The purpose of this project is to streamline the initial steps in creating and deploying a new iControl LX Extension. icrdk provides a CLI utility for initializing, building, and deploying Node.js code on BIG-IP. It can also be also be used as a module for other Node.js applications that manage iControl LX packages.
This dev kit enables the following options on the command line or within a Node.js application:
init
- Creates folder structure and RPM Spec file for a new iControl LX Extensionbuild
- Builds an RPM package for installation on BIG-IPdeploy
- Automatically uploads and installs an iControl LX Extension RPM on BIG-IPquery
- Query installed iControl LX Extensionsuninstall
- Uninstall iControl LX Extensions by package name (obtained byquery
)
icrdk has commands to initialize, build, and deploy a project to a BIG-IP.
Prerequisite:
rpmbuild
must be installed on the machine where it is being used.
Install:
npm install icrdk@https://github.com/f5devcentral/f5-icontrollx-dev-kit.git
Use the -g flag to add icrdk
to your path and have it globally available.
Follow the installation directions above.
$ mkdir project_name
$ cd project_name
$ icrdk init
## edit project files inside src/nodejs
$ icrdk build
## edit devconfig.json to configure target BIG-IP and auth credentials
$ icrdk deploy
## test your deployed application!
Once the icrdk command is aliased or added to your path, you are ready to create and deploy a new iControl LX Extension.
To initialize a new project, create a new directory and initialize te project inside that directory:
$ mkdir hello_world
$ cd hello_world
$ icrdk init
This will create the appropriate file hierarchy, create some basic configuration files, and run npm init.
./f5-project.spec ## RPM spec file for building deployment package, populated with information from package.json
./devconfig.json ## development config file for specifying target dev BIG-IP and credentials usd by CLI utility
./src ## this is the root directory of the extension, and the structure inside should confirm to the iControlLX Extension specificaton
./src/nodejs
./src/nodejs/skeletonWorker.js ## A basic rest worker example, this can be modified or deleted
./src/nodejs/package.json ## package.json created by npm, dependant modules should be installed within this directory
The devconfig.json file looks like this, and may be different for each developer. This file should not be committed to your VCS/SCM as it contains credential information. The first time you create a project on a new development machine, this file will need to be created or populated.
{
"HOST": "(Required) IP address or DNS name of your target BIG-IP",
"USER": "(Required) BIG-IP basic auth username",
"PASS": "(Required) BIG-IP basic auth password",
"PORT": "(Optional) BIG-IP managment port, default is 443"
}
Alternatively, you can specify these parameters as environment variables. This may be useful for CI/CD flows. If the devconfig file exists, these variables will be ignored.
ICRDK_HOST
ICRDK_USER
ICRDK_PASS
An example rest worker is added to the project, skeleton worker, this file can be modified to fit your needs, used as reference, or discarded altogether. When deployed, it will add a new rest endpoint at /mgmt/shared/hello
by default.
Once you are ready to run your project on a BIG-IP, you can build a deployable RPM with:
icrdk build
This will build an rpm and output it to a build/
folder within your directory. By default, rpms are versioned using a unix timestamp.
After the project is successfully built, it can be deployed to a BIG-IP by typing:
icrdk deploy
Now you can use your favorite HTTP client to test your new endpoint.
when used with no arguments, deploy
will look inside the ./build
directory where it is run, and copy and install the newest RPM to a BIG-IP configured in devconfig.json
.
The deploy
target can also be used to install any arbitrary RPM by specifying it at the command line like so:
icrdk deploy /path/to/your/package.rpm
icrdk query
will list the packages installed on the configured BIG-IP. These package names can be passd to icrdk uninstall
to remove them from a BIG-IP.
Packages can be uninstalled using the icrdk uninstall
command. Removing a package can be achievd by passing a package name from icrdk query
to the uninstall
target like so:
icrdk uninstall package.noarch
In addition to command line use, the icrdk package can be used as a node module in other applications.
npm install icrdk@https://github.com/f5devcentral/f5-icontrollx-dev-kit.git
path
- a string specifying the location of the new projectcallback(error)
- invoked when finishederror
- contains error object, or null on success
This function will copy project files, create folders, and invoke npm init
inside ./src/nodejs
const icrdk = require('icrdk')
// initialize a project in the current working directory
const initPath = process.cwd();
icrdk.initializeProject(initPath, (err) => {
if (err)
console.error(err)
else
console.log(`New project initialized at ${initPath}`);
} );
path
- path to directory to invoke rpmbuildopts
- optionally specify rpm optionsrpmSpecfile
- rpm.spec
file to use, defaults tof5-project.spec
destDir
- destination where new RPM will be copied, defaults to${path}/build
callback(error)
- invoked when finishederror
- contains error object, or null on sucessstdout
- stdout from the rpmbuild process
This function will invoke rpmbuild using the default spec file, or the spec file specified in the options. The resulting rpm will placed in ./build
, or the directory specified in opts.
// build an rpm using the default spec file in cwd
const path = process.cwd();
icrdk.buildRpm(rpmPath, (err, stdout) => {
if (err) {
console.error(err)
} else {
console.log(stdout);
console.log(`New RPM copied to ${initPath}/build`);
}
});
config
- config object containing HOST, USER, and PASS for HTTP using basic authfilename
- filename of the RPM to deploycallback(error)
- called upon error, or successful deploymenterror
- error object, or null on success
returns EventEmitter
with the following events:
progress
- fired when a chunk is uploaded to a BIG-IPmsg
- file upload progress information
This function will upload and install an iControl LX extension RPM to a BIG-IP specified in the config object.
// Upload an RPM to a host BIG-IP
const opts = {
HOST: "127.0.0.1",
USER: "admin",
PASS: "admin",
AUTH_TOKEN: "token" // optional, use instead of USER/PASS
}
// Using and install a local RPM
const rpmPath = '/local/path/to/project.rpm'
icrdk.deployToBigIp(opts, rpmPath, );
config
- BIG-IP location and user credentialscallback(results)
- called when finishedresults
- contains query results
This function queries a BIG-IP for installed packages.
// list installed packages
icrdk.queryInstalledPackages(opts, (queryResults) => {
console.log(queryResults);
});
config
- BIG-IP location and user credentialspackageName
- package on BIG-IP to remove, can be fetched with query. Usually has a.noarch
extension.callback(error)
- called on error, or when finishederror
- error object when call unsuccessful
This function will uninstall a package from a BIG-IP.
// uninstall packageName, package names available from icrdk.query
const packageName = 'project.noarch'
icrdk.uninstallPackage(opts, packageName);
Applications can be debugged by inspecting logs. By logging into a BIG-IP's bash console, you can read the most recent log with the following commands:
less +F /var/logs/restnoded/restnoded.log
Any javascript errors will be reported here, as well as the output from the f5logger module.
It is possible to use console.log()
for ad hoc debug messages, that information can be read by using:
less +F /var/tmp/restnoded.out
1.0.1
- Renamed package from 'ffdk' to 'icrdk'