Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial changes to get rancher ui working for vultr #1

Merged
merged 6 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp

# dependencies
Expand Down
51 changes: 0 additions & 51 deletions assets/example.svg

This file was deleted.

1 change: 1 addition & 0 deletions assets/vultr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion component/component.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.machine-driver.%%DRIVERNAME%% {
background-image: url('example.svg');
background-image: url('vultr.svg');
}
109 changes: 82 additions & 27 deletions component/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*!!!!!!!!!!!Do not change anything between here (the DRIVERNAME placeholder will be automatically replaced at buildtime)!!!!!!!!!!!*/
import NodeDriver from 'shared/mixins/node-driver';

// import uiConstants from 'ui/utils/constants'

// do not remove LAYOUT, it is replaced at build time with a base64 representation of the template of the hbs template
// we do this to avoid converting template to a js file that returns a string and the cors issues that would come along with that
const LAYOUT;
Expand All @@ -9,44 +11,63 @@ const LAYOUT;

/*!!!!!!!!!!!GLOBAL CONST START!!!!!!!!!!!*/
// EMBER API Access - if you need access to any of the Ember API's add them here in the same manner rather then import them via modules, since the dependencies exist in rancher we dont want to expor the modules in the amd def
const computed = Ember.computed;
const get = Ember.get;
const set = Ember.set;
const alias = Ember.computed.alias;
const service = Ember.inject.service;

const defaultRadix = 10;
const defaultBase = 1024;
const computed = Ember.computed;
const get = Ember.get;
const set = Ember.set;
const alias = Ember.computed.alias;
const service = Ember.inject.service;

/*!!!!!!!!!!!GLOBAL CONST END!!!!!!!!!!!*/



/*!!!!!!!!!!!DO NOT CHANGE START!!!!!!!!!!!*/
export default Ember.Component.extend(NodeDriver, {
driverName: '%%DRIVERNAME%%',
config: alias('model.%%DRIVERNAME%%Config'),
app: service(),
needAPIToken: true,
config: alias('model.%%DRIVERNAME%%Config'),
app: service(),

init() {
// This does on the fly template compiling, if you mess with this :cry:
const decodedLayout = window.atob(LAYOUT);
const template = Ember.HTMLBars.compile(decodedLayout, {
const template = Ember.HTMLBars.compile(decodedLayout, {
moduleName: 'nodes/components/driver-%%DRIVERNAME%%/template'
});
set(this,'layout', template);
set(this, 'layout', template);

this._super(...arguments);

},
/*!!!!!!!!!!!DO NOT CHANGE END!!!!!!!!!!!*/

// Write your component here, starting with setting 'model' to a machine with your config populated
bootstrap: function() {
bootstrap: function () {
// bootstrap is called by rancher ui on 'init', you're better off doing your setup here rather then the init function to ensure everything is setup correctly
let config = get(this, 'globalStore').createRecord({
type: '%%DRIVERNAME%%Config',
cpuCount: 2,
memorySize: 2048,
additionalKey: [],
"apiKey": "",
"appId": "0",
"cloudInitUserData": "",
"ddosProtection": false,
"enableVpc": false,
"enabledIpv6": false,
"firewallGroupId": "",
"floatingIpv4Id": "",
"imageId": "",
"ipxeChainUrl": "",
"isoId": "",
"osId": 387,
"region": "ewr",
"sendActivationEmail": false,
"snapshotId": "",
"sshKeyIds": null,
"startupScriptId": "",
"tags": null,
"vpcIds": null,
"vpsBackups": false,
"vpsPlan": "vc2-1c-2gb"
});

set(this, 'model.%%DRIVERNAME%%Config', config);
Expand All @@ -56,28 +77,62 @@ export default Ember.Component.extend(NodeDriver, {
validate() {
// Get generic API validation errors
this._super();
var errors = get(this, 'errors')||[];
if ( !get(this, 'model.name') ) {
errors.push('Name is required');
}

// Add more specific errors
if (!this.get('model.%%DRIVERNAME%%Config.additionalKey')) {
this.set('model.%%DRIVERNAME%%Config.additionalKey', [])
}

// Check something and add an error entry if it fails:
if ( parseInt(get(this, 'config.memorySize'), defaultRadix) < defaultBase ) {
errors.push('Memory Size must be at least 1024 MB');
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') ) {
if (get(errors, 'length')) {
set(this, 'errors', errors);
return false;
} else {
set(this, 'errors', null);
return true;
}
},

// Any computed properties or custom logic can go here
});
actions: {
getData() {
this.set('gettingData', true);
let that = this;
Promise.all([this.apiRequest('/v2/regions'), this.apiRequest('/v2/regions/ewr/availability'), this.apiRequest('/v2/os')]).then(function (responses) {
that.setProperties({
errors: [],
needAPIToken: false,
gettingData: false,
regionChoices: responses[0].regions,
planChoices: responses[1].available_plans,
osChoices: responses[2].os
});
}).catch(function (err) {
err.then(function (msg) {
that.setProperties({
errors: ['Error received from Vultr: ' + msg.error.message],
gettingData: false
})
})
})
},
setLabels: function(labels){
let labels_list = labels.map(l => l.key + "=" + l.value);
this.set('model.%%DRIVERNAME%%Config.serverLabel', labels_list);

this._super(labels);
},
modifyKeys: function (select) {
let options = [...select.target.options]
.filter(o => o.selected)
.map(o => this.keyChoices.find(keyChoice => keyChoice.id == o.value)["public_key"]);
this.set('model.%%DRIVERNAME%%Config.additionalKey', options);
},
},
apiRequest(path) {
return fetch('https://rancher-proxy.vultrlabs.dev' + path).then(res => res.ok ? res.json() : Promise.reject(res.json()));
}
});
Loading