Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/v4api_sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
config.json
.eslintrc.json
package-lock.json
package.json
9 changes: 4 additions & 5 deletions js/v4api_sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

Code sample to demonstrate use of the new Nutanix v4 APIs via JS SDK.

This example demonstrates use of the Nutanix `vmm` JS API library
This example demonstrates use of the Nutanix `clustermgmt` JS API library

## Usage

Example instructions are for a Linux or Mac OS X environment.

- Install Node.js as per the [official documentation](https://nodejs.org/en/download/)
- Add the [Nutanix vmm JS Client](https://www.npmjs.com/package/@nutanix-api/vmm-js-client) as a project dependency; for this demo we are using the `vmm` SDK as it provides access to Images APIs:
- Add the [Nutanix clustermgmt JS Client](https://www.npmjs.com/package/@nutanix-api/clustermgmt-js-client) as a project dependency; for this demo we are using the `clustermgmt` SDK as it provides access to Cluster APIs:

```
npm install @nutanix-api/vmm-js-client
npm install @nutanix-api/clustermgmt-js-client
```

- Optional but useful: Install [ESLint](https://eslint.org/)
Expand All @@ -28,10 +28,9 @@ Example instructions are for a Linux or Mac OS X environment.
- Run the script:

```
node list_images_sdk.js
node list_clusters_sdk.js
```

## Screenshot

![Example script execution](./screenshot.png "Example script execution")

64 changes: 64 additions & 0 deletions js/v4api_sdk/list_clusters_sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* list_clusters_sdk.js
*
* Code sample showing basic usage of the Nutanix v4 API SDK for JS
*
* This demo read configuration from config.json, connects to Prism Central,
* authenticates then returns a list of registered clusters. The list is formatted to show
* cluster names and their extId
*
* Requirements:
*
* Prism Central pc.2023.3 or later
*/

const sdk = require("@nutanix-api/clustermgmt-js-client/dist/lib/index");
let client = new sdk.ApiClient();

client.addDefaultHeader("Accept-Encoding","gzip, deflate, br");

const fs = require('fs');

// load the configuration from on-disk config.json
fs.readFile('./config.json', 'utf8', (err, data) => {
if (err) {
console.log(`Unable to load config from ./config.json: ${err}`);
} else {
// parse JSON string to JSON object
const config = JSON.parse(data);

// setup the connection configuration
// for this demo, only Prism Central IP, port, username, password and debug mode are read from on-disk configuration
// Prism Central IPv4/IPv6 address or FQDN
client.host = config.pc_ip;
// HTTP port for connection
client.port = config.pc_port;
// connection credentials
client.username = config.username;
client.password = config.password;
// don't verify SSL certificates; not recommended in production
client.verifySsl = false;
// show extra debug info during demo
client.debug = config.debug;
client.cache = false;

console.log(`Prism Central IP or FQDN: ${client.host}`);
console.log(`Username: ${client.username}`);

let clientApi = new sdk.ClusterApi(client);

// setup request options
var entityListOptions = new Object();
entityListOptions.page = 0;
entityListOptions.limit = 20;
entityListOptions.filter = '';
entityListOptions.orderBy = '';

clientApi.getClusters(entityListOptions).then(({ data, response }) => {
console.log(`API returned the following status code: ${response.status}`);
data.getData().forEach(element => console.log('Cluster found with name "' + element.name + '"'))
}).catch((err) => {
console.log(`Error is ${err}`);
})
}
})
55 changes: 0 additions & 55 deletions js/v4api_sdk/list_images_sdk.js

This file was deleted.

Loading