Skip to content

Commit f7ccdcb

Browse files
Merge pull request #18 from nutanixdev/Update
Update
2 parents 0d257c7 + 1ea1e82 commit f7ccdcb

File tree

7 files changed

+330
-74
lines changed

7 files changed

+330
-74
lines changed

js/v4api_sdk/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules/
22
config.json
3+
.eslintrc.json
4+
package-lock.json
5+
package.json

js/v4api_sdk/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

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

5-
This example demonstrates use of the Nutanix `vmm` JS API library
5+
This example demonstrates use of the Nutanix `clustermgmt` JS API library
66

77
## Usage
88

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

1111
- Install Node.js as per the [official documentation](https://nodejs.org/en/download/)
12-
- 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:
12+
- 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:
1313

1414
```
15-
npm install @nutanix-api/vmm-js-client
15+
npm install @nutanix-api/clustermgmt-js-client
1616
```
1717

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

3030
```
31-
node list_images_sdk.js
31+
node list_clusters_sdk.js
3232
```
3333

3434
## Screenshot
3535

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

js/v4api_sdk/list_clusters_sdk.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* list_clusters_sdk.js
3+
*
4+
* Code sample showing basic usage of the Nutanix v4 API SDK for JS
5+
*
6+
* This demo read configuration from config.json, connects to Prism Central,
7+
* authenticates then returns a list of registered clusters. The list is formatted to show
8+
* cluster names and their extId
9+
*
10+
* Requirements:
11+
*
12+
* Prism Central pc.2023.3 or later
13+
*/
14+
15+
const sdk = require("@nutanix-api/clustermgmt-js-client/dist/lib/index");
16+
let client = new sdk.ApiClient();
17+
18+
client.addDefaultHeader("Accept-Encoding","gzip, deflate, br");
19+
20+
const fs = require('fs');
21+
22+
// load the configuration from on-disk config.json
23+
fs.readFile('./config.json', 'utf8', (err, data) => {
24+
if (err) {
25+
console.log(`Unable to load config from ./config.json: ${err}`);
26+
} else {
27+
// parse JSON string to JSON object
28+
const config = JSON.parse(data);
29+
30+
// setup the connection configuration
31+
// for this demo, only Prism Central IP, port, username, password and debug mode are read from on-disk configuration
32+
// Prism Central IPv4/IPv6 address or FQDN
33+
client.host = config.pc_ip;
34+
// HTTP port for connection
35+
client.port = config.pc_port;
36+
// connection credentials
37+
client.username = config.username;
38+
client.password = config.password;
39+
// don't verify SSL certificates; not recommended in production
40+
client.verifySsl = false;
41+
// show extra debug info during demo
42+
client.debug = config.debug;
43+
client.cache = false;
44+
45+
console.log(`Prism Central IP or FQDN: ${client.host}`);
46+
console.log(`Username: ${client.username}`);
47+
48+
let clientApi = new sdk.ClusterApi(client);
49+
50+
// setup request options
51+
var entityListOptions = new Object();
52+
entityListOptions.page = 0;
53+
entityListOptions.limit = 20;
54+
entityListOptions.filter = '';
55+
entityListOptions.orderBy = '';
56+
57+
clientApi.getClusters(entityListOptions).then(({ data, response }) => {
58+
console.log(`API returned the following status code: ${response.status}`);
59+
data.getData().forEach(element => console.log('Cluster found with name "' + element.name + '"'))
60+
}).catch((err) => {
61+
console.log(`Error is ${err}`);
62+
})
63+
}
64+
})

js/v4api_sdk/list_images_sdk.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)