JS Jujulib
This project provides a JavaScript API client library for interacting with the Juju
WebSocket API.
Getting Started
To access the Juju API, a connection must be made to either a Juju
controller or a Juju model.
import { connect } from "@canonical/jujulib";
import Client from "@canonical/jujulib/dist/api/facades/client";
import ModelManager from "@canonical/jujulib/dist/api/facades/model-manager";
const serverURL = "ws://localhost:17070";
const credentials = {
username: "admin",
password: "test",
};
const controller = await connect(`${serverURL}/api`, {
facades: [ModelManager],
wsclass: WebSocket,
});
let conn = await controller.login(credentials);
const modelManager = conn.facades.modelManager;
const response = await modelManager.listModels({
tag: conn.info.user.identity,
});
const models = response["user-models"];
console.log("models:", models);
conn.transport.close();
for (const modelDetails of models) {
const model = await connect(
`${serverURL}/model/${modelDetails.model.uuid}/api`,
{
facades: [Client],
wsclass: WebSocket,
}
);
conn = await model.login(credentials);
const client = conn.facades.client;
console.log("model details:", await client.fullStatus());
conn.transport.close();
}
In the code above, a connection is established to the provided controller API URL where the client declares interest in using the facade ModelManager, and we establish a new connection with each model API to get the full details using the facade Client.
Note: Facades are used to supported different versions of juju, when multiple versions of the same facade are supported by the juju API (like the two client versions in the example), the most recent version supported by the server is made available to the client.
The connect method returns a juju object which is used to log into the controller or model by providing a user/pass credentials or macaroons. See the various examples.
Client API Reference
Visit the full API documentation for detailed information on the Client API.
Examples
We have a number of examples showing how to perform a few common tasks. Those can be found in the examples folder.
Facade API Reference
Detailed Facade documentation is available as part of the full API documentation or you can visit the facade source directly using the following links:
| ActionPruner | |
| Action | |
| Admin | |
| AgentLifeFlag | |
| AgentTools | |
| Agent | |
| AllModelWatcher | |
| AllWatcher | |
| Annotations | |
| ApplicationOffers | |
| ApplicationScaler | |
| Application | |
| Backups | |
| Block | |
| Bundle | |
| CAASAdmission | |
| CAASAgent | |
| CAASApplicationProvisioner | |
| CAASApplication | |
| CAASFirewallerEmbedded | |
| CAASFirewallerSidecar | |
| CAASFirewaller | |
| CAASModelConfigManager | |
| CAASModelOperator | |
| CAASOperatorProvisioner | |
| CAASOperatorUpgrader | |
| CAASOperator | |
| CAASUnitProvisioner | |
| CharmDownloader | |
| CharmHub | |
| CharmRevisionUpdater | |
| Charms | |
| Cleaner | |
| Client | |
| Cloud | |
| Controller | |
| CredentialManager | |
| CredentialValidator | |
| CrossController | |
| CrossModelRelations | |
| CrossModelSecrets | |
| Deployer | |
| DiskManager | |
| EntityWatcher | |
| EnvironUpgrader | |
| ExternalControllerUpdater | |
| FanConfigurer | |
| FilesystemAttachmentsWatcher | |
| FirewallRules | |
| Firewaller | |
| HighAvailability | |
| HostKeyReporter | |
| ImageManager | |
| ImageMetadataManager | |
| ImageMetadata | |
| InstanceMutater | |
| InstancePoller | |
| KeyManager | |
| KeyUpdater | |
| LeadershipService | |
| LifeFlag | |
| LogForwarding | |
| Logger | |
| MachineActions | |
| MachineManager | |
| MachineUndertaker | |
| Machiner | |
| MeterStatus | |
| MetricsAdder | |
| MetricsDebug | |
| MetricsManager | |
| MigrationFlag | |
| MigrationMaster | |
| MigrationMinion | |
| MigrationStatusWatcher | |
| MigrationTarget | |
| ModelConfig | |
| ModelGeneration | |
| ModelManager | |
| ModelSummaryWatcher | |
| ModelUpgrader | |
| NotifyWatcher | |
| OfferStatusWatcher | |
| PayloadsHookContext | |
| Payloads | |
| Pinger | |
| Provisioner | |
| ProxyUpdater | |
| RaftLease | |
| Reboot | |
| RelationStatusWatcher | |
| RelationUnitsWatcher | |
| RemoteRelationWatcher | |
| RemoteRelations | |
| ResourcesHookContext | |
| Resources | |
| Resumer | |
| RetryStrategy | |
| SecretBackendsManager | |
| SecretBackendsRotateWatcher | |
| SecretBackends | |
| SecretsDrain | |
| SecretsManager | |
| SecretsRevisionWatcher | |
| SecretsRotationWatcher | |
| SecretsTriggerWatcher | |
| Secrets | |
| Singular | |
| Spaces | |
| SSHClient | |
| StatusHistory | |
| StorageProvisioner | |
| Storage | |
| StringsWatcher | |
| Subnets | |
| Undertaker | |
| UnitAssigner | |
| Uniter | |
| UpgradeSeries | |
| UpgradeSteps | |
| Upgrader | |
| UserManager | |
| UserSecretsDrain | |
| UserSecretsManager | |
| VolumeAttachmentPlansWatcher | |
| VolumeAttachmentsWatcher | |
Library Maintenance
Updating Library Facades
The Juju facade API files are generated from a supplied Juju schema.
First, open the file generator/schema/schema-history.json and add a new object with juju-version set to the version of Juju you want to support.
Set schema to a "raw" path on github for the schema file e.g. https://raw.githubusercontent.com/juju/juju/refs/tags/v3.6.14/apiserver/facades/schema.json (substituting the tag with the version number from above).
Set juju-git-sha to the sha for the release (go to the release page for the version you want to support e.g. https://github.com/juju/juju/releases/tag/v3.6.14 and the sha will be listed next to the tag).
To update the facades, run yarn regenerate-all-facades. This will generate the facades using the data from the schema-history.json file.
Finally, update CLIENT_VERSION in api/client.ts with the highest version of Juju that is supported by Jujulib.
Releasing to NPM
- Update the version number in
package.json, respecting semver, create a PR
and land it.
- Build package with
yarn run build.
- Upgrade the Juju Dashboard to this version using
yarn link and ensure that everything works as expected.
- Create a new release on
GitHub, setting the tag and title to the version number from above and include
any relevant changes in the release notes (use the 'Generate release notes' to
show changes since the last release and create a full changelog link, but
rewrite the changes to help them make sense to consumers of the library).
- Clone a fresh copy of the repository:
git clone git@github.com:juju/js-libjuju.git.
- Install the dependencies and build the package with
yarn install && yarn run build.
- Now you can publish to NPM with
yarn publish.