Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit f207cc0

Browse files
committed
update sample scripts to create machines using ML in a Box template
1 parent 8e113be commit f207cc0

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

samples/sample_bash_script.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ PAPERSPACE_API_KEY=1be4f97...
99
echo "paperspace templates list"
1010
paperspace templates list
1111

12-
# Select the 6th template in the list using the 'jq' tool
13-
echo "selecting the 6th template id..."
14-
t_id=`paperspace templates list | jq -r '.[5].id'`
12+
# Select the first template with a label of "ML in a Box", using the 'jq' tool
13+
echo "finding a template with label 'ML in a Box'..."
14+
t_id=`paperspace templates list | jq -r '.[] | select(.label=="ML in a Box") | .id'`
1515

16-
# Create the machine and parse out the new machine id
16+
# Create a machine and parse out the new machine id
1717
echo "paperspace machines create ... --templateId $t_id"
1818
m_id=`paperspace machines create --machineName "Test Machine" --billingType "hourly" \
19-
--region "East Coast (NY2)" --size 50 --machineType "C1" --templateId "$t_id" | jq -r '.id'`
19+
--region "East Coast (NY2)" --size 50 --machineType "GPU+" --templateId "$t_id" | jq -r '.id'`
2020

2121
echo "paperspace machines waitfor --machineId $m_id --state ready"
2222
paperspace machines waitfor --machineId "$m_id" --state "ready"
@@ -32,3 +32,5 @@ paperspace machines waitfor --machineId "$m_id" --state "off"
3232

3333
echo "paperspace machines destroy --machineId $m_id"
3434
paperspace machines destroy --machineId "$m_id"
35+
36+
echo "done"

samples/sample_node_app.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Assumes you have installed the paperspace-node package globally.
22
// Use "require('../../paperspace-node')" if running from the repository tree.
3-
var paperspace_node = require('paperspace-node');
3+
var paperspace_node = require('../../paperspace-node');
44

5+
// Set apkKey for use of the paperspace api
56
var paperspace = paperspace_node({
67
apiKey: '1be4f97...' // Substitue your actual apiKey here
78
});
89

9-
console.log('paperspace tempates list');
10+
// Retrieve a list of all the templates as a json array
11+
console.log('\npaperspace.tempates.list(...);');
1012

1113
paperspace.templates.list(
1214
function(err, resp) {
@@ -16,13 +18,27 @@ paperspace.templates.list(
1618
}
1719
console.log(resp.body);
1820

19-
var t_id = resp.body[5].id; // e.g., the 6th template was os type 'Ubuntu 16.04 Server'
21+
// Search the response body for a template with the label 'ML in a Box'
22+
var t_id;
23+
for(var i = 0; i < resp.body.length; i++) {
24+
if(resp.body[i].label === 'ML in a Box') {
25+
t_id = resp.body[i].id;
26+
break;
27+
}
28+
}
29+
if (!t_id) {
30+
console.log('Error: \'ML in a Box\' template not found.');
31+
process.exit(1);
32+
}
2033

21-
console.log('paperspace machines create ... --templateId ' + t_id);
34+
// Create a machine using the found template id
35+
console.log('\npaperspace.machines.create({\n region: \'East Coast (NY2)\',\n machineType: \'GPU+\',');
36+
console.log(' size: 50,\n billingType: \'hourly\',\n machineName: \'Test Machine\',');
37+
console.log(' templateId: \'' + t_id + '\'}, ...);');
2238

2339
paperspace.machines.create({
2440
region: 'East Coast (NY2)',
25-
machineType: 'C1',
41+
machineType: 'GPU+',
2642
size: 50,
2743
billingType: 'hourly',
2844
machineName: 'Test Machine',
@@ -36,7 +52,8 @@ paperspace.templates.list(
3652

3753
var id = resp.body.id; // Extract the id of the newly created machine
3854

39-
console.log('paperspace machines waitfor --machineId ' + id + ' --state ready');
55+
// Wait for machine to enter the 'ready' state
56+
console.log('\npaperspace.machines.waitfor({machineId: \'' + id + '\', state: \'ready\'}, ...);');
4057

4158
paperspace.machines.waitfor({
4259
machineId: id,
@@ -48,7 +65,8 @@ paperspace.templates.list(
4865
}
4966
console.log(resp.body);
5067

51-
console.log('paperspace machines stop --machineId ' + id);
68+
// Stop the machine
69+
console.log('\npaperspace.machines.stop({machineId: \'' + id + '\'}, ...);');
5270

5371
paperspace.machines.stop({
5472
machineId: id,
@@ -59,7 +77,8 @@ paperspace.templates.list(
5977
}
6078
console.log(resp.body);
6179

62-
console.log('paperspace machines waitfor --machineId ' + id + ' --state off');
80+
// Wait for machine to enter the 'off' state
81+
console.log('\npaperspace.machines.waitfor({machineId: \'' + id + '\', state: \'off\'}, ...);');
6382

6483
paperspace.machines.waitfor({
6584
machineId: id,
@@ -71,7 +90,8 @@ paperspace.templates.list(
7190
}
7291
console.log(resp.body);
7392

74-
console.log('paperspace machines destroy --machineId ' + id);
93+
// Destroy the machine
94+
console.log('\npaperspace.machines.destroy({machineId: \'' + id + '\'}, ...);');
7595

7696
paperspace.machines.destroy({
7797
machineId: id,
@@ -82,7 +102,7 @@ paperspace.templates.list(
82102
}
83103
console.log(resp.body);
84104

85-
console.log('done');
105+
console.log('\ndone');
86106
});
87107
});
88108
});

0 commit comments

Comments
 (0)