updates to shell
authorScott Baker <smbaker@gmail.com>
Thu, 19 Jun 2014 23:51:16 +0000 (16:51 -0700)
committerScott Baker <smbaker@gmail.com>
Thu, 19 Jun 2014 23:51:16 +0000 (16:51 -0700)
planetstack/core/static/shell/constants.js
planetstack/core/static/shell/opencloud.js
planetstack/core/static/shell/opencloud_shell.js

index dd267e2..5231cda 100644 (file)
@@ -36,4 +36,4 @@ var JavascriptKeywords = ['abstract', 'boolean', 'break', 'byte', 'case', 'catch
 \r
 var JavascriptClassNames = ['Array', 'String', 'Object']\r
 \r
-var MongoKeywords = ['help','tutorial','next','back','t0','t1','t2'];\r
+var MongoKeywords = ['help','tutorial','next','back','t0','t1','t2','t3','t4'];\r
index 52c9e5c..7166abf 100644 (file)
@@ -24,12 +24,46 @@ function updateOpenCloud(onLoaded) {
     });
 }
 
-function Slices() {
-    this.listAll = function() { return opencloud_data["slices"] }
-    this.__str__ = function() { return '["listAll"]'; }
+function OpenCloudModel(name) {
+    this.all = function() { return opencloud_data[name]; };
+
+    this.match = function(filterDict,obj) {
+                   for (var k in filterDict) {
+                       if (obj[k] == filterDict[k]) {
+                           return true;
+                       }
+                   }
+                   return false;
+                 };
+
+    this.filter = function(filterDict) {
+                   result = []
+                   all_objs = this.all()
+                   for (var k in all_objs) {
+                        obj = all_objs[k];
+                        if (this.match(filterDict, obj)) {
+                            result.push(obj);
+                        }
+                   }
+                   return result;
+                 };
+
+    this.get = function(filterDict) {
+                   return this.filter(filterDict)[0];
+                 };
+
+    this.__str__ = function() { return '["all", "filter", "get"]' };
 }
 
+//function Slices() {
+//    this.listAll = function() { return opencloud_data["slices"] }
+//    this.__str__ = function() { return '["listAll"]'; }
+//}
+
 function OpenCloud() {
-    this.slices = new Slices()
-    this.__str__ = function() { return '["slices"]'; }
+    this.slices = new OpenCloudModel("slices");
+    this.slivers = new OpenCloudModel("slivers");
+    this.nodes = new OpenCloudModel("nodes");
+    this.sites = new OpenCloudModel("sites");
+    this.__str__ = function() { return '["slices", "slivers", "nodes", "sites"]'; }
 };
index ab5a355..861cd10 100644 (file)
@@ -116,7 +116,7 @@ var MongoHandler = function() {
   this._rawCommand     = "";
   this._commandStack   = 0;
   this._tutorialPtr    = 0;
-  this._tutorialMax    = 2;
+  this._tutorialMax    = 4;
 
   this._mongo          = {};
   this._mongo.test     = [];
@@ -249,7 +249,11 @@ MongoHandler.prototype = {
   // help command
   _help: function() {
       return PTAG('HELP') +
-             PTAG('opencloud.slices.listAll()       get all slices');
+             PTAG('opencloud                                 list opencloud API object types') +
+             PTAG('opencloud.slices                          list methods to can call on slices') +
+             PTAG('opencloud.slices.all()                    get all slices') +
+             PTAG('opencloud.slices.filter({key: "value"})   filter using dictionary') +
+             PTAG('opencloud.slices.get({key: "value"}))     get using dictionary')
 
   },
 
@@ -296,9 +300,30 @@ MongoHandler.prototype = {
 
   _t2: function() {
     this._tutorialPtr = 2;
-    return PTAG('2. List some slices') +
-           PTAG('Type this:') +
-           PTAG('    opencloud.slices.listAll();');
+    return PTAG('2. List some objects') +
+           PTAG('Try these:') +
+           PTAG('    opencloud.slices.all();') +
+           PTAG('    opencloud.slivers.all();') +
+           PTAG('    opencloud.sites.all();') +
+           PTAG('    opencloud.nodes.all();');
+
+  },
+
+  _t3: function() {
+    this._tutorialPtr = 3;
+    return PTAG('3. Filter some objects') +
+           PTAG('Try these:') +
+           PTAG('    opencloud.slices.get({name: "HyperCache"});');
+           PTAG('    opencloud.nodes.filter({site_id: opencloud.sites.get({name: "Princeton"})["id"]});');
+
+  },
+
+  _t4: function() {
+    this._tutorialPtr = 4;
+    return PTAG('4. Available OpenCloud objects and methods') +
+           PTAG('Try these:') +
+           PTAG('    opencloud;') +
+           PTAG('    opencloud.nodes;');
 
   },
 
@@ -320,6 +345,10 @@ MongoHandler.prototype = {
           return this._t1;
         case 't2':
           return this._t2;
+        case 't3':
+          return this._t3;
+        case 't4':
+          return this._t4;
       }
     }
   }