@canonical/jujulib
v7.0.0
Published
Juju API client
Downloads
394
Readme
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";
// Nodejs
// import WebSocket from "ws";
const serverURL = "ws://localhost:17070";
const credentials = {
username: "admin",
password: "test",
};
// Connect to the controller
const controller = await connect(`${serverURL}/api`, {
facades: [ModelManager],
wsclass: WebSocket,
});
let conn = await controller.login(credentials);
// Get the list of models
const modelManager = conn.facades.modelManager;
const response = await modelManager.listModels({
tag: conn.info.user.identity,
});
const models = response["user-models"];
console.log("models:", models);
// Close the connection to the controller
conn.transport.close();
// Login to each model
for (const modelDetails of models) {
const model = await connect(
`${serverURL}/model/${modelDetails.model.uuid}/api`,
{
facades: [Client],
wsclass: WebSocket,
}
);
conn = await model.login(credentials);
// Get the details of the model
const client = conn.facades.client;
console.log("model details:", await client.fullStatus());
// Close the connection to the model
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:
| Facade | Versions | | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ActionPruner | ActionPrunerV1.ts | | Action | ActionV6.tsActionV7.ts | | Admin | AdminV3.ts | | AgentLifeFlag | AgentLifeFlagV1.ts | | AgentTools | AgentToolsV1.ts | | Agent | AgentV2.tsAgentV3.ts | | AllModelWatcher | AllModelWatcherV2.tsAllModelWatcherV3.tsAllModelWatcherV4.ts | | AllWatcher | AllWatcherV1.tsAllWatcherV2.tsAllWatcherV3.ts | | Annotations | AnnotationsV2.ts | | ApplicationOffers | ApplicationOffersV2.tsApplicationOffersV3.tsApplicationOffersV4.ts | | ApplicationScaler | ApplicationScalerV1.ts | | Application | ApplicationV12.tsApplicationV13.tsApplicationV14.tsApplicationV15.tsApplicationV18.tsApplicationV19.ts | | Backups | BackupsV2.tsBackupsV3.ts | | Block | BlockV2.ts | | Bundle | BundleV1.tsBundleV4.tsBundleV5.tsBundleV6.ts | | CAASAdmission | CAASAdmissionV1.ts | | CAASAgent | CAASAgentV1.tsCAASAgentV2.ts | | CAASApplicationProvisioner | CAASApplicationProvisionerV1.ts | | CAASApplication | CAASApplicationV1.ts | | CAASFirewallerEmbedded | CAASFirewallerEmbeddedV1.ts | | CAASFirewallerSidecar | CAASFirewallerSidecarV1.ts | | CAASFirewaller | CAASFirewallerV1.ts | | CAASModelConfigManager | CAASModelConfigManagerV1.ts | | CAASModelOperator | CAASModelOperatorV1.ts | | CAASOperatorProvisioner | CAASOperatorProvisionerV1.ts | | CAASOperatorUpgrader | CAASOperatorUpgraderV1.ts | | CAASOperator | CAASOperatorV1.ts | | CAASUnitProvisioner | CAASUnitProvisionerV1.tsCAASUnitProvisionerV2.ts | | CharmDownloader | CharmDownloaderV1.ts | | CharmHub | CharmHubV1.ts | | CharmRevisionUpdater | CharmRevisionUpdaterV2.ts | | Charms | CharmsV2.tsCharmsV4.tsCharmsV5.tsCharmsV6.tsCharmsV7.ts | | Cleaner | CleanerV2.ts | | Client | ClientV2.tsClientV3.tsClientV5.tsClientV6.tsClientV7.ts | | Cloud | CloudV1.tsCloudV2.tsCloudV3.tsCloudV4.tsCloudV5.tsCloudV7.ts | | Controller | ControllerV11.tsControllerV3.tsControllerV4.tsControllerV5.tsControllerV6.tsControllerV7.tsControllerV8.tsControllerV9.ts | | CredentialManager | CredentialManagerV1.ts | | CredentialValidator | CredentialValidatorV2.ts | | CrossController | CrossControllerV1.ts | | CrossModelRelations | CrossModelRelationsV2.ts | | CrossModelSecrets | CrossModelSecretsV1.ts | | Deployer | DeployerV1.ts | | DiskManager | DiskManagerV2.ts | | EntityWatcher | EntityWatcherV2.ts | | EnvironUpgrader | EnvironUpgraderV1.ts | | ExternalControllerUpdater | ExternalControllerUpdaterV1.ts | | FanConfigurer | FanConfigurerV1.ts | | FilesystemAttachmentsWatcher | FilesystemAttachmentsWatcherV2.ts | | FirewallRules | FirewallRulesV1.ts | | Firewaller | FirewallerV5.tsFirewallerV7.ts | | HighAvailability | HighAvailabilityV2.ts | | HostKeyReporter | HostKeyReporterV1.ts | | ImageManager | ImageManagerV2.ts | | ImageMetadataManager | ImageMetadataManagerV1.ts | | ImageMetadata | ImageMetadataV3.ts | | InstanceMutater | InstanceMutaterV2.tsInstanceMutaterV3.ts | | InstancePoller | InstancePollerV4.ts | | KeyManager | KeyManagerV1.ts | | KeyUpdater | KeyUpdaterV1.ts | | LeadershipService | LeadershipServiceV2.ts | | LifeFlag | LifeFlagV1.ts | | LogForwarding | LogForwardingV1.ts | | Logger | LoggerV1.ts | | MachineActions | MachineActionsV1.ts | | MachineManager | MachineManagerV10.tsMachineManagerV6.tsMachineManagerV7.tsMachineManagerV9.ts | | MachineUndertaker | MachineUndertakerV1.ts | | Machiner | MachinerV4.tsMachinerV5.ts | | MeterStatus | MeterStatusV2.ts | | MetricsAdder | MetricsAdderV2.ts | | MetricsDebug | MetricsDebugV2.ts | | MetricsManager | MetricsManagerV1.ts | | MigrationFlag | MigrationFlagV1.ts | | MigrationMaster | MigrationMasterV2.tsMigrationMasterV3.ts | | MigrationMinion | MigrationMinionV1.ts | | MigrationStatusWatcher | MigrationStatusWatcherV1.ts | | MigrationTarget | MigrationTargetV1.tsMigrationTargetV2.tsMigrationTargetV3.ts | | ModelConfig | ModelConfigV2.tsModelConfigV3.ts | | ModelGeneration | ModelGenerationV4.ts | | ModelManager | ModelManagerV2.tsModelManagerV3.tsModelManagerV4.tsModelManagerV5.tsModelManagerV8.tsModelManagerV9.ts | | ModelSummaryWatcher | ModelSummaryWatcherV1.ts | | ModelUpgrader | ModelUpgraderV1.ts | | NotifyWatcher | NotifyWatcherV1.ts | | OfferStatusWatcher | OfferStatusWatcherV1.ts | | PayloadsHookContext | PayloadsHookContextV1.ts | | Payloads | PayloadsV1.ts | | Pinger | PingerV1.ts | | Provisioner | ProvisionerV11.ts | | ProxyUpdater | ProxyUpdaterV2.ts | | RaftLease | RaftLeaseV1.tsRaftLeaseV2.ts | | Reboot | RebootV2.ts | | RelationStatusWatcher | RelationStatusWatcherV1.ts | | RelationUnitsWatcher | RelationUnitsWatcherV1.ts | | RemoteRelationWatcher | RemoteRelationWatcherV1.ts | | RemoteRelations | RemoteRelationsV2.ts | | ResourcesHookContext | ResourcesHookContextV1.ts | | Resources | ResourcesV1.tsResourcesV2.tsResourcesV3.ts | | Resumer | ResumerV2.ts | | RetryStrategy | RetryStrategyV1.ts | | SecretBackendsManager | SecretBackendsManagerV1.ts | | SecretBackendsRotateWatcher | SecretBackendsRotateWatcherV1.ts | | SecretBackends | SecretBackendsV1.ts | | SecretsDrain | SecretsDrainV1.ts | | SecretsManager | SecretsManagerV1.tsSecretsManagerV2.ts | | SecretsRevisionWatcher | SecretsRevisionWatcherV1.ts | | SecretsRotationWatcher | SecretsRotationWatcherV1.ts