From bcdc09e507b75248173842b7bbd4c6fdd8371528 Mon Sep 17 00:00:00 2001 From: Logan Date: Wed, 14 Mar 2018 01:25:40 +0800 Subject: [PATCH] Update for 2.0 (#7) --- README.md | 4 +-- bower.json | 2 +- component/component.js | 50 +++++++++++++++++++------------- component/template.hbs | 66 ++++++++++++++++++++++++++++-------------- gulpfile.js | 6 ++-- package.json | 4 +-- 6 files changed, 83 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 2f99423..6afee2c 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ For other users to see your driver, you need to build it and host the output on ## Using -* Add a Machine Driver in Rancher (Admin tab -> Settings -> Machine Drivers) +* Add a Machine Driver in Rancher 2.0 (Global -> Node Drivers) * Name: Your `DRIVERNAME` (see above). * Download URL: The URL for the driver binary (e.g. `https://github.com/mycompany/docker-machine-mycompany/releases/download/v1.0.0/docker-machine-driver-mycompany-v1.0.0-linux-amd64.tar.gz`) * Custom UI URL: The URL you uploaded the `dist` folder to, e.g. `https://github.com/mycompany/ui-driver-mycompany/releases/download/v1.0.0/component.js`) * Wait for the driver to become "Active" -* Go to Infrastructure -> Hosts -> Add Host, your driver and custom UI should show up. +* Go to Clusters -> Add Cluster, your driver and custom UI should show up. diff --git a/bower.json b/bower.json index c06876a..8a156c5 100644 --- a/bower.json +++ b/bower.json @@ -17,6 +17,6 @@ "tests" ], "dependencies": { - "ember": "2.9.1" + "ember": "2.16.2" } } diff --git a/component/component.js b/component/component.js index aa79d53..9a633ee 100644 --- a/component/component.js +++ b/component/component.js @@ -1,54 +1,64 @@ /* v----- Do not change anything between here * (the DRIVERNAME placeholder will be automatically replaced during build) */ -define('ui/components/machine/driver-%%DRIVERNAME%%/component', ['exports', 'ember', 'ui/mixins/driver'], function (exports, _ember, _uiMixinsDriver) { +define('ui/components/node-driver/driver-%%DRIVERNAME%%/component', ['exports', 'ember', 'shared/components/node-driver/driver-%%DRIVERNAME%%/component'], function (exports, _ember, _component) { + exports['default'] = _component['default']; +}); + +define('shared/components/node-driver/driver-%%DRIVERNAME%%/component', ['exports', 'ember', 'shared/mixins/node-driver', 'shared/components/node-driver/driver-%%DRIVERNAME%%/template'], function (exports, _ember, _uiMixinsDriver, _template) { +/* ^--- And here */ + // You can put embmer object here + var computed = Ember.computed; + var get = Ember.get; + var set = Ember.set; + var alias = Ember.computed.alias; + +/* v----- Do not change anything between here + * (the DRIVERNAME placeholder will be automatically replaced during build) */ exports['default'] = _ember['default'].Component.extend(_uiMixinsDriver['default'], { + layout: _template.default, driverName: '%%DRIVERNAME%%', + config: alias('model.%%DRIVERNAME%%Config'), /* ^--- And here */ // Write your component here, starting with setting 'model' to a machine with your config populated bootstrap: function() { - let config = this.get('store').createRecord({ - type : '%%DRIVERNAME%%Config', - size : 512, + let config = get(this, 'globalStore').createRecord({ + type: '%%DRIVERNAME%%Config', + cpuCount: 2, + memorySize: 2048, }); - let type = 'host'; - - if (!this.get('useHost')) { - type = 'machine'; - } - - this.set('model', this.get('store').createRecord({ - type: type, - '%%DRIVERNAME%%Config': config, - })); + set(this, 'model.%%DRIVERNAME%%Config', config); }, // Add custom validation beyond what can be done from the config API schema validate() { // Get generic API validation errors this._super(); - var errors = this.get('errors')||[]; + var errors = get(this, 'errors')||[]; + if ( !get(this, 'model.name') ) { + errors.push('Name is required'); + } // Add more specific errors // Check something and add an error entry if it fails: - if ( parseInt(this.get('model.%%DRIVERNAME%%Config.size'),10) < 1024 ) + if ( parseInt(get(this, 'config.memorySize'),10) < 1024 ) { - errors.push('Size must be at least 1024 MB'); + errors.push('Memory Size must be at least 1024 MB'); } // Set the array of errors for display, // and return true if saving should continue. - if ( errors.get('length') ) + if ( get(errors, 'length') ) { - this.set('errors', errors); + set(this, 'errors', errors); return false; } else { - this.set('errors', null); + set(this, 'errors', null); return true; } }, diff --git a/component/template.hbs b/component/template.hbs index 4dd07f0..e978c42 100644 --- a/component/template.hbs +++ b/component/template.hbs @@ -1,31 +1,55 @@
-
- {{!-- This partial contains the quantity, name, and description fields --}} - {{partial "host/add-common"}} - -
- My Skeleton Driver -
+ {{#accordion-list showExpandAll=false as | al expandFn |}} + {{!-- This line shows the driver title which you don't have to change it --}} +
{{driverOptionsTitle}}
{{!-- An example input option --}} -
-
- -
-
-
- {{input type="text" - class="form-control" - value=model.%%DRIVERNAME%%Config.size - }} - MB +
+

Instance Options

+
+
+ +
+ +
+ {{config.cpuCount}} +
+
+ {{input-slider value=config.cpuCount valueMin=1 valueMax=32}} +
+ +
+ +
+
+
+ {{input-integer min=1 value=config.memorySize classNames="form-control"}} +
MB
+
- {{!-- This partial contains the Labels and Advanced Options fields --}} - {{partial "host/add-options"}} -
+ {{!-- This following contains the Name, Labels and Engine Options fields --}} +
{{templateOptionsTitle}}
+ + {{form-name-description + model=model + nameRequired=true + }} + + {{form-user-labels + initialLabels=labelResource.labels + setLabels=(action 'setLabels') + expandAll=expandAll + expand=(action expandFn) + }} + + {{form-engine-opts + machine=model + showEngineUrl=showEngineUrl + }} + {{/accordion-list}} {{!-- This component shows errors produced by validate() in the component --}} {{top-errors errors=errors}} diff --git a/gulpfile.js b/gulpfile.js index 0c2fc11..0781dc2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -72,10 +72,10 @@ gulp.task('compiled', ['js'], function() { .pipe(replace(NAME_TOKEN, DRIVER_NAME)) .pipe(htmlbars({compiler: emCompiler})) .pipe(wrapAmd({ - deps: ['exports', 'ember', 'ui/mixins/driver'], - params: ['exports', '_ember', '_uiMixinsDriver'], + deps: ['exports'], + params: ['exports'], moduleRoot: 'component/', - modulePrefix: 'ui/components/machine/driver-' + DRIVER_NAME + '/' + modulePrefix: 'shared/components/node-driver/driver-' + DRIVER_NAME + '/' })) .pipe(replace( "return Ember.TEMPLATES['template']", 'exports["default"]' diff --git a/package.json b/package.json index 66faf03..ae98f42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "ui-driver-hwclouds", - "version": "0.0.1", + "name": "ui-driver-skel", + "version": "0.0.2", "description": "Skeleton Rancher UI driver for custom docker-machine drivers", "repository": { "type": "git",