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
56var 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
1113paperspace . 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