Skip to content

Instantly share code, notes, and snippets.

@displague
Last active July 9, 2018 19:21
Show Gist options
  • Save displague/20d5eb6e231fea2196ac162d3c880712 to your computer and use it in GitHub Desktop.
Save displague/20d5eb6e231fea2196ac162d3c880712 to your computer and use it in GitHub Desktop.
/* v----- Do not change anything between here
* (the DRIVERNAME placeholder will be automatically replaced during build) */
define('ui/components/node-driver/driver-linode/component', ['exports', 'ember', 'shared/components/node-driver/driver-linode/component'], function (exports, _ember, _component) {
exports['default'] = _component['default'];
});
define('shared/components/node-driver/driver-linode/component', ['exports', 'ember', 'shared/mixins/node-driver', 'shared/components/node-driver/driver-linode/template', 'ui/utils/constants'], function (exports, _ember, _uiMixinsDriver, _template, _uiUtilsConstants) {
/* ^--- 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: 'linode',
needAPIToken: true,
config: alias('model.linodeConfig'),
/* ^--- And here */
// Write your component here, starting with setting 'model' to a machine with your config populated
bootstrap: function () {
let config = get(this, 'store').createRecord({
type: 'linodeConfig',
instanceType: 'g6-standard-4', // 4 GB Ram
region: 'us-east', // Newark
image: 'ubuntu18.04',
userData: ''
});
set(this, 'model.linodeConfig', config);
set(this, 'model.engineStorageDriver', 'overlay');
},
// Add custom validation beyond what can be done from the config API schema
validate() {
// Get generic API validation errors
this._super();
var errors = get(this, 'errors') || [];
if (!get(this, 'model.name')) {
errors.push('Name is required');
}
// Set the array of errors for display,
// and return true if saving should continue.
if (get(errors, 'length')) {
set(this, 'errors', errors);
return false;
} else {
set(this, 'errors', null);
return true;
}
},
actions: {
getData() {
this.set('gettingData', true);
let that = this;
Promise.all([this.apiRequest('/v4/regions'), this.apiRequest('/v4/images'), this.apiRequest('/v4/linode/types')]).then(function (responses) {
that.setProperties({
errors: [],
needAPIToken: false,
gettingData: false,
regionChoices: responses[0].data,
imageChoices: responses[1].data.filter(image => !/fedora/.test(image.label)),
sizeChoices: responses[2].data
});
}).catch(function (err) {
err.then(function (msg) {
that.setProperties({
errors: ['Error received from Linode: ' + msg.error.message],
gettingData: false
})
})
})
}
},
apiRequest: function (path) {
return fetch('https://api.linode.com' + path, {
headers: {
'Authorization': 'Bearer ' + this.get('model.linodeConfig.apiToken'),
},
}).then(res => res.ok ? res.json() : Promise.reject(res.json()));
}
});
});
;
define("shared/components/node-driver/driver-linode/template",["exports"],function(exports){
exports["default"] = Ember.HTMLBars.template({"id":"54o7aXaq","block":"{\"symbols\":[\"choice\",\"choice\",\"choice\"],\"statements\":[[6,\"section\"],[10,\"class\",\"horizontal-form\"],[8],[0,\"\\n\"],[4,\"if\",[[22,[\"needAPIToken\"]]],null,{\"statements\":[[0,\" \"],[6,\"form\"],[8],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"over-hr r-mb20\"],[8],[0,\"\\n \"],[6,\"span\"],[8],[0,\"Account Access\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"row form-group\"],[8],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-2\"],[8],[0,\"\\n \"],[6,\"label\"],[10,\"class\",\"form-control-static\"],[8],[0,\"API Token*\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-10\"],[8],[0,\"\\n \"],[1,[26,\"input\",null,[[\"type\",\"value\",\"classNames\",\"placeholder\"],[\"password\",[22,[\"model\",\"linodeConfig\",\"apiToken\"]],\"form-control\",\"Your Linode APIv4 Token\"]]],false],[0,\"\\n \"],[6,\"p\"],[10,\"class\",\"help-block\"],[8],[0,\"Create a Personal Access Token at\\n \"],[6,\"a\"],[10,\"target\",\"_blank\"],[10,\"href\",\"https://cloud.linode.com/profile/tokens\"],[8],[0,\"Linode Cloud Manager\"],[9],[0,\", click your username, go to My Profile → Add a Personal Access Token\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[1,[26,\"top-errors\",null,[[\"errors\"],[[22,[\"errors\"]]]]],false],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"footer-actions\"],[8],[0,\"\\n\"],[4,\"if\",[[22,[\"gettingData\"]]],null,{\"statements\":[[0,\" \"],[6,\"button\"],[10,\"class\",\"btn bg-primary btn-disabled\"],[8],[0,\"\\n \"],[6,\"i\"],[10,\"class\",\"icon icon-spinner icon-spin\"],[8],[9],[0,\" \"],[1,[26,\"t\",[\"generic.loading\"],null],false],[9],[0,\"\\n\"]],\"parameters\":[]},{\"statements\":[[0,\" \"],[6,\"button\"],[10,\"class\",\"btn bg-primary\"],[11,\"disabled\",[26,\"not\",[[22,[\"model\",\"linodeConfig\",\"apiToken\"]]],null]],[3,\"action\",[[21,0,[]],\"getData\"]],[8],[0,\"Configure Server\"],[9],[0,\"\\n\"]],\"parameters\":[]}],[0,\" \"],[6,\"button\"],[10,\"class\",\"btn bg-transparent\"],[3,\"action\",[[21,0,[]],\"cancel\"]],[8],[1,[26,\"t\",[\"generic.cancel\"],null],false],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[9],[0,\"\\n\"]],\"parameters\":[]},{\"statements\":[[0,\" \"],[6,\"div\"],[10,\"class\",\"container-fluid\"],[8],[0,\"\\n\"],[0,\" \"],[6,\"div\"],[10,\"class\",\"over-hr\"],[8],[0,\"\\n \"],[6,\"span\"],[8],[1,[20,\"templateOptionsTitle\"],false],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"over-hr r-mt20 r-mb20\"],[8],[0,\"\\n \"],[6,\"span\"],[8],[0,\"Region\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"row form-group\"],[8],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-2\"],[8],[0,\"\\n \"],[6,\"label\"],[10,\"class\",\"form-control-static\"],[8],[0,\"Region\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-10\"],[8],[0,\"\\n \"],[6,\"select\"],[10,\"class\",\"form-control\"],[11,\"onchange\",[26,\"action\",[[21,0,[]],[26,\"mut\",[[22,[\"model\",\"linodeConfig\",\"region\"]]],null]],[[\"value\"],[\"target.value\"]]]],[8],[0,\"\\n\"],[4,\"each\",[[22,[\"regionChoices\"]]],null,{\"statements\":[[0,\" \"],[6,\"option\"],[11,\"value\",[21,3,[\"id\"]]],[11,\"selected\",[26,\"eq\",[[22,[\"model\",\"linodeConfig\",\"region\"]],[21,3,[\"id\"]]],null]],[8],[1,[21,3,[\"id\"]],false],[0,\" (\"],[1,[21,3,[\"country\"]],false],[0,\")\"],[9],[0,\"\\n\"]],\"parameters\":[3]},null],[0,\" \"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"over-hr r-mt20 r-mb20\"],[8],[0,\"\\n \"],[6,\"span\"],[8],[0,\"Settings\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"row form-group\"],[8],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-2\"],[8],[0,\"\\n \"],[6,\"label\"],[10,\"class\",\"form-control-static\"],[8],[0,\"Image\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-4\"],[8],[0,\"\\n \"],[6,\"select\"],[10,\"class\",\"form-control\"],[11,\"onchange\",[26,\"action\",[[21,0,[]],[26,\"mut\",[[22,[\"model\",\"linodeConfig\",\"image\"]]],null]],[[\"value\"],[\"target.value\"]]]],[8],[0,\"\\n\"],[4,\"each\",[[22,[\"imageChoices\"]]],null,{\"statements\":[[0,\" \"],[6,\"option\"],[11,\"value\",[21,2,[\"id\"]]],[11,\"selected\",[26,\"eq\",[[22,[\"model\",\"linodeConfig\",\"image\"]],[21,2,[\"id\"]]],null]],[8],[1,[21,2,[\"label\"]],false],[9],[0,\"\\n\"]],\"parameters\":[2]},null],[0,\" \"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-2\"],[8],[0,\"\\n \"],[6,\"label\"],[10,\"class\",\"form-control-static\"],[8],[0,\"Instance Type\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-4\"],[8],[0,\"\\n \"],[6,\"select\"],[10,\"class\",\"form-control\"],[11,\"onchange\",[26,\"action\",[[21,0,[]],[26,\"mut\",[[22,[\"model\",\"linodeConfig\",\"instanceType\"]]],null]],[[\"value\"],[\"target.value\"]]]],[8],[0,\"\\n\"],[4,\"each\",[[22,[\"sizeChoices\"]]],null,{\"statements\":[[0,\" \"],[6,\"option\"],[11,\"value\",[21,1,[\"id\"]]],[11,\"selected\",[26,\"eq\",[[22,[\"model\",\"linodeConfig\",\"instanceType\"]],[21,1,[\"id\"]]],null]],[8],[1,[21,1,[\"label\"]],false],[0,\" - \"],[1,[21,1,[\"vcpus\"]],false],[0,\" vCPUs, \"],[1,[21,1,[\"memory\"]],false],[0,\"GB Memory, \"],[1,[21,1,[\"disk\"]],false],[0,\"GB Disk space\"],[9],[0,\"\\n\"]],\"parameters\":[1]},null],[0,\" \"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"over-hr r-mt20 r-mb20\"],[8],[0,\"\\n \"],[6,\"span\"],[8],[0,\"User data\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"row form-group\"],[8],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-2\"],[8],[0,\"\\n \"],[6,\"label\"],[10,\"class\",\"form-control-static\"],[8],[0,\"Cloud-init Configuration (optional)\"],[9],[0,\"\\n \"],[9],[0,\"\\n \"],[6,\"div\"],[10,\"class\",\"col-md-10\"],[8],[0,\"\\n \"],[6,\"textarea\"],[11,\"onchange\",[26,\"action\",[[21,0,[]],[26,\"mut\",[[22,[\"model\",\"linodeConfig\",\"userData\"]]],null]],[[\"value\"],[\"target.value\"]]]],[10,\"rows\",\"3\"],[10,\"style\",\"width: 100%; resize: vertical\"],[8],[9],[0,\" \"],[9],[0,\"\\n \"],[9],[0,\"\\n\"],[0,\" \"],[1,[26,\"form-name-description\",null,[[\"model\",\"nameRequired\"],[[22,[\"model\"]],true]]],false],[0,\"\\n \"],[1,[26,\"form-user-labels\",null,[[\"initialLabels\",\"setLabels\",\"expandAll\",\"expand\"],[[22,[\"labelResource\",\"labels\"]],[26,\"action\",[[21,0,[]],\"setLabels\"],null],[22,[\"expandAll\"]],[26,\"action\",[[21,0,[]],[22,[\"expandFn\"]]],null]]]],false],[0,\"\\n \"],[1,[26,\"form-engine-opts\",null,[[\"machine\",\"showEngineUrl\"],[[22,[\"model\"]],[22,[\"showEngineUrl\"]]]]],false],[0,\"\\n\"],[0,\" \"],[1,[26,\"top-errors\",null,[[\"errors\"],[[22,[\"errors\"]]]]],false],[0,\"\\n\"],[0,\" \"],[1,[26,\"save-cancel\",null,[[\"save\",\"cancel\"],[\"save\",\"cancel\"]]],false],[0,\"\\n \"],[9],[0,\"\\n\"]],\"parameters\":[]}],[9],[0,\"\\n\"]],\"hasEval\":false}","meta":{}});;
});
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment