· 7 years ago · Dec 09, 2018, 02:50 PM
1function getInstances(apiKey, secretKey, instanceId){
2 console.log("[ComputeQloud]Â Listing running instances - expecting success");
3
4 //a promise is part of node fibers (threads) and can wait for a callback to finish
5 var mypromise = new promise();
6
7 var options = null;
8 if (instanceId) {
9 options = {
10 FilterName: [ 'instance-id' ],
11 FilterValue: [ [instanceId]Â ]
12 }
13 }
14
15 getEC2(apiKey, secretKey).DescribeInstances(options, function(err, result) {
16 if (err) {
17 inspect(err, 'Error');
18 mypromise.set(new Meteor.Error(500, "Can't find my pants"));
19 return;
20 }
21
22 var instances = result.Body.DescribeInstancesResponse.reservationSet;
23 inspect(instances, 'Data');
24 mypromise.set(instances)
25 return;
26 });
27
28 mypromise.wait();
29
30 finalValue = mypromise.get();
31 if(finalValue instanceof Meteor.Error){
32 throw finalValue;
33 }
34
35 return finalValue;
36}